Skip to content

Commit 9972c02

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Introduce scsi_cmd_list_info()
Slightly improve code readability by introducing a helper function for deriving the list information and by using guard() + return instead of goto + explicit unlock + return. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20240325224755.1477910-2-bvanassche@acm.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 4cece76 commit 9972c02

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

drivers/scsi/scsi_debugfs.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/bitops.h>
3+
#include <linux/cleanup.h>
34
#include <linux/seq_file.h>
45
#include <scsi/scsi_cmnd.h>
56
#include <scsi/scsi_dbg.h>
@@ -32,31 +33,32 @@ static int scsi_flags_show(struct seq_file *m, const unsigned long flags,
3233
return 0;
3334
}
3435

35-
void scsi_show_rq(struct seq_file *m, struct request *rq)
36+
static const char *scsi_cmd_list_info(struct scsi_cmnd *cmd)
3637
{
37-
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq), *cmd2;
3838
struct Scsi_Host *shost = cmd->device->host;
39+
struct scsi_cmnd *cmd2;
40+
41+
guard(spinlock_irq)(shost->host_lock);
42+
43+
list_for_each_entry(cmd2, &shost->eh_abort_list, eh_entry)
44+
if (cmd == cmd2)
45+
return "on eh_abort_list";
46+
47+
list_for_each_entry(cmd2, &shost->eh_cmd_q, eh_entry)
48+
if (cmd == cmd2)
49+
return "on eh_cmd_q";
50+
51+
return NULL;
52+
}
53+
54+
void scsi_show_rq(struct seq_file *m, struct request *rq)
55+
{
56+
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
3957
int alloc_ms = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc);
4058
int timeout_ms = jiffies_to_msecs(rq->timeout);
41-
const char *list_info = NULL;
59+
const char *list_info = scsi_cmd_list_info(cmd);
4260
char buf[80] = "(?)";
4361

44-
spin_lock_irq(shost->host_lock);
45-
list_for_each_entry(cmd2, &shost->eh_abort_list, eh_entry) {
46-
if (cmd == cmd2) {
47-
list_info = "on eh_abort_list";
48-
goto unlock;
49-
}
50-
}
51-
list_for_each_entry(cmd2, &shost->eh_cmd_q, eh_entry) {
52-
if (cmd == cmd2) {
53-
list_info = "on eh_cmd_q";
54-
goto unlock;
55-
}
56-
}
57-
unlock:
58-
spin_unlock_irq(shost->host_lock);
59-
6062
__scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len);
6163
seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x, %s%s.flags=",
6264
buf, cmd->retries, cmd->allowed, cmd->result,

0 commit comments

Comments
 (0)