Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b91b73a

Browse files
l1kgregkh
authored andcommitted
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>
1 parent 7b53e92 commit b91b73a

File tree

14 files changed

+15
-139
lines changed

14 files changed

+15
-139
lines changed

arch/x86/events/intel/core.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,18 +5645,11 @@ lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
56455645

56465646
static char pmu_name_str[30];
56475647

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);
56565649

56575650
static struct attribute *intel_pmu_caps_attrs[] = {
5658-
&dev_attr_pmu_name.attr,
5659-
NULL
5651+
&dev_attr_pmu_name.attr.attr,
5652+
NULL
56605653
};
56615654

56625655
static DEVICE_ATTR(allow_tsx_force_abort, 0644,

drivers/perf/alibaba_uncore_drw_pmu.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,16 @@ static const struct attribute_group ali_drw_pmu_cpumask_attr_group = {
236236
.attrs = ali_drw_pmu_cpumask_attrs,
237237
};
238238

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-
246239
static umode_t ali_drw_pmu_identifier_attr_visible(struct kobject *kobj,
247240
struct attribute *attr, int n)
248241
{
249242
return attr->mode;
250243
}
251244

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");
254246

255247
static struct attribute *ali_drw_pmu_identifier_attrs[] = {
256-
&ali_drw_pmu_identifier_attr.attr,
248+
&dev_attr_ali_drw_pmu_identifier.attr.attr,
257249
NULL
258250
};
259251

drivers/perf/arm-cci.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ enum cci_models {
127127

128128
static void pmu_write_counters(struct cci_pmu *cci_pmu,
129129
unsigned long *mask);
130-
static ssize_t __maybe_unused cci_pmu_format_show(struct device *dev,
131-
struct device_attribute *attr, char *buf);
132130
static ssize_t __maybe_unused cci_pmu_event_show(struct device *dev,
133131
struct device_attribute *attr, char *buf);
134132

@@ -138,7 +136,7 @@ static ssize_t __maybe_unused cci_pmu_event_show(struct device *dev,
138136
})[0].attr.attr
139137

140138
#define CCI_FORMAT_EXT_ATTR_ENTRY(_name, _config) \
141-
CCI_EXT_ATTR_ENTRY(_name, cci_pmu_format_show, (char *)_config)
139+
CCI_EXT_ATTR_ENTRY(_name, device_show_string, _config)
142140
#define CCI_EVENT_EXT_ATTR_ENTRY(_name, _config) \
143141
CCI_EXT_ATTR_ENTRY(_name, cci_pmu_event_show, (unsigned long)_config)
144142

@@ -688,14 +686,6 @@ static void __cci_pmu_disable(struct cci_pmu *cci_pmu)
688686
writel(val, cci_pmu->ctrl_base + CCI_PMCR);
689687
}
690688

691-
static ssize_t cci_pmu_format_show(struct device *dev,
692-
struct device_attribute *attr, char *buf)
693-
{
694-
struct dev_ext_attribute *eattr = container_of(attr,
695-
struct dev_ext_attribute, attr);
696-
return sysfs_emit(buf, "%s\n", (char *)eattr->var);
697-
}
698-
699689
static ssize_t cci_pmu_event_show(struct device *dev,
700690
struct device_attribute *attr, char *buf)
701691
{

drivers/perf/arm-ccn.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,9 @@ static void arm_ccn_pmu_config_set(u64 *config, u32 node_xp, u32 type, u32 port)
215215
*config |= (node_xp << 0) | (type << 8) | (port << 24);
216216
}
217217

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-
227218
#define CCN_FORMAT_ATTR(_name, _config) \
228219
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, \
230221
NULL), _config }
231222

232223
static CCN_FORMAT_ATTR(node, "config:0-7");

drivers/perf/arm_cspmu/arm_cspmu.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,6 @@ arm_cspmu_event_attr_is_visible(struct kobject *kobj,
223223
return attr->mode;
224224
}
225225

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-
236226
static struct attribute *arm_cspmu_format_attrs[] = {
237227
ARM_CSPMU_FORMAT_EVENT_ATTR,
238228
ARM_CSPMU_FORMAT_FILTER_ATTR,

drivers/perf/arm_cspmu/arm_cspmu.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
})[0].attr.attr)
2929

3030
#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)
3232

3333
#define ARM_CSPMU_EVENT_ATTR(_name, _config) \
3434
PMU_EVENT_ATTR_ID(_name, arm_cspmu_sysfs_event_show, _config)
@@ -167,11 +167,6 @@ ssize_t arm_cspmu_sysfs_event_show(struct device *dev,
167167
struct device_attribute *attr,
168168
char *buf);
169169

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-
175170
/* Register vendor backend. */
176171
int arm_cspmu_impl_register(const struct arm_cspmu_impl_match *impl_match);
177172

drivers/perf/arm_dsu_pmu.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
DSU_EXT_ATTR(_name, dsu_pmu_sysfs_event_show, (unsigned long)_config)
8686

8787
#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)
8989

9090
#define DSU_CPUMASK_ATTR(_name, _config) \
9191
DSU_EXT_ATTR(_name, dsu_pmu_cpumask_show, (unsigned long)_config)
@@ -139,15 +139,6 @@ static ssize_t dsu_pmu_sysfs_event_show(struct device *dev,
139139
return sysfs_emit(buf, "event=0x%lx\n", (unsigned long)eattr->var);
140140
}
141141

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-
}
150-
151142
static ssize_t dsu_pmu_cpumask_show(struct device *dev,
152143
struct device_attribute *attr,
153144
char *buf)

drivers/perf/cxl_pmu.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,10 @@ static int cxl_pmu_parse_caps(struct device *dev, struct cxl_pmu_info *info)
208208
return 0;
209209
}
210210

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-
221211
#define CXL_PMU_FORMAT_ATTR(_name, _format)\
222212
(&((struct dev_ext_attribute[]) { \
223213
{ \
224-
.attr = __ATTR(_name, 0444, \
225-
cxl_pmu_format_sysfs_show, NULL), \
214+
.attr = __ATTR(_name, 0444, device_show_string, NULL), \
226215
.var = (void *)_format \
227216
} \
228217
})[0].attr.attr)

drivers/perf/hisilicon/hisi_pcie_pmu.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,6 @@ HISI_PCIE_PMU_FILTER_ATTR(len_mode, config1, 11, 10);
9999
HISI_PCIE_PMU_FILTER_ATTR(port, config2, 15, 0);
100100
HISI_PCIE_PMU_FILTER_ATTR(bdf, config2, 31, 16);
101101

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-
112102
static ssize_t hisi_pcie_event_sysfs_show(struct device *dev, struct device_attribute *attr,
113103
char *buf)
114104
{
@@ -120,8 +110,7 @@ static ssize_t hisi_pcie_event_sysfs_show(struct device *dev, struct device_attr
120110

121111
#define HISI_PCIE_PMU_FORMAT_ATTR(_name, _format) \
122112
(&((struct dev_ext_attribute[]){ \
123-
{ .attr = __ATTR(_name, 0444, hisi_pcie_format_sysfs_show, \
124-
NULL), \
113+
{ .attr = __ATTR(_name, 0444, device_show_string, NULL), \
125114
.var = (void *)_format } \
126115
})[0].attr.attr)
127116

drivers/perf/hisilicon/hisi_uncore_pmu.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@
2222

2323
#define HISI_MAX_PERIOD(nr) (GENMASK_ULL((nr) - 1, 0))
2424

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-
3925
/*
4026
* PMU event attributes
4127
*/

0 commit comments

Comments
 (0)