Re: [PATCH v2 1/3] hwmon: (core) Constify device attributes

[email protected] Thu, 06 Aug 2026 06:20:48 +0000
Newsgroups org.kernel.vger.linux-hwmon
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incomplete constification of device attributes: the `pec` attribute was missed.
--

--- Patch [1]: [PATCH v2 1/3] hwmon: (core) Constify device attributes ---
commit 63bf6c9fac5c27892b6188fad21e12ff51c4b53a
Author: Thomas Weißschuh <[email protected]>

hwmon: (core) Constify device attributes

This commit updates the hwmon core to mark device attribute structures as const
since they are never modified. It also updates the show callbacks and visibility
functions to accept const arguments.

> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index 55a9a3ddd4aac..84108a16ef60c 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -71,27 +71,27 @@ struct hwmon_thermal_data {
>  };
>  
>  static ssize_t
> -name_show(struct device *dev, struct device_attribute *attr, char *buf)
> +name_show(struct device *dev, const struct device_attribute *attr, char *buf)
>  {
>  	return sysfs_emit(buf, "%s\n", to_hwmon_device(dev)->name);
>  }
> -static DEVICE_ATTR_RO(name);
> +static const DEVICE_ATTR_RO(name);
>  
>  static ssize_t
> -label_show(struct device *dev, struct device_attribute *attr, char *buf)
> +label_show(struct device *dev, const struct device_attribute *attr, char *buf)
>  {
>  	return sysfs_emit(buf, "%s\n", to_hwmon_device(dev)->label);
>  }
> -static DEVICE_ATTR_RO(label);
> +static const DEVICE_ATTR_RO(label);

[Severity: Low]
This isn't a bug, but should the pec attribute also be constified?

The pec attribute is defined further down in drivers/hwmon/hwmon.c but seems to
have been missed by this refactoring:

static ssize_t pec_show(struct device *dev, struct device_attribute *dummy,
			char *buf)

static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,
			 const char *buf, size_t count)

static DEVICE_ATTR_RW(pec);

Since device_create_file() accepts a const struct device_attribute, could we
update pec_show(), pec_store(), and the pec device attribute to be const as
well?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1