Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf: Use device_show_string() helper for sysfs attributes

Deduplicate sysfs ->show() callbacks which expose a string at a static
memory location. Use the newly introduced device_show_string() helper
in the driver core instead by declaring those sysfs attributes with
DEVICE_STRING_ATTR_RO().

No functional change intended.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://lore.kernel.org/r/3a297850312b4ecb62d6872121de04496900f502.1713608122.git.lukas@wunner.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Lukas Wunner and committed by
Greg Kroah-Hartman
b91b73a4 7b53e926

+15 -139
+3 -10
arch/x86/events/intel/core.c
··· 5645 5645 5646 5646 static char pmu_name_str[30]; 5647 5647 5648 - static ssize_t pmu_name_show(struct device *cdev, 5649 - struct device_attribute *attr, 5650 - char *buf) 5651 - { 5652 - return snprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str); 5653 - } 5654 - 5655 - static DEVICE_ATTR_RO(pmu_name); 5648 + static DEVICE_STRING_ATTR_RO(pmu_name, 0444, pmu_name_str); 5656 5649 5657 5650 static struct attribute *intel_pmu_caps_attrs[] = { 5658 - &dev_attr_pmu_name.attr, 5659 - NULL 5651 + &dev_attr_pmu_name.attr.attr, 5652 + NULL 5660 5653 }; 5661 5654 5662 5655 static DEVICE_ATTR(allow_tsx_force_abort, 0644,
+2 -10
drivers/perf/alibaba_uncore_drw_pmu.c
··· 236 236 .attrs = ali_drw_pmu_cpumask_attrs, 237 237 }; 238 238 239 - static ssize_t ali_drw_pmu_identifier_show(struct device *dev, 240 - struct device_attribute *attr, 241 - char *page) 242 - { 243 - return sysfs_emit(page, "%s\n", "ali_drw_pmu"); 244 - } 245 - 246 239 static umode_t ali_drw_pmu_identifier_attr_visible(struct kobject *kobj, 247 240 struct attribute *attr, int n) 248 241 { 249 242 return attr->mode; 250 243 } 251 244 252 - static struct device_attribute ali_drw_pmu_identifier_attr = 253 - __ATTR(identifier, 0444, ali_drw_pmu_identifier_show, NULL); 245 + static DEVICE_STRING_ATTR_RO(ali_drw_pmu_identifier, 0444, "ali_drw_pmu"); 254 246 255 247 static struct attribute *ali_drw_pmu_identifier_attrs[] = { 256 - &ali_drw_pmu_identifier_attr.attr, 248 + &dev_attr_ali_drw_pmu_identifier.attr.attr, 257 249 NULL 258 250 }; 259 251
+1 -11
drivers/perf/arm-cci.c
··· 127 127 128 128 static void pmu_write_counters(struct cci_pmu *cci_pmu, 129 129 unsigned long *mask); 130 - static ssize_t __maybe_unused cci_pmu_format_show(struct device *dev, 131 - struct device_attribute *attr, char *buf); 132 130 static ssize_t __maybe_unused cci_pmu_event_show(struct device *dev, 133 131 struct device_attribute *attr, char *buf); 134 132 ··· 136 138 })[0].attr.attr 137 139 138 140 #define CCI_FORMAT_EXT_ATTR_ENTRY(_name, _config) \ 139 - CCI_EXT_ATTR_ENTRY(_name, cci_pmu_format_show, (char *)_config) 141 + CCI_EXT_ATTR_ENTRY(_name, device_show_string, _config) 140 142 #define CCI_EVENT_EXT_ATTR_ENTRY(_name, _config) \ 141 143 CCI_EXT_ATTR_ENTRY(_name, cci_pmu_event_show, (unsigned long)_config) 142 144 ··· 684 686 /* Disable all the PMU counters. */ 685 687 val = readl_relaxed(cci_pmu->ctrl_base + CCI_PMCR) & ~CCI_PMCR_CEN; 686 688 writel(val, cci_pmu->ctrl_base + CCI_PMCR); 687 - } 688 - 689 - static ssize_t cci_pmu_format_show(struct device *dev, 690 - struct device_attribute *attr, char *buf) 691 - { 692 - struct dev_ext_attribute *eattr = container_of(attr, 693 - struct dev_ext_attribute, attr); 694 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 695 689 } 696 690 697 691 static ssize_t cci_pmu_event_show(struct device *dev,
+1 -10
drivers/perf/arm-ccn.c
··· 215 215 *config |= (node_xp << 0) | (type << 8) | (port << 24); 216 216 } 217 217 218 - static ssize_t arm_ccn_pmu_format_show(struct device *dev, 219 - struct device_attribute *attr, char *buf) 220 - { 221 - struct dev_ext_attribute *ea = container_of(attr, 222 - struct dev_ext_attribute, attr); 223 - 224 - return sysfs_emit(buf, "%s\n", (char *)ea->var); 225 - } 226 - 227 218 #define CCN_FORMAT_ATTR(_name, _config) \ 228 219 struct dev_ext_attribute arm_ccn_pmu_format_attr_##_name = \ 229 - { __ATTR(_name, S_IRUGO, arm_ccn_pmu_format_show, \ 220 + { __ATTR(_name, S_IRUGO, device_show_string, \ 230 221 NULL), _config } 231 222 232 223 static CCN_FORMAT_ATTR(node, "config:0-7");
-10
drivers/perf/arm_cspmu/arm_cspmu.c
··· 223 223 return attr->mode; 224 224 } 225 225 226 - ssize_t arm_cspmu_sysfs_format_show(struct device *dev, 227 - struct device_attribute *attr, 228 - char *buf) 229 - { 230 - struct dev_ext_attribute *eattr = 231 - container_of(attr, struct dev_ext_attribute, attr); 232 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 233 - } 234 - EXPORT_SYMBOL_GPL(arm_cspmu_sysfs_format_show); 235 - 236 226 static struct attribute *arm_cspmu_format_attrs[] = { 237 227 ARM_CSPMU_FORMAT_EVENT_ATTR, 238 228 ARM_CSPMU_FORMAT_FILTER_ATTR,
+1 -6
drivers/perf/arm_cspmu/arm_cspmu.h
··· 28 28 })[0].attr.attr) 29 29 30 30 #define ARM_CSPMU_FORMAT_ATTR(_name, _config) \ 31 - ARM_CSPMU_EXT_ATTR(_name, arm_cspmu_sysfs_format_show, (char *)_config) 31 + ARM_CSPMU_EXT_ATTR(_name, device_show_string, _config) 32 32 33 33 #define ARM_CSPMU_EVENT_ATTR(_name, _config) \ 34 34 PMU_EVENT_ATTR_ID(_name, arm_cspmu_sysfs_event_show, _config) ··· 166 166 ssize_t arm_cspmu_sysfs_event_show(struct device *dev, 167 167 struct device_attribute *attr, 168 168 char *buf); 169 - 170 - /* Default function to show format attribute in sysfs. */ 171 - ssize_t arm_cspmu_sysfs_format_show(struct device *dev, 172 - struct device_attribute *attr, 173 - char *buf); 174 169 175 170 /* Register vendor backend. */ 176 171 int arm_cspmu_impl_register(const struct arm_cspmu_impl_match *impl_match);
+1 -10
drivers/perf/arm_dsu_pmu.c
··· 85 85 DSU_EXT_ATTR(_name, dsu_pmu_sysfs_event_show, (unsigned long)_config) 86 86 87 87 #define DSU_FORMAT_ATTR(_name, _config) \ 88 - DSU_EXT_ATTR(_name, dsu_pmu_sysfs_format_show, (char *)_config) 88 + DSU_EXT_ATTR(_name, device_show_string, _config) 89 89 90 90 #define DSU_CPUMASK_ATTR(_name, _config) \ 91 91 DSU_EXT_ATTR(_name, dsu_pmu_cpumask_show, (unsigned long)_config) ··· 137 137 struct dev_ext_attribute *eattr = container_of(attr, 138 138 struct dev_ext_attribute, attr); 139 139 return sysfs_emit(buf, "event=0x%lx\n", (unsigned long)eattr->var); 140 - } 141 - 142 - static ssize_t dsu_pmu_sysfs_format_show(struct device *dev, 143 - struct device_attribute *attr, 144 - char *buf) 145 - { 146 - struct dev_ext_attribute *eattr = container_of(attr, 147 - struct dev_ext_attribute, attr); 148 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 149 140 } 150 141 151 142 static ssize_t dsu_pmu_cpumask_show(struct device *dev,
+1 -12
drivers/perf/cxl_pmu.c
··· 208 208 return 0; 209 209 } 210 210 211 - static ssize_t cxl_pmu_format_sysfs_show(struct device *dev, 212 - struct device_attribute *attr, char *buf) 213 - { 214 - struct dev_ext_attribute *eattr; 215 - 216 - eattr = container_of(attr, struct dev_ext_attribute, attr); 217 - 218 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 219 - } 220 - 221 211 #define CXL_PMU_FORMAT_ATTR(_name, _format)\ 222 212 (&((struct dev_ext_attribute[]) { \ 223 213 { \ 224 - .attr = __ATTR(_name, 0444, \ 225 - cxl_pmu_format_sysfs_show, NULL), \ 214 + .attr = __ATTR(_name, 0444, device_show_string, NULL), \ 226 215 .var = (void *)_format \ 227 216 } \ 228 217 })[0].attr.attr)
+1 -12
drivers/perf/hisilicon/hisi_pcie_pmu.c
··· 99 99 HISI_PCIE_PMU_FILTER_ATTR(port, config2, 15, 0); 100 100 HISI_PCIE_PMU_FILTER_ATTR(bdf, config2, 31, 16); 101 101 102 - static ssize_t hisi_pcie_format_sysfs_show(struct device *dev, struct device_attribute *attr, 103 - char *buf) 104 - { 105 - struct dev_ext_attribute *eattr; 106 - 107 - eattr = container_of(attr, struct dev_ext_attribute, attr); 108 - 109 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 110 - } 111 - 112 102 static ssize_t hisi_pcie_event_sysfs_show(struct device *dev, struct device_attribute *attr, 113 103 char *buf) 114 104 { ··· 110 120 111 121 #define HISI_PCIE_PMU_FORMAT_ATTR(_name, _format) \ 112 122 (&((struct dev_ext_attribute[]){ \ 113 - { .attr = __ATTR(_name, 0444, hisi_pcie_format_sysfs_show, \ 114 - NULL), \ 123 + { .attr = __ATTR(_name, 0444, device_show_string, NULL), \ 115 124 .var = (void *)_format } \ 116 125 })[0].attr.attr) 117 126
-14
drivers/perf/hisilicon/hisi_uncore_pmu.c
··· 23 23 #define HISI_MAX_PERIOD(nr) (GENMASK_ULL((nr) - 1, 0)) 24 24 25 25 /* 26 - * PMU format attributes 27 - */ 28 - ssize_t hisi_format_sysfs_show(struct device *dev, 29 - struct device_attribute *attr, char *buf) 30 - { 31 - struct dev_ext_attribute *eattr; 32 - 33 - eattr = container_of(attr, struct dev_ext_attribute, attr); 34 - 35 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 36 - } 37 - EXPORT_SYMBOL_GPL(hisi_format_sysfs_show); 38 - 39 - /* 40 26 * PMU event attributes 41 27 */ 42 28 ssize_t hisi_event_sysfs_show(struct device *dev,
+1 -3
drivers/perf/hisilicon/hisi_uncore_pmu.h
··· 33 33 })[0].attr.attr) 34 34 35 35 #define HISI_PMU_FORMAT_ATTR(_name, _config) \ 36 - HISI_PMU_ATTR(_name, hisi_format_sysfs_show, (void *)_config) 36 + HISI_PMU_ATTR(_name, device_show_string, _config) 37 37 #define HISI_PMU_EVENT_ATTR(_name, _config) \ 38 38 HISI_PMU_ATTR(_name, hisi_event_sysfs_show, (unsigned long)_config) 39 39 ··· 122 122 void hisi_uncore_pmu_disable(struct pmu *pmu); 123 123 ssize_t hisi_event_sysfs_show(struct device *dev, 124 124 struct device_attribute *attr, char *buf); 125 - ssize_t hisi_format_sysfs_show(struct device *dev, 126 - struct device_attribute *attr, char *buf); 127 125 ssize_t hisi_cpumask_sysfs_show(struct device *dev, 128 126 struct device_attribute *attr, char *buf); 129 127 int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node);
+1 -11
drivers/perf/hisilicon/hns3_pmu.c
··· 363 363 HNS3_PMU_EVT_PPS_##_name##_TIME, \ 364 364 HNS3_PMU_FILTER_INTR_##_name}) 365 365 366 - static ssize_t hns3_pmu_format_show(struct device *dev, 367 - struct device_attribute *attr, char *buf) 368 - { 369 - struct dev_ext_attribute *eattr; 370 - 371 - eattr = container_of(attr, struct dev_ext_attribute, attr); 372 - 373 - return sysfs_emit(buf, "%s\n", (char *)eattr->var); 374 - } 375 - 376 366 static ssize_t hns3_pmu_event_show(struct device *dev, 377 367 struct device_attribute *attr, char *buf) 378 368 { ··· 411 421 })[0].attr.attr) 412 422 413 423 #define HNS3_PMU_FORMAT_ATTR(_name, _format) \ 414 - HNS3_PMU_ATTR(_name, hns3_pmu_format_show, (void *)_format) 424 + HNS3_PMU_ATTR(_name, device_show_string, _format) 415 425 #define HNS3_PMU_EVENT_ATTR(_name, _event) \ 416 426 HNS3_PMU_ATTR(_name, hns3_pmu_event_show, (void *)_event) 417 427 #define HNS3_PMU_FLT_MODE_ATTR(_name, _event) \
+1 -10
drivers/perf/qcom_l3_pmu.c
··· 609 609 610 610 /* formats */ 611 611 612 - static ssize_t l3cache_pmu_format_show(struct device *dev, 613 - struct device_attribute *attr, char *buf) 614 - { 615 - struct dev_ext_attribute *eattr; 616 - 617 - eattr = container_of(attr, struct dev_ext_attribute, attr); 618 - return sysfs_emit(buf, "%s\n", (char *) eattr->var); 619 - } 620 - 621 612 #define L3CACHE_PMU_FORMAT_ATTR(_name, _config) \ 622 613 (&((struct dev_ext_attribute[]) { \ 623 - { .attr = __ATTR(_name, 0444, l3cache_pmu_format_show, NULL), \ 614 + { .attr = __ATTR(_name, 0444, device_show_string, NULL), \ 624 615 .var = (void *) _config, } \ 625 616 })[0].attr.attr) 626 617
+1 -10
drivers/perf/xgene_pmu.c
··· 162 162 /* 163 163 * sysfs format attributes 164 164 */ 165 - static ssize_t xgene_pmu_format_show(struct device *dev, 166 - struct device_attribute *attr, char *buf) 167 - { 168 - struct dev_ext_attribute *eattr; 169 - 170 - eattr = container_of(attr, struct dev_ext_attribute, attr); 171 - return sysfs_emit(buf, "%s\n", (char *) eattr->var); 172 - } 173 - 174 165 #define XGENE_PMU_FORMAT_ATTR(_name, _config) \ 175 166 (&((struct dev_ext_attribute[]) { \ 176 - { .attr = __ATTR(_name, S_IRUGO, xgene_pmu_format_show, NULL), \ 167 + { .attr = __ATTR(_name, S_IRUGO, device_show_string, NULL), \ 177 168 .var = (void *) _config, } \ 178 169 })[0].attr.attr) 179 170