Skip to content

Commit c9be0a3

Browse files
Andi Kleengregkh
authored andcommitted
sysdev: Pass attribute in sysdev_class attributes show/store
Passing the attribute to the low level IO functions allows all kinds of cleanups, by sharing low level IO code without requiring an own function for every piece of data. Also drivers can extend the attributes with own data fields and use that in the low level function. Similar to sysdev_attributes and normal attributes. This is a tree-wide sweep, converting everything in one go. No functional changes in this patch other than passing the new argument everywhere. Tested on x86, the non x86 parts are uncompiled. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 3d03ba4 commit c9be0a3

10 files changed

Lines changed: 89 additions & 30 deletions

File tree

‎arch/mips/txx9/generic/7segled.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ static ssize_t raw_store(struct sys_device *dev,
5858
static SYSDEV_ATTR(ascii, 0200, NULL, ascii_store);
5959
static SYSDEV_ATTR(raw, 0200, NULL, raw_store);
6060

61-
static ssize_t map_seg7_show(struct sysdev_class *class, char *buf)
61+
static ssize_t map_seg7_show(struct sysdev_class *class,
62+
struct sysdev_class_attribute *attr,
63+
char *buf)
6264
{
6365
memcpy(buf, &txx9_seg7map, sizeof(txx9_seg7map));
6466
return sizeof(txx9_seg7map);
6567
}
6668

6769
static ssize_t map_seg7_store(struct sysdev_class *class,
70+
struct sysdev_class_attribute *attr,
6871
const char *buf, size_t size)
6972
{
7073
if (size != sizeof(txx9_seg7map))

‎arch/s390/kernel/smp.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,9 @@ int __ref smp_rescan_cpus(void)
10201020
return rc;
10211021
}
10221022

1023-
static ssize_t __ref rescan_store(struct sysdev_class *class, const char *buf,
1023+
static ssize_t __ref rescan_store(struct sysdev_class *class,
1024+
struct sysdev_class_attribute *attr,
1025+
const char *buf,
10241026
size_t count)
10251027
{
10261028
int rc;
@@ -1041,7 +1043,9 @@ static ssize_t dispatching_show(struct sysdev_class *class, char *buf)
10411043
return count;
10421044
}
10431045

1044-
static ssize_t dispatching_store(struct sysdev_class *dev, const char *buf,
1046+
static ssize_t dispatching_store(struct sysdev_class *dev,
1047+
struct sysdev_class_attribute *attr,
1048+
const char *buf,
10451049
size_t count)
10461050
{
10471051
int val, rc;

‎arch/s390/kernel/time.c‎

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,14 +1116,18 @@ static struct sys_device etr_port1_dev = {
11161116
/*
11171117
* ETR class attributes
11181118
*/
1119-
static ssize_t etr_stepping_port_show(struct sysdev_class *class, char *buf)
1119+
static ssize_t etr_stepping_port_show(struct sysdev_class *class,
1120+
struct sysdev_class_attribute *attr,
1121+
char *buf)
11201122
{
11211123
return sprintf(buf, "%i\n", etr_port0.esw.p);
11221124
}
11231125

11241126
static SYSDEV_CLASS_ATTR(stepping_port, 0400, etr_stepping_port_show, NULL);
11251127

1126-
static ssize_t etr_stepping_mode_show(struct sysdev_class *class, char *buf)
1128+
static ssize_t etr_stepping_mode_show(struct sysdev_class *class,
1129+
struct sysdev_class_attribute *attr,
1130+
char *buf)
11271131
{
11281132
char *mode_str;
11291133

@@ -1584,7 +1588,9 @@ static struct sysdev_class stp_sysclass = {
15841588
.name = "stp",
15851589
};
15861590

1587-
static ssize_t stp_ctn_id_show(struct sysdev_class *class, char *buf)
1591+
static ssize_t stp_ctn_id_show(struct sysdev_class *class,
1592+
struct sysdev_class_attribute *attr,
1593+
char *buf)
15881594
{
15891595
if (!stp_online)
15901596
return -ENODATA;
@@ -1594,7 +1600,9 @@ static ssize_t stp_ctn_id_show(struct sysdev_class *class, char *buf)
15941600

15951601
static SYSDEV_CLASS_ATTR(ctn_id, 0400, stp_ctn_id_show, NULL);
15961602

1597-
static ssize_t stp_ctn_type_show(struct sysdev_class *class, char *buf)
1603+
static ssize_t stp_ctn_type_show(struct sysdev_class *class,
1604+
struct sysdev_class_attribute *attr,
1605+
char *buf)
15981606
{
15991607
if (!stp_online)
16001608
return -ENODATA;
@@ -1603,7 +1611,9 @@ static ssize_t stp_ctn_type_show(struct sysdev_class *class, char *buf)
16031611

16041612
static SYSDEV_CLASS_ATTR(ctn_type, 0400, stp_ctn_type_show, NULL);
16051613

1606-
static ssize_t stp_dst_offset_show(struct sysdev_class *class, char *buf)
1614+
static ssize_t stp_dst_offset_show(struct sysdev_class *class,
1615+
struct sysdev_class_attribute *attr,
1616+
char *buf)
16071617
{
16081618
if (!stp_online || !(stp_info.vbits & 0x2000))
16091619
return -ENODATA;
@@ -1612,7 +1622,9 @@ static ssize_t stp_dst_offset_show(struct sysdev_class *class, char *buf)
16121622

16131623
static SYSDEV_CLASS_ATTR(dst_offset, 0400, stp_dst_offset_show, NULL);
16141624

1615-
static ssize_t stp_leap_seconds_show(struct sysdev_class *class, char *buf)
1625+
static ssize_t stp_leap_seconds_show(struct sysdev_class *class,
1626+
struct sysdev_class_attribute *attr,
1627+
char *buf)
16161628
{
16171629
if (!stp_online || !(stp_info.vbits & 0x8000))
16181630
return -ENODATA;
@@ -1621,7 +1633,9 @@ static ssize_t stp_leap_seconds_show(struct sysdev_class *class, char *buf)
16211633

16221634
static SYSDEV_CLASS_ATTR(leap_seconds, 0400, stp_leap_seconds_show, NULL);
16231635

1624-
static ssize_t stp_stratum_show(struct sysdev_class *class, char *buf)
1636+
static ssize_t stp_stratum_show(struct sysdev_class *class,
1637+
struct sysdev_class_attribute *attr,
1638+
char *buf)
16251639
{
16261640
if (!stp_online)
16271641
return -ENODATA;
@@ -1630,7 +1644,9 @@ static ssize_t stp_stratum_show(struct sysdev_class *class, char *buf)
16301644

16311645
static SYSDEV_CLASS_ATTR(stratum, 0400, stp_stratum_show, NULL);
16321646

1633-
static ssize_t stp_time_offset_show(struct sysdev_class *class, char *buf)
1647+
static ssize_t stp_time_offset_show(struct sysdev_class *class,
1648+
struct sysdev_class_attribute *attr,
1649+
char *buf)
16341650
{
16351651
if (!stp_online || !(stp_info.vbits & 0x0800))
16361652
return -ENODATA;
@@ -1639,7 +1655,9 @@ static ssize_t stp_time_offset_show(struct sysdev_class *class, char *buf)
16391655

16401656
static SYSDEV_CLASS_ATTR(time_offset, 0400, stp_time_offset_show, NULL);
16411657

1642-
static ssize_t stp_time_zone_offset_show(struct sysdev_class *class, char *buf)
1658+
static ssize_t stp_time_zone_offset_show(struct sysdev_class *class,
1659+
struct sysdev_class_attribute *attr,
1660+
char *buf)
16431661
{
16441662
if (!stp_online || !(stp_info.vbits & 0x4000))
16451663
return -ENODATA;
@@ -1649,7 +1667,9 @@ static ssize_t stp_time_zone_offset_show(struct sysdev_class *class, char *buf)
16491667
static SYSDEV_CLASS_ATTR(time_zone_offset, 0400,
16501668
stp_time_zone_offset_show, NULL);
16511669

1652-
static ssize_t stp_timing_mode_show(struct sysdev_class *class, char *buf)
1670+
static ssize_t stp_timing_mode_show(struct sysdev_class *class,
1671+
struct sysdev_class_attribute *attr,
1672+
char *buf)
16531673
{
16541674
if (!stp_online)
16551675
return -ENODATA;
@@ -1658,7 +1678,9 @@ static ssize_t stp_timing_mode_show(struct sysdev_class *class, char *buf)
16581678

16591679
static SYSDEV_CLASS_ATTR(timing_mode, 0400, stp_timing_mode_show, NULL);
16601680

1661-
static ssize_t stp_timing_state_show(struct sysdev_class *class, char *buf)
1681+
static ssize_t stp_timing_state_show(struct sysdev_class *class,
1682+
struct sysdev_class_attribute *attr,
1683+
char *buf)
16621684
{
16631685
if (!stp_online)
16641686
return -ENODATA;
@@ -1667,12 +1689,15 @@ static ssize_t stp_timing_state_show(struct sysdev_class *class, char *buf)
16671689

16681690
static SYSDEV_CLASS_ATTR(timing_state, 0400, stp_timing_state_show, NULL);
16691691

1670-
static ssize_t stp_online_show(struct sysdev_class *class, char *buf)
1692+
static ssize_t stp_online_show(struct sysdev_class *class,
1693+
struct sysdev_class_attribute *attr,
1694+
char *buf)
16711695
{
16721696
return sprintf(buf, "%i\n", stp_online);
16731697
}
16741698

16751699
static ssize_t stp_online_store(struct sysdev_class *class,
1700+
struct sysdev_class_attribute *attr,
16761701
const char *buf, size_t count)
16771702
{
16781703
unsigned int value;

‎drivers/base/cpu.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ static ssize_t print_cpus_map(char *buf, const struct cpumask *map)
151151
}
152152

153153
#define print_cpus_func(type) \
154-
static ssize_t print_cpus_##type(struct sysdev_class *class, char *buf) \
154+
static ssize_t print_cpus_##type(struct sysdev_class *class, \
155+
struct sysdev_class_attribute *attr, char *buf) \
155156
{ \
156157
return print_cpus_map(buf, cpu_##type##_mask); \
157158
} \
@@ -165,7 +166,8 @@ print_cpus_func(present);
165166
/*
166167
* Print values for NR_CPUS and offlined cpus
167168
*/
168-
static ssize_t print_cpus_kernel_max(struct sysdev_class *class, char *buf)
169+
static ssize_t print_cpus_kernel_max(struct sysdev_class *class,
170+
struct sysdev_class_attribute *attr, char *buf)
169171
{
170172
int n = snprintf(buf, PAGE_SIZE-2, "%d\n", NR_CPUS - 1);
171173
return n;
@@ -175,7 +177,8 @@ static SYSDEV_CLASS_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL);
175177
/* arch-optional setting to enable display of offline cpus >= nr_cpu_ids */
176178
unsigned int total_cpus;
177179

178-
static ssize_t print_cpus_offline(struct sysdev_class *class, char *buf)
180+
static ssize_t print_cpus_offline(struct sysdev_class *class,
181+
struct sysdev_class_attribute *attr, char *buf)
179182
{
180183
int n = 0, len = PAGE_SIZE-2;
181184
cpumask_var_t offline;

‎drivers/base/node.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,23 +544,29 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
544544
return n;
545545
}
546546

547-
static ssize_t print_nodes_possible(struct sysdev_class *class, char *buf)
547+
static ssize_t print_nodes_possible(struct sysdev_class *class,
548+
struct sysdev_class_attribute *attr, char *buf)
548549
{
549550
return print_nodes_state(N_POSSIBLE, buf);
550551
}
551552

552-
static ssize_t print_nodes_online(struct sysdev_class *class, char *buf)
553+
static ssize_t print_nodes_online(struct sysdev_class *class,
554+
struct sysdev_class_attribute *attr,
555+
char *buf)
553556
{
554557
return print_nodes_state(N_ONLINE, buf);
555558
}
556559

557560
static ssize_t print_nodes_has_normal_memory(struct sysdev_class *class,
558-
char *buf)
561+
struct sysdev_class_attribute *attr,
562+
char *buf)
559563
{
560564
return print_nodes_state(N_NORMAL_MEMORY, buf);
561565
}
562566

563-
static ssize_t print_nodes_has_cpu(struct sysdev_class *class, char *buf)
567+
static ssize_t print_nodes_has_cpu(struct sysdev_class *class,
568+
struct sysdev_class_attribute *attr,
569+
char *buf)
564570
{
565571
return print_nodes_state(N_CPU, buf);
566572
}
@@ -573,7 +579,8 @@ static SYSDEV_CLASS_ATTR(has_cpu, 0444, print_nodes_has_cpu, NULL);
573579

574580
#ifdef CONFIG_HIGHMEM
575581
static ssize_t print_nodes_has_high_memory(struct sysdev_class *class,
576-
char *buf)
582+
struct sysdev_class_attribute *attr,
583+
char *buf)
577584
{
578585
return print_nodes_state(N_HIGH_MEMORY, buf);
579586
}

‎drivers/base/sys.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr,
8989
struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr);
9090

9191
if (class_attr->show)
92-
return class_attr->show(class, buffer);
92+
return class_attr->show(class, class_attr, buffer);
9393
return -EIO;
9494
}
9595

@@ -100,7 +100,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
100100
struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr);
101101

102102
if (class_attr->store)
103-
return class_attr->store(class, buffer, count);
103+
return class_attr->store(class, class_attr, buffer, count);
104104
return -EIO;
105105
}
106106

‎drivers/cpuidle/sysfs.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static int __init cpuidle_sysfs_setup(char *unused)
2222
__setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup);
2323

2424
static ssize_t show_available_governors(struct sysdev_class *class,
25+
struct sysdev_class_attribute *attr,
2526
char *buf)
2627
{
2728
ssize_t i = 0;
@@ -41,6 +42,7 @@ static ssize_t show_available_governors(struct sysdev_class *class,
4142
}
4243

4344
static ssize_t show_current_driver(struct sysdev_class *class,
45+
struct sysdev_class_attribute *attr,
4446
char *buf)
4547
{
4648
ssize_t ret;
@@ -56,6 +58,7 @@ static ssize_t show_current_driver(struct sysdev_class *class,
5658
}
5759

5860
static ssize_t show_current_governor(struct sysdev_class *class,
61+
struct sysdev_class_attribute *attr,
5962
char *buf)
6063
{
6164
ssize_t ret;
@@ -71,6 +74,7 @@ static ssize_t show_current_governor(struct sysdev_class *class,
7174
}
7275

7376
static ssize_t store_current_governor(struct sysdev_class *class,
77+
struct sysdev_class_attribute *attr,
7478
const char *buf, size_t count)
7579
{
7680
char gov_name[CPUIDLE_NAME_LEN];

‎include/linux/sysdev.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ struct sysdev_class {
4141

4242
struct sysdev_class_attribute {
4343
struct attribute attr;
44-
ssize_t (*show)(struct sysdev_class *, char *);
45-
ssize_t (*store)(struct sysdev_class *, const char *, size_t);
44+
ssize_t (*show)(struct sysdev_class *, struct sysdev_class_attribute *,
45+
char *);
46+
ssize_t (*store)(struct sysdev_class *, struct sysdev_class_attribute *,
47+
const char *, size_t);
4648
};
4749

4850
#define _SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \

‎kernel/perf_event.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5481,13 +5481,16 @@ void __init perf_event_init(void)
54815481
register_cpu_notifier(&perf_cpu_nb);
54825482
}
54835483

5484-
static ssize_t perf_show_reserve_percpu(struct sysdev_class *class, char *buf)
5484+
static ssize_t perf_show_reserve_percpu(struct sysdev_class *class,
5485+
struct sysdev_class_attribute *attr,
5486+
char *buf)
54855487
{
54865488
return sprintf(buf, "%d\n", perf_reserved_percpu);
54875489
}
54885490

54895491
static ssize_t
54905492
perf_set_reserve_percpu(struct sysdev_class *class,
5493+
struct sysdev_class_attribute *attr,
54915494
const char *buf,
54925495
size_t count)
54935496
{
@@ -5516,13 +5519,17 @@ perf_set_reserve_percpu(struct sysdev_class *class,
55165519
return count;
55175520
}
55185521

5519-
static ssize_t perf_show_overcommit(struct sysdev_class *class, char *buf)
5522+
static ssize_t perf_show_overcommit(struct sysdev_class *class,
5523+
struct sysdev_class_attribute *attr,
5524+
char *buf)
55205525
{
55215526
return sprintf(buf, "%d\n", perf_overcommit);
55225527
}
55235528

55245529
static ssize_t
5525-
perf_set_overcommit(struct sysdev_class *class, const char *buf, size_t count)
5530+
perf_set_overcommit(struct sysdev_class *class,
5531+
struct sysdev_class_attribute *attr,
5532+
const char *buf, size_t count)
55265533
{
55275534
unsigned long val;
55285535
int err;

‎kernel/sched.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7406,11 +7406,13 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt)
74067406

74077407
#ifdef CONFIG_SCHED_MC
74087408
static ssize_t sched_mc_power_savings_show(struct sysdev_class *class,
7409+
struct sysdev_class_attribute *attr,
74097410
char *page)
74107411
{
74117412
return sprintf(page, "%u\n", sched_mc_power_savings);
74127413
}
74137414
static ssize_t sched_mc_power_savings_store(struct sysdev_class *class,
7415+
struct sysdev_class_attribute *attr,
74147416
const char *buf, size_t count)
74157417
{
74167418
return sched_power_savings_store(buf, count, 0);
@@ -7422,11 +7424,13 @@ static SYSDEV_CLASS_ATTR(sched_mc_power_savings, 0644,
74227424

74237425
#ifdef CONFIG_SCHED_SMT
74247426
static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev,
7427+
struct sysdev_class_attribute *attr,
74257428
char *page)
74267429
{
74277430
return sprintf(page, "%u\n", sched_smt_power_savings);
74287431
}
74297432
static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev,
7433+
struct sysdev_class_attribute *attr,
74307434
const char *buf, size_t count)
74317435
{
74327436
return sched_power_savings_store(buf, count, 1);

0 commit comments

Comments
 (0)