From nobody Wed Dec 17 10:52:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95F1034DB56 for ; Thu, 13 Nov 2025 11:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763034992; cv=none; b=GGV8oUKaDou6M0nHODW58fw18lzIDddHZuRHLeSDZfoyogePFJGzwjtuD98toqVpXy7JWoURvlRgK4l7h+oikonvi+uN8/Wvh593Sz13lIYfL2SJMtLBBE66pW6Do1tf3/ZqUwhtjJ0yztP761YBpejtJ96U+ImLrY3jrRKcJz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763034992; c=relaxed/simple; bh=kgGOdkCWntU0Y0x0HGjZfBJubTZM2CsetyHawR7zyMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Oy5RwRbZYyoOaF3Dz1rC9UNAuG13g3GW0DFPxgR+yGF20TdQ/VBXmdvAmzGdsEa/HLYcoJ7NXZhOmhurtHTrfrNza3QJ45P5hfvnwQE+DZZHJp8A5nCVnNWRF9fxZQ7fIGxCi+UyoFbtkf5yIrOQTPebCtG+Bv75nsFfM1VMmso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UCgkc6zV; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UCgkc6zV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763034989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lVSlVzxAg6GPuquH579aTv/XdSON+JMIkQy+Iw4qXlU=; b=UCgkc6zV08WqYecONEM5wPSvsd8ZdOiFV4FBhKu/YDBJECvLAi90xl9a0c6+mFZuK2F1h5 snU0Nacfqwpi75bpDfHgMV22UxusBx80i8CLF+PBSh47zEk4XxDCagz/iR9EiKYmiA8r3f mVLLt/4wevVaSI3ZftJOJdrexIeb0lo= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-HPITotpoPKyWonre8iVjNw-1; Thu, 13 Nov 2025 06:56:26 -0500 X-MC-Unique: HPITotpoPKyWonre8iVjNw-1 X-Mimecast-MFC-AGG-ID: HPITotpoPKyWonre8iVjNw_1763034985 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 66485180034D; Thu, 13 Nov 2025 11:56:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.122]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9DAF19560BD; Thu, 13 Nov 2025 11:56:20 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Laurent Vivier , virtualization@lists.linux.dev, Maxime Coquelin , Cindy Lu , jasowang@redhat.com, linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Xuan Zhuo , Stefano Garzarella Subject: [PATCH v9 4/6] vduse: refactor vdpa_dev_add for goto err handling Date: Thu, 13 Nov 2025 12:55:56 +0100 Message-ID: <20251113115558.1277981-5-eperezma@redhat.com> In-Reply-To: <20251113115558.1277981-1-eperezma@redhat.com> References: <20251113115558.1277981-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Next patches introduce more error paths in this function. Refactor it so they can be accomodated through gotos. Acked-by: Jason Wang Reviewed-by: Xie Yongji Signed-off-by: Eugenio P=C3=A9rez --- v6: New in v6. --- drivers/vdpa/vdpa_user/vduse_dev.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index b01f55a1c22d..97be04f73fbf 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -2172,21 +2172,27 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev,= const char *name, dev->bounce_size); mutex_unlock(&dev->domain_lock); if (!dev->domain) { - put_device(&dev->vdev->vdpa.dev); - return -ENOMEM; + ret =3D -ENOMEM; + goto domain_err; } =20 ret =3D _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num); if (ret) { - put_device(&dev->vdev->vdpa.dev); - mutex_lock(&dev->domain_lock); - vduse_domain_destroy(dev->domain); - dev->domain =3D NULL; - mutex_unlock(&dev->domain_lock); - return ret; + goto register_err; } =20 return 0; + +register_err: + mutex_lock(&dev->domain_lock); + vduse_domain_destroy(dev->domain); + dev->domain =3D NULL; + mutex_unlock(&dev->domain_lock); + +domain_err: + put_device(&dev->vdev->vdpa.dev); + + return ret; } =20 static void vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *d= ev) --=20 2.51.1