[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250611143932.2443796-2-alok.a.tiwari@oracle.com>
Date: Wed, 11 Jun 2025 07:39:22 -0700
From: Alok Tiwari <alok.a.tiwari@...cle.com>
To: mst@...hat.com, jasowang@...hat.com, michael.christie@...cle.com,
pbonzini@...hat.com, stefanha@...hat.com, eperezma@...hat.com,
virtualization@...ts.linux.dev, kvm@...r.kernel.org
Cc: alok.a.tiwari@...cle.com, darren.kenny@...cle.com, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] vhost-scsi: Improve error handling in vhost_scsi_make_nexus and tpg
Use PTR_ERR to return the actual error code when vhost_scsi_make_nexus
fails to create a session, instead of returning -ENOMEM.
This ensures more accurate error propagation.
Replace NULL with ERR_PTR(ret) in vhost_scsi_make_tpg to follow kernel
conventions for pointer-returning functions, allowing callers to use
IS_ERR and PTR_ERR for proper error handling.
Signed-off-by: Alok Tiwari <alok.a.tiwari@...cle.com>
---
drivers/vhost/scsi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 508ff3b29f39..fd9e435d28bf 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -2594,6 +2594,7 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
const char *name)
{
struct vhost_scsi_nexus *tv_nexus;
+ int ret;
mutex_lock(&tpg->tv_tpg_mutex);
if (tpg->tpg_nexus) {
@@ -2617,9 +2618,10 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
(unsigned char *)name, tv_nexus, NULL);
if (IS_ERR(tv_nexus->tvn_se_sess)) {
+ ret = PTR_ERR(tv_nexus->tvn_se_sess);
mutex_unlock(&tpg->tv_tpg_mutex);
kfree(tv_nexus);
- return -ENOMEM;
+ return ret;
}
tpg->tpg_nexus = tv_nexus;
@@ -2810,7 +2812,7 @@ vhost_scsi_make_tpg(struct se_wwn *wwn, const char *name)
ret = core_tpg_register(wwn, &tpg->se_tpg, tport->tport_proto_id);
if (ret < 0) {
kfree(tpg);
- return NULL;
+ return ERR_PTR(ret);
}
mutex_lock(&vhost_scsi_mutex);
list_add_tail(&tpg->tv_tpg_list, &vhost_scsi_list);
--
2.47.1
Powered by blists - more mailing lists