Skip to content

Commit 1782dc8

Browse files
YueHaibingKAGA-KOKO
authored andcommitted
cpu/hotplug: Use DEVICE_ATTR_*() macro
Use DEVICE_ATTR_*() helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read. Signed-off-by: YueHaibing <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 11bc021 commit 1782dc8

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

kernel/cpu.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,18 +2249,17 @@ int cpuhp_smt_enable(void)
22492249
#endif
22502250

22512251
#if defined(CONFIG_SYSFS) && defined(CONFIG_HOTPLUG_CPU)
2252-
static ssize_t show_cpuhp_state(struct device *dev,
2253-
struct device_attribute *attr, char *buf)
2252+
static ssize_t state_show(struct device *dev,
2253+
struct device_attribute *attr, char *buf)
22542254
{
22552255
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
22562256

22572257
return sprintf(buf, "%d\n", st->state);
22582258
}
2259-
static DEVICE_ATTR(state, 0444, show_cpuhp_state, NULL);
2259+
static DEVICE_ATTR_RO(state);
22602260

2261-
static ssize_t write_cpuhp_target(struct device *dev,
2262-
struct device_attribute *attr,
2263-
const char *buf, size_t count)
2261+
static ssize_t target_store(struct device *dev, struct device_attribute *attr,
2262+
const char *buf, size_t count)
22642263
{
22652264
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
22662265
struct cpuhp_step *sp;
@@ -2298,19 +2297,17 @@ static ssize_t write_cpuhp_target(struct device *dev,
22982297
return ret ? ret : count;
22992298
}
23002299

2301-
static ssize_t show_cpuhp_target(struct device *dev,
2302-
struct device_attribute *attr, char *buf)
2300+
static ssize_t target_show(struct device *dev,
2301+
struct device_attribute *attr, char *buf)
23032302
{
23042303
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
23052304

23062305
return sprintf(buf, "%d\n", st->target);
23072306
}
2308-
static DEVICE_ATTR(target, 0644, show_cpuhp_target, write_cpuhp_target);
2309-
2307+
static DEVICE_ATTR_RW(target);
23102308

2311-
static ssize_t write_cpuhp_fail(struct device *dev,
2312-
struct device_attribute *attr,
2313-
const char *buf, size_t count)
2309+
static ssize_t fail_store(struct device *dev, struct device_attribute *attr,
2310+
const char *buf, size_t count)
23142311
{
23152312
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
23162313
struct cpuhp_step *sp;
@@ -2359,15 +2356,15 @@ static ssize_t write_cpuhp_fail(struct device *dev,
23592356
return count;
23602357
}
23612358

2362-
static ssize_t show_cpuhp_fail(struct device *dev,
2363-
struct device_attribute *attr, char *buf)
2359+
static ssize_t fail_show(struct device *dev,
2360+
struct device_attribute *attr, char *buf)
23642361
{
23652362
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
23662363

23672364
return sprintf(buf, "%d\n", st->fail);
23682365
}
23692366

2370-
static DEVICE_ATTR(fail, 0644, show_cpuhp_fail, write_cpuhp_fail);
2367+
static DEVICE_ATTR_RW(fail);
23712368

23722369
static struct attribute *cpuhp_cpu_attrs[] = {
23732370
&dev_attr_state.attr,
@@ -2382,7 +2379,7 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
23822379
NULL
23832380
};
23842381

2385-
static ssize_t show_cpuhp_states(struct device *dev,
2382+
static ssize_t states_show(struct device *dev,
23862383
struct device_attribute *attr, char *buf)
23872384
{
23882385
ssize_t cur, res = 0;
@@ -2401,7 +2398,7 @@ static ssize_t show_cpuhp_states(struct device *dev,
24012398
mutex_unlock(&cpuhp_state_mutex);
24022399
return res;
24032400
}
2404-
static DEVICE_ATTR(states, 0444, show_cpuhp_states, NULL);
2401+
static DEVICE_ATTR_RO(states);
24052402

24062403
static struct attribute *cpuhp_cpu_root_attrs[] = {
24072404
&dev_attr_states.attr,
@@ -2474,28 +2471,27 @@ static const char *smt_states[] = {
24742471
[CPU_SMT_NOT_IMPLEMENTED] = "notimplemented",
24752472
};
24762473

2477-
static ssize_t
2478-
show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
2474+
static ssize_t control_show(struct device *dev,
2475+
struct device_attribute *attr, char *buf)
24792476
{
24802477
const char *state = smt_states[cpu_smt_control];
24812478

24822479
return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
24832480
}
24842481

2485-
static ssize_t
2486-
store_smt_control(struct device *dev, struct device_attribute *attr,
2487-
const char *buf, size_t count)
2482+
static ssize_t control_store(struct device *dev, struct device_attribute *attr,
2483+
const char *buf, size_t count)
24882484
{
24892485
return __store_smt_control(dev, attr, buf, count);
24902486
}
2491-
static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control);
2487+
static DEVICE_ATTR_RW(control);
24922488

2493-
static ssize_t
2494-
show_smt_active(struct device *dev, struct device_attribute *attr, char *buf)
2489+
static ssize_t active_show(struct device *dev,
2490+
struct device_attribute *attr, char *buf)
24952491
{
24962492
return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
24972493
}
2498-
static DEVICE_ATTR(active, 0444, show_smt_active, NULL);
2494+
static DEVICE_ATTR_RO(active);
24992495

25002496
static struct attribute *cpuhp_smt_attrs[] = {
25012497
&dev_attr_control.attr,

0 commit comments

Comments
 (0)