Skip to content

Commit 3fd07ae

Browse files
Damien Le Moalmartinkpetersen
authored andcommitted
scsi: scsi_debug: Fix qc_lock use in sdebug_blk_mq_poll()
The use of the 'locked' boolean variable to control locking and unlocking of the qc_lock spinlock of struct sdebug_queue confuses sparse, leading to a warning about an unexpected unlock. Simplify the qc_lock lock/unlock handling code of this function to avoid this warning by removing the 'locked' boolean variable. This change also fixes unlocked access to the in_use_bm bitmap with the find_first_bit() function. Link: https://lore.kernel.org/r/[email protected] Fixes: b05d4e4 ("scsi: scsi_debug: Refine sdebug_blk_mq_poll()") Cc: [email protected] Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent e9c4780 commit 3fd07ae

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,7 +7509,6 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
75097509
{
75107510
bool first;
75117511
bool retiring = false;
7512-
bool locked = false;
75137512
int num_entries = 0;
75147513
unsigned int qc_idx = 0;
75157514
unsigned long iflags;
@@ -7525,11 +7524,9 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
75257524
if (qc_idx >= sdebug_max_queue)
75267525
return 0;
75277526

7527+
spin_lock_irqsave(&sqp->qc_lock, iflags);
7528+
75287529
for (first = true; first || qc_idx + 1 < sdebug_max_queue; ) {
7529-
if (!locked) {
7530-
spin_lock_irqsave(&sqp->qc_lock, iflags);
7531-
locked = true;
7532-
}
75337530
if (first) {
75347531
first = false;
75357532
if (!test_bit(qc_idx, sqp->in_use_bm))
@@ -7586,14 +7583,15 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
75867583
}
75877584
WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE);
75887585
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
7589-
locked = false;
75907586
scsi_done(scp); /* callback to mid level */
75917587
num_entries++;
7588+
spin_lock_irqsave(&sqp->qc_lock, iflags);
75927589
if (find_first_bit(sqp->in_use_bm, sdebug_max_queue) >= sdebug_max_queue)
7593-
break; /* if no more then exit without retaking spinlock */
7590+
break;
75947591
}
7595-
if (locked)
7596-
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
7592+
7593+
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
7594+
75977595
if (num_entries > 0)
75987596
atomic_add(num_entries, &sdeb_mq_poll_count);
75997597
return num_entries;

0 commit comments

Comments
 (0)