* [PATCH] scsi: core: Do not declare scsi_cmnd pointers const
@ 2025-10-14 22:04 Bart Van Assche
2025-10-20 11:39 ` John Garry
2025-10-22 1:13 ` Martin K. Petersen
0 siblings, 2 replies; 4+ messages in thread
From: Bart Van Assche @ 2025-10-14 22:04 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Bart Van Assche, Hannes Reinecke, John Garry,
James E.J. Bottomley
This change allows removing multiple casts and hence improves type checking
by the compiler.
Cc: Hannes Reinecke <hare@suse.de>
Suggested-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_logging.c | 21 ++++++++++-----------
include/scsi/scsi_dbg.h | 4 ++--
include/scsi/scsi_device.h | 4 ++--
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c
index b02af340c2d3..3cd0d3074085 100644
--- a/drivers/scsi/scsi_logging.c
+++ b/drivers/scsi/scsi_logging.c
@@ -26,9 +26,9 @@ static void scsi_log_release_buffer(char *bufptr)
kfree(bufptr);
}
-static inline const char *scmd_name(const struct scsi_cmnd *scmd)
+static inline const char *scmd_name(struct scsi_cmnd *scmd)
{
- struct request *rq = scsi_cmd_to_rq((struct scsi_cmnd *)scmd);
+ const struct request *rq = scsi_cmd_to_rq(scmd);
if (!rq->q || !rq->q->disk)
return NULL;
@@ -80,8 +80,8 @@ void sdev_prefix_printk(const char *level, const struct scsi_device *sdev,
}
EXPORT_SYMBOL(sdev_prefix_printk);
-void scmd_printk(const char *level, const struct scsi_cmnd *scmd,
- const char *fmt, ...)
+void scmd_printk(const char *level, struct scsi_cmnd *scmd, const char *fmt,
+ ...)
{
va_list args;
char *logbuf;
@@ -94,7 +94,7 @@ void scmd_printk(const char *level, const struct scsi_cmnd *scmd,
if (!logbuf)
return;
off = sdev_format_header(logbuf, logbuf_len, scmd_name(scmd),
- scsi_cmd_to_rq((struct scsi_cmnd *)scmd)->tag);
+ scsi_cmd_to_rq(scmd)->tag);
if (off < logbuf_len) {
va_start(args, fmt);
off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args);
@@ -371,16 +371,15 @@ void __scsi_print_sense(const struct scsi_device *sdev, const char *name,
EXPORT_SYMBOL(__scsi_print_sense);
/* Normalize and print sense buffer in SCSI command */
-void scsi_print_sense(const struct scsi_cmnd *cmd)
+void scsi_print_sense(struct scsi_cmnd *cmd)
{
scsi_log_print_sense(cmd->device, scmd_name(cmd),
- scsi_cmd_to_rq((struct scsi_cmnd *)cmd)->tag,
- cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
+ scsi_cmd_to_rq(cmd)->tag, cmd->sense_buffer,
+ SCSI_SENSE_BUFFERSIZE);
}
EXPORT_SYMBOL(scsi_print_sense);
-void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg,
- int disposition)
+void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition)
{
char *logbuf;
size_t off, logbuf_len;
@@ -393,7 +392,7 @@ void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg,
return;
off = sdev_format_header(logbuf, logbuf_len, scmd_name(cmd),
- scsi_cmd_to_rq((struct scsi_cmnd *)cmd)->tag);
+ scsi_cmd_to_rq(cmd)->tag);
if (off >= logbuf_len)
goto out_printk;
diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h
index bd29cdb513a5..efcdc78530d5 100644
--- a/include/scsi/scsi_dbg.h
+++ b/include/scsi/scsi_dbg.h
@@ -11,11 +11,11 @@ extern size_t __scsi_format_command(char *, size_t,
const unsigned char *, size_t);
extern void scsi_print_sense_hdr(const struct scsi_device *, const char *,
const struct scsi_sense_hdr *);
-extern void scsi_print_sense(const struct scsi_cmnd *);
+extern void scsi_print_sense(struct scsi_cmnd *);
extern void __scsi_print_sense(const struct scsi_device *, const char *name,
const unsigned char *sense_buffer,
int sense_len);
-extern void scsi_print_result(const struct scsi_cmnd *, const char *, int);
+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 **);
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 6d6500148c4b..4c106342c4ae 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -313,8 +313,8 @@ sdev_prefix_printk(const char *, const struct scsi_device *, const char *,
#define sdev_printk(l, sdev, fmt, a...) \
sdev_prefix_printk(l, sdev, NULL, fmt, ##a)
-__printf(3, 4) void
-scmd_printk(const char *, const struct scsi_cmnd *, const char *, ...);
+__printf(3, 4) void scmd_printk(const char *, struct scsi_cmnd *, const char *,
+ ...);
#define scmd_dbg(scmd, fmt, a...) \
do { \
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: core: Do not declare scsi_cmnd pointers const
2025-10-14 22:04 [PATCH] scsi: core: Do not declare scsi_cmnd pointers const Bart Van Assche
@ 2025-10-20 11:39 ` John Garry
2025-10-20 15:44 ` Bart Van Assche
2025-10-22 1:13 ` Martin K. Petersen
1 sibling, 1 reply; 4+ messages in thread
From: John Garry @ 2025-10-20 11:39 UTC (permalink / raw)
To: Bart Van Assche, Martin K . Petersen
Cc: linux-scsi, Hannes Reinecke, James E.J. Bottomley
On 14/10/2025 23:04, Bart Van Assche wrote:
Maybe mention in the title that we are touching the scsi logging code
> This change allows removing multiple casts and hence improves type checking
> by the compiler.
>
> Cc: Hannes Reinecke <hare@suse.de>
> Suggested-by: John Garry <john.g.garry@oracle.com>
thanks
Reviewed-by: John Garry <john.g.garry@oracle.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> drivers/scsi/scsi_logging.c | 21 ++++++++++-----------
> include/scsi/scsi_dbg.h | 4 ++--
> include/scsi/scsi_device.h | 4 ++--
> 3 files changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c
> index b02af340c2d3..3cd0d3074085 100644
> --- a/drivers/scsi/scsi_logging.c
> +++ b/drivers/scsi/scsi_logging.c
> @@ -26,9 +26,9 @@ static void scsi_log_release_buffer(char *bufptr)
> kfree(bufptr);
> }
>
> -static inline const char *scmd_name(const struct scsi_cmnd *scmd)
> +static inline const char *scmd_name(struct scsi_cmnd *scmd)
> {
> - struct request *rq = scsi_cmd_to_rq((struct scsi_cmnd *)scmd);
> + const struct request *rq = scsi_cmd_to_rq(scmd);
do you really need to declare this a pointer to const? Or just a good
practice?
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] scsi: core: Do not declare scsi_cmnd pointers const
2025-10-20 11:39 ` John Garry
@ 2025-10-20 15:44 ` Bart Van Assche
0 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2025-10-20 15:44 UTC (permalink / raw)
To: John Garry, Martin K . Petersen
Cc: linux-scsi, Hannes Reinecke, James E.J. Bottomley
On 10/20/25 4:39 AM, John Garry wrote:
> On 14/10/2025 23:04, Bart Van Assche wrote:
>> diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c
>> index b02af340c2d3..3cd0d3074085 100644
>> --- a/drivers/scsi/scsi_logging.c
>> +++ b/drivers/scsi/scsi_logging.c
>> @@ -26,9 +26,9 @@ static void scsi_log_release_buffer(char *bufptr)
>> kfree(bufptr);
>> }
>> -static inline const char *scmd_name(const struct scsi_cmnd *scmd)
>> +static inline const char *scmd_name(struct scsi_cmnd *scmd)
>> {
>> - struct request *rq = scsi_cmd_to_rq((struct scsi_cmnd *)scmd);
>> + const struct request *rq = scsi_cmd_to_rq(scmd);
>
> do you really need to declare this a pointer to const? Or just a good
> practice?
It's a matter of code style. In some code bases the memory a pointer
points at is always declared const if the pointer is not used to modify
that memory. In other code bases, e.g. the Linux kernel, the "const
type *" pattern is not that common.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: core: Do not declare scsi_cmnd pointers const
2025-10-14 22:04 [PATCH] scsi: core: Do not declare scsi_cmnd pointers const Bart Van Assche
2025-10-20 11:39 ` John Garry
@ 2025-10-22 1:13 ` Martin K. Petersen
1 sibling, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-10-22 1:13 UTC (permalink / raw)
To: Bart Van Assche
Cc: Martin K . Petersen, linux-scsi, Hannes Reinecke, John Garry,
James E.J. Bottomley
Bart,
> This change allows removing multiple casts and hence improves type
> checking by the compiler.
Applied to 6.19/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-22 1:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 22:04 [PATCH] scsi: core: Do not declare scsi_cmnd pointers const Bart Van Assche
2025-10-20 11:39 ` John Garry
2025-10-20 15:44 ` Bart Van Assche
2025-10-22 1:13 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).