All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
	"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>,
	linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org,
	Niklas Cassel <cassel@kernel.org>,
	linux-usb@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-s390@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>
Subject: [PATCH v2 06/40] scsi: use struct scsi_sense_hdr to log sense keys and codes
Date: Thu,  3 Sep 2026 12:41:27 +0900	[thread overview]
Message-ID: <20260903034201.112211-7-dlemoal@kernel.org> (raw)
In-Reply-To: <20260903034201.112211-1-dlemoal@kernel.org>

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>
---
 drivers/scsi/constants.c        | 11 +++++------
 drivers/scsi/scsi_logging.c     | 22 ++++++++++++----------
 drivers/usb/storage/debug.c     | 12 +++++-------
 drivers/usb/storage/debug.h     |  4 ++--
 drivers/usb/storage/transport.c |  2 +-
 include/scsi/scsi_dbg.h         |  6 +++---
 6 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 4b97f574fe8c..57b51c4529c3 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -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;
 		}
diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c
index 3cd0d3074085..0a9a2f7c1966 100644
--- a/drivers/scsi/scsi_logging.c
+++ b/drivers/scsi/scsi_logging.c
@@ -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);
 }
diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index dda610f689b7..4cc5a019382a 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -140,15 +140,12 @@ void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
 		     (const unsigned char *)srb->cmnd);
 }
 
-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, 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 +153,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);
 }
diff --git a/drivers/usb/storage/debug.h b/drivers/usb/storage/debug.h
index a6505ceb6693..616e518eeb21 100644
--- a/drivers/usb/storage/debug.h
+++ b/drivers/usb/storage/debug.h
@@ -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,
+			 struct scsi_sense_hdr *sshdr);
 __printf(2, 3) void usb_stor_dbg(const struct us_data *us,
 				 const char *fmt, ...);
 
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 9a4bf86e7b6a..8e9359501d88 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -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 */
diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h
index efcdc78530d5..f21a5e3caca9 100644
--- a/include/scsi/scsi_dbg.h
+++ b/include/scsi/scsi_dbg.h
@@ -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;
-- 
2.55.0


  parent reply	other threads:[~2026-09-03  3:42 UTC|newest]

Thread overview: 130+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  3:41 [PATCH v2 00/40] Use defined 16-bits ASC/ASCQ combinations Damien Le Moal
2026-09-03  3:41 ` [PATCH v2 01/40] scsi: define all additional sense codes and their qualifiers Damien Le Moal
2026-09-03  3:55   ` sashiko-bot
2026-09-03 11:54   ` Johannes Thumshirn
2026-09-07 12:01   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 02/40] scsi: constants: use defined sense codes Damien Le Moal
2026-09-03  3:53   ` sashiko-bot
2026-09-03 12:35   ` Johannes Thumshirn
2026-09-07 12:02   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 03/40] scsi: constants: rename internal struct field names Damien Le Moal
2026-09-03  3:50   ` sashiko-bot
2026-09-03 12:37   ` Johannes Thumshirn
2026-09-07 12:04   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 04/40] scsi: rename sense field of struct scsi_failure Damien Le Moal
2026-09-03  3:53   ` sashiko-bot
2026-09-07 12:10   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 05/40] scsi: prepare for using 16-bits defined sense codes Damien Le Moal
2026-09-03  3:53   ` sashiko-bot
2026-09-03 12:39   ` Johannes Thumshirn
2026-09-07 12:16   ` Hannes Reinecke
2026-09-08  0:22     ` Damien Le Moal
2026-09-08 14:29       ` Hannes Reinecke
2026-09-03  3:41 ` Damien Le Moal [this message]
2026-09-03  3:51   ` [PATCH v2 06/40] scsi: use struct scsi_sense_hdr to log sense keys and codes sashiko-bot
2026-09-07 12:18   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 07/40] scsi: core: use 16-bits defined sense codes Damien Le Moal
2026-09-03  3:56   ` sashiko-bot
2026-09-07 12:21   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 08/40] scsi: sd: " Damien Le Moal
2026-09-03  4:00   ` sashiko-bot
2026-09-07 12:25   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 09/40] scsi: sr: " Damien Le Moal
2026-09-03  3:54   ` sashiko-bot
2026-09-07 13:56   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 10/40] scsi: ses: " Damien Le Moal
2026-09-03  3:51   ` sashiko-bot
2026-09-07 12:27   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 11/40] scsi: ch: " Damien Le Moal
2026-09-03  3:50   ` sashiko-bot
2026-09-07 13:48   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 12/40] scsi: st: " Damien Le Moal
2026-09-03  3:49   ` sashiko-bot
2026-09-07 13:47   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 13/40] scsi: device_handlers: hp_sw: " Damien Le Moal
2026-09-03  3:49   ` sashiko-bot
2026-09-07 12:28   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 14/40] scsi: device_handlers: rdac: " Damien Le Moal
2026-09-03  3:51   ` sashiko-bot
2026-09-07 13:49   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 15/40] scsi: device_handlers: emc: " Damien Le Moal
2026-09-03  3:50   ` sashiko-bot
2026-09-07 13:48   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 16/40] scsi: device_handlers: alua: " Damien Le Moal
2026-09-03  3:52   ` sashiko-bot
2026-09-07 12:29   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 17/40] scsi: mpt3sas: " Damien Le Moal
2026-09-03  3:51   ` sashiko-bot
2026-09-07 12:29   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 18/40] scsi: mpi3mr: " Damien Le Moal
2026-09-03  3:51   ` sashiko-bot
2026-09-07 12:30   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 19/40] scsi: 3w-xxxx: " Damien Le Moal
2026-09-03  3:52   ` sashiko-bot
2026-09-07 13:51   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 20/40] scsi: leapraid: " Damien Le Moal
2026-09-03  3:52   ` sashiko-bot
2026-09-07 13:52   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 21/40] scsi: megaraid: " Damien Le Moal
2026-09-03  3:54   ` sashiko-bot
2026-09-07 12:33   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 22/40] scsi: myrX: " Damien Le Moal
2026-09-03  4:01   ` sashiko-bot
2026-09-07 12:34   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 23/40] scsi: smartpqi: " Damien Le Moal
2026-09-03  3:54   ` sashiko-bot
2026-09-07 12:35   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 24/40] scsi: qla2xxx: " Damien Le Moal
2026-09-03  4:00   ` sashiko-bot
2026-09-07 12:36   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 25/40] scsi: ps3rom: " Damien Le Moal
2026-09-03  4:01   ` sashiko-bot
2026-09-07 12:36   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 26/40] scsi: lpfc: " Damien Le Moal
2026-09-03  3:54   ` sashiko-bot
2026-09-07 12:37   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 27/40] scsi: stex: " Damien Le Moal
2026-09-03  3:59   ` sashiko-bot
2026-09-07 12:38   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 28/40] scsi: mvumi: " Damien Le Moal
2026-09-03  4:02   ` sashiko-bot
2026-09-07 12:38   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 29/40] scsi: libiscsi: " Damien Le Moal
2026-09-03  3:55   ` sashiko-bot
2026-09-07 12:40   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 30/40] scsi: ibmvscsi_tgt: " Damien Le Moal
2026-09-03  4:04   ` sashiko-bot
2026-09-07 12:40   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 31/40] scsi: scsi_debug: " Damien Le Moal
2026-09-03  4:01   ` sashiko-bot
2026-09-07 12:47   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 32/40] scsi: hpsa: " Damien Le Moal
2026-09-03  3:57   ` sashiko-bot
2026-09-07 12:52   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 33/40] scsi: storvsc: " Damien Le Moal
2026-09-03  3:58   ` sashiko-bot
2026-09-07 12:53   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 34/40] target: " Damien Le Moal
2026-09-03  4:02   ` sashiko-bot
2026-09-07 12:55   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 35/40] usb: storage: " Damien Le Moal
2026-09-03  4:01   ` sashiko-bot
2026-09-07 12:56   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 36/40] cdrom: " Damien Le Moal
2026-09-03  3:57   ` sashiko-bot
2026-09-07 13:17   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 37/40] ata: libata: " Damien Le Moal
2026-09-03  4:06   ` sashiko-bot
2026-09-03  9:10   ` Niklas Cassel
2026-09-07 13:19   ` Hannes Reinecke
2026-09-03  3:41 ` [PATCH v2 38/40] s390: scsi: " Damien Le Moal
2026-09-03  4:01   ` sashiko-bot
2026-09-07 13:20   ` Hannes Reinecke
2026-09-08  0:24     ` Damien Le Moal
2026-09-03  3:42 ` [PATCH v2 39/40] scsi: cleanup scsi_proto.h Damien Le Moal
2026-09-03  4:00   ` sashiko-bot
2026-09-07 13:41   ` Hannes Reinecke
2026-09-03  3:42 ` [PATCH v2 40/40] scsi: remove scsi_build_sense() and scsi_build_sense_buffer() Damien Le Moal
2026-09-03  3:58   ` sashiko-bot
2026-09-03  9:15   ` Niklas Cassel
2026-09-07 13:43   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260903034201.112211-7-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=cassel@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hca@linux.ibm.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.