Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: shao.mingyin@zte.com.cn, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: proc: use snprintf() for the host name
Date: Mon, 09 Nov 2026 03:46:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-204381@kernel.org> (raw)
In-Reply-To: <20261109113810258gK5WuYWQKt0HsI2ikxmHo@zte.com.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: proc: host_no truncation in scsi_proc_host_add() and
  scsi_proc_host_rm()
--

commit 3f018a4fb0e8a43b35d69140bbb854cdcd245155
Author: Shao Mingyin <shao.mingyin@zte.com.cn>

scsi: proc: use snprintf() for the host name

This commit replaces sprintf() with snprintf() when formatting
shost->host_no into the 10-byte name buffer in scsi_proc_host_add() and
scsi_proc_host_rm().

> diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
> index fdc355d783da3..d1f474c287206 100644
> --- a/drivers/scsi/scsi_proc.c
> +++ b/drivers/scsi/scsi_proc.c
> @@ -230,7 +230,7 @@ void scsi_proc_host_add(struct Scsi_Host *shost)
>  	if (!e)
>  		goto err;
>  
> -	sprintf(name,"%d", shost->host_no);
> +	snprintf(name, sizeof(name), "%d", shost->host_no);
>  	p = proc_create_data(name, S_IRUGO | S_IWUSR, e->proc_dir,
>  			     &proc_scsi_ops, shost);
>  	if (!p)
> @@ -260,7 +260,7 @@ void scsi_proc_host_rm(struct Scsi_Host *shost)
>  	if (!e)
>  		return;
>  
> -	sprintf(name,"%d", shost->host_no);
> +	snprintf(name, sizeof(name), "%d", shost->host_no);
>  	remove_proc_entry(name, e->proc_dir);
>  }
>  /**

[Severity: Medium]
Does keeping char name[10] still truncate 10-digit shost->host_no values to
9 digits?  Once shost->host_no reaches 10 digits, proc_create_data()
collides with the existing 9-digit procfs entry, and later calling
scsi_proc_host_rm() removes that active host's entry instead.

Formatting a 32-bit int with %d into a 10-byte buffer via an unchecked
snprintf() also triggers -Wformat-truncation warnings under W=1 builds.
Sizing name[] to at least 11 bytes and using %u for the unsigned int
shost->host_no avoids both truncation and the compiler warning.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109113810258gK5WuYWQKt0HsI2ikxmHo@zte.com.cn?part=1

  reply	other threads:[~2026-11-09  3:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  3:38 [PATCH] scsi: proc: use snprintf() for the host name shao.mingyin
2026-11-09  3:46 ` sashiko-bot [this message]
2026-11-09  5:56   ` shao.mingyin

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=sashiko-outbox-204381@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shao.mingyin@zte.com.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox