scsi: core: Use struct scsi_sense_hdr to log sense keys and codes

Instead of passing the sense key, additional sense code and additional
sense code qualifier as separate parameters, change the functions
scsi_extd_sense_format(), scsi_format_extd_sense(), and
usb_stor_show_sense() to take a pointer to a struct scsi_sense_hdr to
access the sense key and sense code with a single argument.

No functional change intended.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Link: https://patch.msgid.link/20260908090308.1085097-7-dlemoal@kernel.org
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
This commit is contained in:
Damien Le Moal 2026-09-08 18:02:34 +09:00 committed by Martin K. Petersen (Oracle)
parent ec5562d3ea
commit 319c440e4e
6 changed files with 28 additions and 28 deletions

View File

@ -377,22 +377,21 @@ EXPORT_SYMBOL(scsi_sense_key_string);
* This string may contain a "%x" and should be printed with ascq as arg.
*/
const char *
scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
scsi_extd_sense_format(const struct scsi_sense_hdr *sshdr, const char **fmt)
{
u16 code = scsi_sense_code(asc, ascq);
unsigned offset = 0;
int i;
*fmt = NULL;
for (i = 0; i < ARRAY_SIZE(additional); i++) {
if (additional[i].code == code)
if (additional[i].code == sshdr->sense_code)
return additional_text + offset;
offset += additional[i].size;
}
for (i = 0; additional2[i].fmt; i++) {
if (additional2[i].asc == asc &&
ascq >= additional2[i].ascq_min &&
ascq <= additional2[i].ascq_max) {
if (additional2[i].asc == scsi_sense_asc(sshdr) &&
scsi_sense_ascq(sshdr) >= additional2[i].ascq_min &&
scsi_sense_ascq(sshdr) <= additional2[i].ascq_max) {
*fmt = additional2[i].fmt;
return additional2[i].str;
}

View File

@ -238,29 +238,32 @@ EXPORT_SYMBOL(scsi_print_command);
static size_t
scsi_format_extd_sense(char *buffer, size_t buf_len,
unsigned char asc, unsigned char ascq)
const struct scsi_sense_hdr *sshdr)
{
size_t off = 0;
const char *extd_sense_fmt = NULL;
const char *extd_sense_str = scsi_extd_sense_format(asc, ascq,
&extd_sense_fmt);
const char *extd_sense_str =
scsi_extd_sense_format(sshdr, &extd_sense_fmt);
if (extd_sense_str) {
off = scnprintf(buffer, buf_len, "Add. Sense: %s",
extd_sense_str);
if (extd_sense_fmt)
off += scnprintf(buffer + off, buf_len - off,
"(%s%x)", extd_sense_fmt, ascq);
"(%s%x)", extd_sense_fmt,
scsi_sense_ascq(sshdr));
} else {
if (asc >= 0x80)
if (scsi_sense_asc(sshdr) >= 0x80)
off = scnprintf(buffer, buf_len, "<<vendor>>");
off += scnprintf(buffer + off, buf_len - off,
"ASC=0x%x ", asc);
if (ascq >= 0x80)
"ASC=0x%x ",
scsi_sense_asc(sshdr));
if (scsi_sense_ascq(sshdr) >= 0x80)
off += scnprintf(buffer + off, buf_len - off,
"<<vendor>>");
off += scnprintf(buffer + off, buf_len - off,
"ASCQ=0x%x ", ascq);
"ASCQ=0x%x ",
scsi_sense_ascq(sshdr));
}
return off;
}
@ -333,8 +336,7 @@ scsi_log_print_sense_hdr(const struct scsi_device *sdev, const char *name,
if (!logbuf)
return;
off = sdev_format_header(logbuf, logbuf_len, name, tag);
off += scsi_format_extd_sense(logbuf + off, logbuf_len - off,
sshdr->asc, sshdr->ascq);
off += scsi_format_extd_sense(logbuf + off, logbuf_len - off, sshdr);
dev_printk(KERN_INFO, &sdev->sdev_gendev, "%s", logbuf);
scsi_log_release_buffer(logbuf);
}

View File

@ -141,14 +141,12 @@ void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
}
void usb_stor_show_sense(const struct us_data *us,
unsigned char key,
unsigned char asc,
unsigned char ascq)
const struct scsi_sense_hdr *sshdr)
{
const char *what, *keystr, *fmt;
keystr = scsi_sense_key_string(key);
what = scsi_extd_sense_format(asc, ascq, &fmt);
keystr = scsi_sense_key_string(sshdr->sense_key);
what = scsi_extd_sense_format(sshdr, &fmt);
if (keystr == NULL)
keystr = "(Unknown Key)";
@ -156,7 +154,8 @@ void usb_stor_show_sense(const struct us_data *us,
what = "(unknown ASC/ASCQ)";
if (fmt)
usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt, ascq);
usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt,
scsi_sense_ascq(sshdr));
else
usb_stor_dbg(us, "%s: %s\n", keystr, what);
}

View File

@ -31,8 +31,8 @@
#ifdef CONFIG_USB_STORAGE_DEBUG
void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb);
void usb_stor_show_sense(const struct us_data *us, unsigned char key,
unsigned char asc, unsigned char ascq);
void usb_stor_show_sense(const struct us_data *us,
const struct scsi_sense_hdr *sshdr);
__printf(2, 3) void usb_stor_dbg(const struct us_data *us,
const char *fmt, ...);

View File

@ -805,7 +805,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
sshdr.response_code, sshdr.sense_key,
sshdr.asc, sshdr.ascq);
#ifdef CONFIG_USB_STORAGE_DEBUG
usb_stor_show_sense(us, sshdr.sense_key, sshdr.asc, sshdr.ascq);
usb_stor_show_sense(us, &sshdr);
#endif
/* set the result so the higher layers expect this data */

View File

@ -20,8 +20,8 @@ extern void scsi_print_result(struct scsi_cmnd *, const char *, int);
#ifdef CONFIG_SCSI_CONSTANTS
extern bool scsi_opcode_sa_name(int, int, const char **, const char **);
extern const char *scsi_sense_key_string(unsigned char);
extern const char *scsi_extd_sense_format(unsigned char, unsigned char,
const char **);
extern const char *scsi_extd_sense_format(const struct scsi_sense_hdr *sshdr,
const char **fmt);
extern const char *scsi_mlreturn_string(int);
extern const char *scsi_hostbyte_string(int);
#else
@ -57,7 +57,7 @@ scsi_sense_key_string(unsigned char key)
}
static inline const char *
scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
scsi_extd_sense_format(const struct scsi_sense_hdr *sshdr, const char **fmt)
{
*fmt = NULL;
return NULL;