mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurence Oberman <loberman@redhat.com>
To: shao.mingyin@zte.com.cn, mkp@kernel.org,
	 james.bottomley@hansenpartnership.com,
	linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: scsi_devinfo: return an error when the proc write fails
Date: Sat, 31 Oct 2026 15:31:29 -0400	[thread overview]
Message-ID: <721baf73d784b73015899bfe0ebca07bd8bf2a69.camel@redhat.com> (raw)
In-Reply-To: <20261031222133489hI-BEIDpFMxrtlntnLiFb@zte.com.cn>

On Sat, 2026-10-31 at 22:21 +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> proc_scsi_devinfo_write() calls scsi_dev_info_list_add_str() but
> ignores
> its return value, so a write to /proc/scsi/device_info always reports
> success, even when the string is malformed and no entry was added. 
> Users
> and scripts then believe that the quirk is in effect.
> 
> scsi_init_devinfo() already checks the return value of the same
> function
> and fails the initialization.  Return the parser error, but keep
> returning
> the number of bytes written on success: a proc write handler that
> returns
> zero for a non-empty write would look like a short write to the
> caller.
> 
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
> diff --git a/drivers/scsi/scsi_devinfo.c
> b/drivers/scsi/scsi_devinfo.c
> index cfc259fd0141..b1f3bcd739b4 100644
> --- a/drivers/scsi/scsi_devinfo.c
> +++ b/drivers/scsi/scsi_devinfo.c
> @@ -688,6 +688,7 @@ static ssize_t proc_scsi_devinfo_write(struct
> file *file,
>  {
>  	char *buffer;
>  	ssize_t err = length;
> +	int ret;
> 
>  	if (!buf || length>PAGE_SIZE)
>  		return -EINVAL;
> @@ -706,7 +707,9 @@ static ssize_t proc_scsi_devinfo_write(struct
> file *file,
>  		goto out;
>  	}
> 
> -	scsi_dev_info_list_add_str(buffer);
> +	ret = scsi_dev_info_list_add_str(buffer);
> +	if (ret)
> +		err = ret;
> 
>  out:
>  	kfree(buffer);

Looks good to me.

Note that a multi-entry write can still partially apply (entries before
the bad one are added, then -EINVAL is returned), but reporting the
error is a clear improvement over silent success.

Reviewed-by: Laurence Oberman <loberman@redhat.com>


      reply	other threads:[~2026-10-31 19:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 14:21 shao.mingyin
2026-10-31 19:31 ` Laurence Oberman [this message]

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=721baf73d784b73015899bfe0ebca07bd8bf2a69.camel@redhat.com \
    --to=loberman@redhat.com \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --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

all inboxes | Powered by JetHome®