Re: [PATCH] scsi: scsi_devinfo: return an error when the proc write fails

From: Laurence Oberman

Date: Sat Oct 31 2026 - 15:32:28 EST


On Sat, 2026-10-31 at 22:21 +0800, shao.mingyin@xxxxxxxxxx wrote:
> From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> ---
> 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@xxxxxxxxxx>