From 06bce26589f430b620c9a6041a4e04b378586def Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 13 Oct 2026 15:10:04 -0700 Subject: [PATCH] scsi: scsi_debug: Split corrupt_lbas() Move the inner logic of corrupt_lbas() into a new helper function __corrupt_lbas() and call it from separate locked and unlocked branches in corrupt_lbas(). This patch prepares for enabling context analysis. Reviewed-by: Christoph Hellwig Reviewed-by: John Garry Signed-off-by: Bart Van Assche Link: https://patch.msgid.link/fe8629d9d7d0a54e8c5c14539953b40c09a6855a.1791924924.git.bvanassche@acm.org Signed-off-by: Martin K. Petersen (Oracle) --- drivers/scsi/scsi_debug.c | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index cadd94e17109..eafcadc6ef07 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4984,37 +4984,25 @@ static int resp_write_tape(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return 0; } -static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num, - u32 nr_bit_errors, s32 reftag_adjust) +static int __corrupt_lbas(struct sdeb_store_info *sip, u64 lba, u32 num, + u32 nr_bit_errors, s32 reftag_adjust, bool lbp) { - struct sdeb_store_info *sip = devip2sip(devip, false); - bool meta_data_locked = false; - bool lbp = scsi_debug_lbp(); u32 block, num_mapped, b, i; - int error = 0; - - if (sdebug_dev_is_zoned(devip) || sdebug_dix || lbp) { - sdeb_meta_write_lock(sip); - meta_data_locked = true; - } if (!sip) { pr_err("can't corrupt with fake_rw\n"); - error = -EINVAL; - goto out_unlock; + return -EINVAL; } if (num > sdebug_capacity || lba > sdebug_capacity - num) { pr_err("logical blocks out of bounds: %llu:%u", lba, num); - error = -EINVAL; - goto out_unlock; + return -EINVAL; } if (lbp && (!map_state(sip, lba, &num_mapped) || num > num_mapped)) { pr_err("can't modify unmapped logical blocks: %llu:%u", lba, num); - error = -EINVAL; - goto out_unlock; + return -EINVAL; } /* @@ -5052,9 +5040,25 @@ static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num, } sdeb_data_unlock(sip, false); -out_unlock: - if (meta_data_locked) + return 0; +} + +static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num, + u32 nr_bit_errors, s32 reftag_adjust) +{ + struct sdeb_store_info *sip = devip2sip(devip, false); + const bool lbp = scsi_debug_lbp(); + int error = 0; + + if (sdebug_dev_is_zoned(devip) || sdebug_dix || lbp) { + sdeb_meta_write_lock(sip); + error = __corrupt_lbas(sip, lba, num, nr_bit_errors, + reftag_adjust, lbp); sdeb_meta_write_unlock(sip); + } else { + error = __corrupt_lbas(sip, lba, num, nr_bit_errors, + reftag_adjust, lbp); + } return error; }