Re: [PATCH] scsi: Correct sysfs attributes access rights

John Garry
2025-07-28T09:40:35Z

On 28/07/2025 05:17, Damien Le Moal wrote:
> The scsi sysfs attributes "supported_mode" and "active_mode" do not
> define a store method and thus cannot be modified. Correct the
> DEVICE_ATTR() call for these two attributes to not include S_IWUSR to
> allow write access as they are read-only.
>
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>

Reviewed-by: John Garry <john.g.garry@oracle.com>

Note that class_attr_store() returns -EIO for no store method. Does the
same happen after this change?

> ---
> drivers/scsi/scsi_sysfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index d772258e29ad..e6464b998960 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -265,7 +265,7 @@ show_shost_supported_mode(struct device *dev, struct device_attribute *attr,
> return show_shost_mode(supported_mode, buf);
> }
>
> -static DEVICE_ATTR(supported_mode, S_IRUGO | S_IWUSR, show_shost_supported_mode, NULL);
> +static DEVICE_ATTR(supported_mode, S_IRUGO, show_shost_supported_mode, NULL);
>
> static ssize_t
> show_shost_active_mode(struct device *dev,
> @@ -279,7 +279,7 @@ show_shost_active_mode(struct device *dev,
> return show_shost_mode(shost->active_mode, buf);
> }
>
> -static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
> +static DEVICE_ATTR(active_mode, S_IRUGO, show_shost_active_mode, NULL);
>
> static int check_reset_type(const char *str)
> {