From f8bd4809aa44d61202abbde1b5a7510b277e623b Mon Sep 17 00:00:00 2001 From: Ksawlii Date: Sun, 24 Nov 2024 00:23:00 +0100 Subject: [PATCH] Revert "vhost/scsi: null-ptr-dereference in vhost_scsi_get_req()" This reverts commit 11889a0690397a828adb1795a3f0f5e82d03a1e9. --- drivers/vhost/scsi.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index a23a65e7d..4ce9f00ae 100755 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -919,23 +919,20 @@ vhost_scsi_get_req(struct vhost_virtqueue *vq, struct vhost_scsi_ctx *vc, /* virtio-scsi spec requires byte 0 of the lun to be 1 */ vq_err(vq, "Illegal virtio-scsi lun: %u\n", *vc->lunp); } else { - struct vhost_scsi_tpg **vs_tpg, *tpg = NULL; + struct vhost_scsi_tpg **vs_tpg, *tpg; - if (vc->target) { - /* validated at handler entry */ - vs_tpg = vhost_vq_get_backend(vq); - tpg = READ_ONCE(vs_tpg[*vc->target]); - if (unlikely(!tpg)) { - vq_err(vq, "Target 0x%x does not exist\n", *vc->target); - goto out; - } + vs_tpg = vhost_vq_get_backend(vq); /* validated at handler entry */ + + tpg = READ_ONCE(vs_tpg[*vc->target]); + if (unlikely(!tpg)) { + vq_err(vq, "Target 0x%x does not exist\n", *vc->target); + } else { + if (tpgp) + *tpgp = tpg; + ret = 0; } - - if (tpgp) - *tpgp = tpg; - ret = 0; } -out: + return ret; }