driver core: Constify the signature of device_show/store_*()
Subsystems (15)
v2 cover driver core: Constify the signature of device_show/store_*()
Prepare for the constification of 'struct dev_ext_attribute' instances by changing the signature of the standard callback functions. The first two patches prepare some drivers to handle both the const and non-const callback variants.
Intended for the driver-core tree.
---
Changes in v2:
- Rebase on v7.3-rc1.
- Cover a few more drivers in drivers/perf/.
- Link to v1: https://patch.msgid.link/20260714-sysfs-const-attr-dev_ext_attr-v1-0-6b2c0435d621@weissschuh.net
---
Thomas Weißschuh (3):
x86/mce: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute
drivers: perf: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute driver core: Constify the signature of device_show/store_*()
arch/powerpc/perf/hv-24x7.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 6 +++--- drivers/base/core.c | 30 ++++++++++++++--------------- drivers/perf/alibaba_uncore_drw_pmu.c | 2 +- drivers/perf/arm-cci.c | 2 +- drivers/perf/arm-ccn.c | 2 +- drivers/perf/arm_cspmu/arm_cspmu.h | 2 +- drivers/perf/arm_dsu_pmu.c | 2 +- drivers/perf/arm_spe_pmu.c | 6 +++--- drivers/perf/cxl_pmu.c | 10 +++++----- drivers/perf/fsl_imx8_ddr_perf.c | 2 +- drivers/perf/fujitsu_uncore_pmu.c | 2 +- drivers/perf/hisilicon/hisi_pcie_pmu.c | 2 +- drivers/perf/hisilicon/hisi_uncore_pmu.h | 6 +++--- drivers/perf/hisilicon/hns3_pmu.c | 6 +++--- drivers/perf/nvidia_t410_c2c_pmu.c | 2 +- drivers/perf/nvidia_t410_cmem_latency_pmu.c | 12 ++++++------ drivers/perf/qcom_l3_pmu.c | 8 ++++---- drivers/perf/starfive_starlink_pmu.c | 2 +- drivers/perf/xgene_pmu.c | 2 +- include/linux/device.h | 14 +++++++------- 21 files changed, 61 insertions(+), 61 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260712-sysfs-const-attr-dev_ext_attr-dbf669fdfd4e
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH v2 1/3 x86/mce: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute
The upcoming constification of the device_show_int() and device_show_bool() signatures requires the users to handle the transition automatically.
Switch to the __DEVICE_ATTR() macro which can do this.
--- arch/x86/kernel/cpu/mce/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -3
@@ -2621,17 +2621,17 @@ static DEVICE_BOOL_ATTR(dont_log_ce, 0644, mca_cfg.dont_log_ce); static DEVICE_BOOL_ATTR(print_all, 0644, mca_cfg.print_all);static struct dev_ext_attribute dev_attr_check_interval = { -__ATTR (check_interval,0644 , device_show_int, store_int_with_restart), +__DEVICE_ATTR (check_interval,0644 , device_show_int, store_int_with_restart), &check_interval };static struct dev_ext_attribute dev_attr_ignore_ce = { -__ATTR (ignore_ce,0644 , device_show_bool, set_ignore_ce), +__DEVICE_ATTR (ignore_ce,0644 , device_show_bool, set_ignore_ce), &mca_cfg.ignore_ce };static struct dev_ext_attribute dev_attr_cmci_disabled = { -__ATTR (cmci_disabled,0644 , device_show_bool, set_cmci_disabled), +__DEVICE_ATTR (cmci_disabled,0644 , device_show_bool, set_cmci_disabled), &mca_cfg.cmci_disabled };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 1/3] x86/mce: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
The upcoming constification of the
device_show_int()anddevice_show_bool()signatures requires the users to handle the transition automatically.Switch to the
__DEVICE_ATTR()macro which can do this.Signed-off-by Thomas Weißschuh <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260907-sysfs-const-attr-dev_ext_attr-v2-0-bf53afe57071@weissschuh.net?part=1
PATCH v2 2/3 drivers: perf: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute
In reply to Thomas WeißschuhThe upcoming constification of the device_show_*() callback signatures requires the users to handle the transition automatically.
Switch to the __DEVICE_ATTR() macro which can do this.
--- drivers/perf/alibaba_uncore_drw_pmu.c | 2 +- drivers/perf/arm-cci.c | 2 +- drivers/perf/arm-ccn.c | 2 +- drivers/perf/arm_cspmu/arm_cspmu.h | 2 +- drivers/perf/arm_dsu_pmu.c | 2 +- drivers/perf/arm_spe_pmu.c | 6 +++--- drivers/perf/cxl_pmu.c | 10 +++++----- drivers/perf/fsl_imx8_ddr_perf.c | 2 +- drivers/perf/fujitsu_uncore_pmu.c | 2 +- drivers/perf/hisilicon/hisi_pcie_pmu.c | 2 +- drivers/perf/hisilicon/hisi_uncore_pmu.h | 6 +++--- drivers/perf/hisilicon/hns3_pmu.c | 6 +++--- drivers/perf/nvidia_t410_c2c_pmu.c | 2 +- drivers/perf/nvidia_t410_cmem_latency_pmu.c | 12 ++++++------ drivers/perf/qcom_l3_pmu.c | 8 ++++---- drivers/perf/starfive_starlink_pmu.c | 2 +- drivers/perf/xgene_pmu.c | 2 +- 17 files changed, 35 insertions(+), 35 deletions(-)
drivers/perf/alibaba_uncore_drw_pmu.c +1 -1
@@ -135,7 +135,7 @@ static ssize_t ali_drw_pmu_event_show(struct device *dev,#define ALI_DRW_PMU_ATTR (_name, _func, _config) \ (&((struct dev_ext_attribute[]) { \ - { __ATTR(_name, 0444, _func, NULL), (void *)_config } \ + { __DEVICE_ATTR(_name, 0444, _func, NULL), (void *)_config } \ })[0].attr.attr)#define ALI_DRW_PMU_FORMAT_ATTR (_name, _config) \
drivers/perf/arm-cci.c +1 -1
@@ -132,7 +132,7 @@ static ssize_t __maybe_unused cci_pmu_event_show(struct device *dev,#define CCI_EXT_ATTR_ENTRY (_name, _func, _config) \ &((struct dev_ext_attribute[]) { \ - { __ATTR(_name, S_IRUGO, _func, NULL), (void *)_config } \ + { __DEVICE_ATTR(_name, S_IRUGO, _func, NULL), (void *)_config } \ })[0].attr.attr#define CCI_FORMAT_EXT_ATTR_ENTRY (_name, _config) \
drivers/perf/arm-ccn.c +1 -1
@@ -216,7 +216,7 @@ static void arm_ccn_pmu_config_set(u64 *config, u32 node_xp, u32 type, u32 port)#define CCN_FORMAT_ATTR (_name, _config) \ struct dev_ext_attribute arm_ccn_pmu_format_attr_##_name = \ - { __ATTR(_name, S_IRUGO, device_show_string, \ + { __DEVICE_ATTR(_name, S_IRUGO, device_show_string, \ NULL), _config } static CCN_FORMAT_ATTR(node, "config:0-7");
drivers/perf/arm_cspmu/arm_cspmu.h +1 -1
@@ -23,7 +23,7 @@#define ARM_CSPMU_EXT_ATTR (_name, _func, _config) \ (&((struct dev_ext_attribute[]){ \ { \ - .attr = __ATTR(_name, 0444, _func, NULL), \ + .attr = __DEVICE_ATTR(_name, 0444, _func, NULL),\ .var = (void *)_config \ } \ })[0].attr.attr)
drivers/perf/arm_dsu_pmu.c +1 -1
@@ -69,7 +69,7 @@#define DSU_EXT_ATTR (_name, _func, _config) \ (&((struct dev_ext_attribute[]) { \ { \ - .attr = __ATTR(_name, 0444, _func, NULL), \ + .attr = __DEVICE_ATTR(_name, 0444, _func, NULL),\ .var = (void *)_config \ } \ })[0].attr.attr)
drivers/perf/arm_spe_pmu.c +3 -3
@@ -172,9 +172,9 @@ static ssize_t arm_spe_pmu_cap_show_hex(struct device *dev,return sysfs_emit (buf,"0x%llx\n" ,arm_spe_pmu_cap_get (spe_pmu, cap)); } -#define SPE_EXT_ATTR_ENTRY (_name, _func, _var) \ - &((struct dev_ext_attribute[]) { \ - { __ATTR(_name, S_IRUGO, _func, NULL), (void *)_var } \ +#define SPE_EXT_ATTR_ENTRY (_name, _func, _var) \ + &((struct dev_ext_attribute[]) { \ + { __DEVICE_ATTR(_name, S_IRUGO, _func, NULL), (void *)_var } \ })[0].attr.attr#define SPE_CAP_EXT_ATTR_ENTRY (_name, _var) \
drivers/perf/cxl_pmu.c +5 -5
@@ -216,11 +216,11 @@ static int cxl_pmu_parse_caps(struct device *dev, struct cxl_pmu_info *info) }#define CXL_PMU_FORMAT_ATTR (_name, _format)\ - (&((struct dev_ext_attribute[]) { \ - { \ - .attr = __ATTR(_name, 0444, device_show_string, NULL), \ - .var = (void *)_format \ - } \ + (&((struct dev_ext_attribute[]) { \ + { \ + .attr = __DEVICE_ATTR(_name, 0444, device_show_string, NULL), \ + .var = (void *)_format \ + } \ })[0].attr.attr)enum {
drivers/perf/fsl_imx8_ddr_perf.c +1 -1
@@ -214,7 +214,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device *dev,#define PERF_EXT_ATTR_ENTRY (_name, _func, _var) \ (&((struct dev_ext_attribute) { \ - __ATTR(_name, 0444, _func, NULL), (void *)_var \ + __DEVICE_ATTR(_name, 0444, _func, NULL), (void *)_var \ }).attr.attr)#define PERF_FILTER_EXT_ATTR_ENTRY (_name, _var) \
drivers/perf/fujitsu_uncore_pmu.c +1 -1
@@ -291,7 +291,7 @@ static void fujitsu_uncore_event_read(struct perf_event *event)#define UNCORE_PMU_FORMAT_ATTR (_name, _config) \ (&((struct dev_ext_attribute[]) { \ - { .attr = __ATTR(_name, 0444, device_show_string, NULL), \ + { .attr = __DEVICE_ATTR(_name, 0444, device_show_string, NULL), \ .var = (void *)_config, } \ })[0].attr.attr)
drivers/perf/hisilicon/hisi_pcie_pmu.c +1 -1
@@ -110,7 +110,7 @@ static ssize_t hisi_pcie_event_sysfs_show(struct device *dev, struct device_attr#define HISI_PCIE_PMU_FORMAT_ATTR (_name, _format) \ (&((struct dev_ext_attribute[]){ \ - { .attr = __ATTR(_name, 0444, device_show_string, NULL), \ + { .attr = __DEVICE_ATTR(_name, 0444, device_show_string, NULL),\ .var = (void *)_format } \ })[0].attr.attr)
drivers/perf/hisilicon/hisi_uncore_pmu.h +3 -3
@@ -27,9 +27,9 @@#define HISI_MAX_COUNTERS 0x18#define to_hisi_pmu (p) (container_of(p, struct hisi_pmu, pmu)) -#define HISI_PMU_ATTR (_name, _func, _config) \ - (&((struct dev_ext_attribute[]) { \ - { __ATTR(_name, 0444, _func, NULL), (void *)_config } \ +#define HISI_PMU_ATTR (_name, _func, _config) \ + (&((struct dev_ext_attribute[]) { \ + { __DEVICE_ATTR(_name, 0444, _func, NULL), (void *)_config } \ })[0].attr.attr)#define HISI_PMU_FORMAT_ATTR (_name, _config) \
drivers/perf/hisilicon/hns3_pmu.c +3 -3
@@ -405,9 +405,9 @@ static ssize_t hns3_pmu_filter_mode_show(struct device *dev,return len; } -#define HNS3_PMU_ATTR (_name, _func, _config) \ - (&((struct dev_ext_attribute[]) { \ - { __ATTR(_name, 0444, _func, NULL), (void *)_config } \ +#define HNS3_PMU_ATTR (_name, _func, _config) \ + (&((struct dev_ext_attribute[]) { \ + { __DEVICE_ATTR(_name, 0444, _func, NULL), (void *)_config } \ })[0].attr.attr)#define HNS3_PMU_FORMAT_ATTR (_name, _format) \
drivers/perf/nvidia_t410_c2c_pmu.c +1 -1
@@ -545,7 +545,7 @@ static struct attribute_group nv_c2c_pmu_peer_attr_group = {#define NV_C2C_PMU_EXT_ATTR (_name, _func, _config) \ (&((struct dev_ext_attribute[]){ \ { \ - .attr = __ATTR(_name, 0444, _func, NULL), \ + .attr = __DEVICE_ATTR(_name, 0444, _func, NULL),\ .var = (void *)_config \ } \ })[0].attr.attr)
drivers/perf/nvidia_t410_cmem_latency_pmu.c +6 -6
@@ -435,12 +435,12 @@ static struct attribute_group cmem_lat_pmu_identifier_attr_group = {/* Format attributes. */ -#define NV_PMU_EXT_ATTR (_name, _func, _config) \ - (&((struct dev_ext_attribute[]){ \ - { \ - .attr = __ATTR(_name, 0444, _func, NULL), \ - .var = (void *)_config \ - } \ +#define NV_PMU_EXT_ATTR (_name, _func, _config) \ + (&((struct dev_ext_attribute[]){ \ + { \ + .attr = __DEVICE_ATTR(_name, 0444, _func, NULL), \ + .var = (void *)_config \ + } \ })[0].attr.attr)static struct attribute *cmem_lat_pmu_formats[] = {
drivers/perf/qcom_l3_pmu.c +4 -4
@@ -609,10 +609,10 @@ static void qcom_l3_cache__event_read(struct perf_event *event)/* formats */ -#define L3CACHE_PMU_FORMAT_ATTR (_name, _config) \ - (&((struct dev_ext_attribute[]) { \ - { .attr = __ATTR(_name, 0444, device_show_string, NULL), \ - .var = (void *) _config, } \ +#define L3CACHE_PMU_FORMAT_ATTR (_name, _config) \ + (&((struct dev_ext_attribute[]) { \ + { .attr = __DEVICE_ATTR(_name, 0444, device_show_string, NULL), \ + .var = (void *) _config, } \ })[0].attr.attr)static struct attribute *qcom_l3_cache_pmu_formats[] = {
drivers/perf/starfive_starlink_pmu.c +1 -1
@@ -51,7 +51,7 @@#define STARLINK_FORMAT_ATTR (_name, _config) \ (&((struct dev_ext_attribute[]) { \ - { .attr = __ATTR(_name, 0444, starlink_pmu_sysfs_format_show, NULL), \ + { .attr = __DEVICE_ATTR(_name, 0444, starlink_pmu_sysfs_format_show, NULL), \ .var = (void *)_config, } \ })[0].attr.attr)
drivers/perf/xgene_pmu.c +1 -1
@@ -164,7 +164,7 @@ enum xgene_pmu_dev_type {*/ #define XGENE_PMU_FORMAT_ATTR (_name, _config) \ (&((struct dev_ext_attribute[]) { \ - { .attr = __ATTR(_name, S_IRUGO, device_show_string, NULL), \ + { .attr = __DEVICE_ATTR(_name, S_IRUGO, device_show_string, NULL), \ .var = (void *) _config, } \ })[0].attr.attr)
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 2/3] drivers: perf: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
The upcoming constification of the device_show_*() callback signatures requires the users to handle the transition automatically.
Switch to the
__DEVICE_ATTR()macro which can do this.Signed-off-by Thomas Weißschuh <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260907-sysfs-const-attr-dev_ext_attr-v2-0-bf53afe57071@weissschuh.net?part=2
Re: [PATCH v2 2/3] drivers: perf: Use __DEVICE_ATTR() macro to initialize dev_ext_attribute
In reply to Thomas WeißschuhQuoted 6 lines · On Mon, 07 Sep 2026 07:45:02 +0200 Thomas Weißschuh <[email protected]>…
The upcoming constification of the device_show_*() callback signatures requires the users to handle the transition automatically.
Switch to the
__DEVICE_ATTR()macro which can do this.Signed-off-by Thomas Weißschuh <[email protected]>
PATCH v2 3/3 driver core: Constify the signature of device_show/store_*()
In reply to Thomas WeißschuhPrepare for the constification of 'struct dev_ext_attribute' by changing the signature of the standard callback functions.
Migrate the hv-24x7 driver in the same commit. It is the only user to manually assign one of the standard callbacks.
--- arch/powerpc/perf/hv-24x7.c | 2 +- drivers/base/core.c | 30 +++++++++++++++--------------- include/linux/device.h | 14 +++++++------- 3 files changed, 23 insertions(+), 23 deletions(-)
arch/powerpc/perf/hv-24x7.c +1 -1
@@ -462,7 +462,7 @@ static struct attribute *device_str_attr_create_(char *name, char *str) attr->var = str; attr->attr.attr.name = name; attr->attr.attr.mode =0444 ; - attr->attr.show = device_show_string; + attr->attr.show_const = device_show_string;return &attr->attr.attr; }
drivers/base/core.c +15 -15
@@ -2517,13 +2517,13 @@ static const struct sysfs_ops dev_sysfs_ops = { .store = dev_attr_store, }; -#define to_ext_attr (x) container_of(x, struct dev_ext_attribute, attr) +#define to_ext_attr (x) container_of_const(x, struct dev_ext_attribute, attr)ssize_t device_store_ulong (struct device *dev, -struct device_attribute *attr, +const struct device_attribute *attr,const char *buf,size_t size) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);int ret;unsigned long new;
@@ -2537,19 +2537,19 @@ ssize_t device_store_ulong(struct device *dev,EXPORT_SYMBOL_GPL (device_store_ulong);ssize_t device_show_ulong (struct device *dev, -struct device_attribute *attr, +const struct device_attribute *attr,char *buf) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);return sysfs_emit (buf,"%lx\n" , *(unsigned long *)(ea->var)); }EXPORT_SYMBOL_GPL (device_show_ulong);ssize_t device_store_int (struct device *dev, -struct device_attribute *attr, +const struct device_attribute *attr,const char *buf,size_t size) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);int ret;long new;
@@ -2566,19 +2566,19 @@ ssize_t device_store_int(struct device *dev,EXPORT_SYMBOL_GPL (device_store_int);ssize_t device_show_int (struct device *dev, -struct device_attribute *attr, +const struct device_attribute *attr,char *buf) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);return sysfs_emit (buf,"%d\n" , *(int *)(ea->var)); }EXPORT_SYMBOL_GPL (device_show_int); -ssize_t device_store_bool (struct device *dev,struct device_attribute *attr, +ssize_t device_store_bool (struct device *dev,const struct device_attribute *attr,const char *buf,size_t size) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);if (kstrtobool (buf, ea->var) <0 )return -EINVAL ;
@@ -2587,19 +2587,19 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, }EXPORT_SYMBOL_GPL (device_store_bool); -ssize_t device_show_bool (struct device *dev,struct device_attribute *attr, +ssize_t device_show_bool (struct device *dev,const struct device_attribute *attr,char *buf) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);return sysfs_emit (buf,"%d\n" , *(bool *)(ea->var)); }EXPORT_SYMBOL_GPL (device_show_bool);ssize_t device_show_string (struct device *dev, -struct device_attribute *attr,char *buf) +const struct device_attribute *attr,char *buf) { -struct dev_ext_attribute *ea =to_ext_attr (attr); +const struct dev_ext_attribute *ea =to_ext_attr (attr);return sysfs_emit (buf,"%s\n" , (char *)ea->var); }
include/linux/device.h +7 -7
@@ -129,19 +129,19 @@ struct dev_ext_attribute {void *var; }; -ssize_t device_show_ulong (struct device *dev,struct device_attribute *attr, +ssize_t device_show_ulong (struct device *dev,const struct device_attribute *attr,char *buf); -ssize_t device_store_ulong (struct device *dev,struct device_attribute *attr, +ssize_t device_store_ulong (struct device *dev,const struct device_attribute *attr,const char *buf,size_t count); -ssize_t device_show_int (struct device *dev,struct device_attribute *attr, +ssize_t device_show_int (struct device *dev,const struct device_attribute *attr,char *buf); -ssize_t device_store_int (struct device *dev,struct device_attribute *attr, +ssize_t device_store_int (struct device *dev,const struct device_attribute *attr,const char *buf,size_t count); -ssize_t device_show_bool (struct device *dev,struct device_attribute *attr, +ssize_t device_show_bool (struct device *dev,const struct device_attribute *attr,char *buf); -ssize_t device_store_bool (struct device *dev,struct device_attribute *attr, +ssize_t device_store_bool (struct device *dev,const struct device_attribute *attr,const char *buf,size_t count); -ssize_t device_show_string (struct device *dev,struct device_attribute *attr, +ssize_t device_show_string (struct device *dev,const struct device_attribute *attr,char *buf); typedef ssize_t __device_show_handler_const(struct device *dev, const struct device_attribute *attr,
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Prepare for the constification of 'struct
dev_ext_attribute' by changing the signature of the standard callback functions.Migrate the hv-24x7 driver in the same commit. It is the only user to manually assign one of the standard callbacks.
Signed-off-by Thomas Weißschuh <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260907-sysfs-const-attr-dev_ext_attr-v2-0-bf53afe57071@weissschuh.net?part=3