Skip to content

Commit e63350d

Browse files
Merge patch series "Improve the code for showing commands in debugfs"
Bart Van Assche <[email protected]> says: Hi Martin, The SCSI debugfs code may show information in debugfs that is invalid. Hence this patch series that makes sure only valid information is shown in debugfs. Please consider this patch series for the next merge window. Thanks, Bart. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
2 parents a0c25d6 + ba0f09b commit e63350d

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

drivers/scsi/scsi_debugfs.c

Lines changed: 31 additions & 25 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,38 +33,43 @@ 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;
4259
char buf[80] = "(?)";
4360

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);
61+
if (cmd->flags & SCMD_INITIALIZED) {
62+
const char *list_info = scsi_cmd_list_info(cmd);
5963

60-
__scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len);
61-
seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x, %s%s.flags=",
62-
buf, cmd->retries, cmd->allowed, cmd->result,
63-
list_info ? : "", list_info ? ", " : "");
64+
__scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len);
65+
seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x%s%s",
66+
buf, cmd->retries, cmd->allowed, cmd->result,
67+
list_info ? ", " : "", list_info ? : "");
68+
seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago",
69+
timeout_ms / 1000, timeout_ms % 1000,
70+
alloc_ms / 1000, alloc_ms % 1000);
71+
}
72+
seq_printf(m, ", .flags=");
6473
scsi_flags_show(m, cmd->flags, scsi_cmd_flags,
6574
ARRAY_SIZE(scsi_cmd_flags));
66-
seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago",
67-
timeout_ms / 1000, timeout_ms % 1000,
68-
alloc_ms / 1000, alloc_ms % 1000);
6975
}

0 commit comments

Comments
 (0)