From 2bc11c1d4571c7a2fd302dc26e984c2079798c75 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 13 Oct 2026 15:10:03 -0700 Subject: [PATCH] scsi: scsi_debug: Split resp_write_same() Since the Clang thread-safety analyzer does not support conditional locking, split the function resp_write_same() such that all locking statements end up in the same branch of an if-statement. Reviewed-by: Christoph Hellwig Reviewed-by: John Garry Signed-off-by: Bart Van Assche Link: https://patch.msgid.link/1127ce1be450f0c4503845b41eaa24c27aba373a.1791924924.git.bvanassche@acm.org Signed-off-by: Martin K. Petersen (Oracle) --- drivers/scsi/scsi_debug.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 44b4587b53c6..cadd94e17109 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5412,8 +5412,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, return ret; } -static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, - u32 ei_lba, bool unmap, bool ndob) +static int __resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, + u32 ei_lba, bool unmap, bool ndob, bool lbp) { struct scsi_device *sdp = scp->device; struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; @@ -5425,21 +5425,14 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, scp->device->hostdata, true); u8 *fs1p; u8 *fsp; - bool meta_data_locked = false; - bool lbp = scsi_debug_lbp(); - - if (sdebug_dev_is_zoned(devip) || lbp) { - sdeb_meta_write_lock(sip); - meta_data_locked = true; - } ret = check_device_access_params(scp, lba, num, true); if (ret) - goto out; + return ret; if (unmap && lbp) { unmap_region(sip, lba, num); - goto out; + return ret; } lbaa = lba; block = do_div(lbaa, sdebug_store_sectors); @@ -5475,9 +5468,28 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ret = 0; unlock: sdeb_data_write_unlock(sip); -out: - if (meta_data_locked) + return ret; +} + +static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u32 ei_lba, + bool unmap, bool ndob) +{ + struct scsi_device *sdp = scp->device; + struct sdebug_dev_info *devip = sdp->hostdata; + struct sdeb_store_info *sip = devip2sip(devip, true); + const bool lbp = scsi_debug_lbp(); + int ret; + + if (sdebug_dev_is_zoned(devip) || lbp) { + sdeb_meta_write_lock(sip); + ret = __resp_write_same(scp, lba, num, ei_lba, unmap, ndob, + lbp); sdeb_meta_write_unlock(sip); + } else { + ret = __resp_write_same(scp, lba, num, ei_lba, unmap, ndob, + lbp); + } + return ret; }