Skip to content

Commit c8d6672

Browse files
vireshkgregkh
authored andcommitted
cpufreq: Use struct kobj_attribute instead of struct global_attr
commit 625c85a upstream. The cpufreq_global_kobject is created using kobject_create_and_add() helper, which assigns the kobj_type as dynamic_kobj_ktype and show/store routines are set to kobj_attr_show() and kobj_attr_store(). These routines pass struct kobj_attribute as an argument to the show/store callbacks. But all the cpufreq files created using the cpufreq_global_kobject expect the argument to be of type struct attribute. Things work fine currently as no one accesses the "attr" argument. We may not see issues even if the argument is used, as struct kobj_attribute has struct attribute as its first element and so they will both get same address. But this is logically incorrect and we should rather use struct kobj_attribute instead of struct global_attr in the cpufreq core and drivers and the show/store callbacks should take struct kobj_attribute as argument instead. This bug is caught using CFI CLANG builds in android kernel which catches mismatch in function prototypes for such callbacks. Reported-by: Donghee Han <dh.han@samsung.com> Reported-by: Sangkyu Kim <skwith.kim@samsung.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 25d0544 commit c8d6672

4 files changed

Lines changed: 17 additions & 25 deletions

File tree

drivers/cpufreq/cpufreq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,13 @@ EXPORT_SYMBOL_GPL(cpufreq_freq_transition_end);
474474
* SYSFS INTERFACE *
475475
*********************************************************************/
476476
static ssize_t show_boost(struct kobject *kobj,
477-
struct attribute *attr, char *buf)
477+
struct kobj_attribute *attr, char *buf)
478478
{
479479
return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
480480
}
481481

482-
static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
483-
const char *buf, size_t count)
482+
static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr,
483+
const char *buf, size_t count)
484484
{
485485
int ret, enable;
486486

drivers/cpufreq/cpufreq_governor.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE};
4848

4949
/* Create attributes */
5050
#define gov_sys_attr_ro(_name) \
51-
static struct global_attr _name##_gov_sys = \
51+
static struct kobj_attribute _name##_gov_sys = \
5252
__ATTR(_name, 0444, show_##_name##_gov_sys, NULL)
5353

5454
#define gov_sys_attr_rw(_name) \
55-
static struct global_attr _name##_gov_sys = \
55+
static struct kobj_attribute _name##_gov_sys = \
5656
__ATTR(_name, 0644, show_##_name##_gov_sys, store_##_name##_gov_sys)
5757

5858
#define gov_pol_attr_ro(_name) \
@@ -74,7 +74,7 @@ __ATTR(_name, 0644, show_##_name##_gov_pol, store_##_name##_gov_pol)
7474
/* Create show/store routines */
7575
#define show_one(_gov, file_name) \
7676
static ssize_t show_##file_name##_gov_sys \
77-
(struct kobject *kobj, struct attribute *attr, char *buf) \
77+
(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
7878
{ \
7979
struct _gov##_dbs_tuners *tuners = _gov##_dbs_cdata.gdbs_data->tuners; \
8080
return sprintf(buf, "%u\n", tuners->file_name); \
@@ -90,7 +90,7 @@ static ssize_t show_##file_name##_gov_pol \
9090

9191
#define store_one(_gov, file_name) \
9292
static ssize_t store_##file_name##_gov_sys \
93-
(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \
93+
(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) \
9494
{ \
9595
struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \
9696
return store_##file_name(dbs_data, buf, count); \
@@ -254,7 +254,7 @@ static inline int delay_for_sampling_rate(unsigned int sampling_rate)
254254

255255
#define declare_show_sampling_rate_min(_gov) \
256256
static ssize_t show_sampling_rate_min_gov_sys \
257-
(struct kobject *kobj, struct attribute *attr, char *buf) \
257+
(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
258258
{ \
259259
struct dbs_data *dbs_data = _gov##_dbs_cdata.gdbs_data; \
260260
return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \

drivers/cpufreq/intel_pstate.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@ static void __init intel_pstate_debug_expose_params(void)
368368
/************************** sysfs begin ************************/
369369
#define show_one(file_name, object) \
370370
static ssize_t show_##file_name \
371-
(struct kobject *kobj, struct attribute *attr, char *buf) \
371+
(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
372372
{ \
373373
return sprintf(buf, "%u\n", limits->object); \
374374
}
375375

376376
static ssize_t show_turbo_pct(struct kobject *kobj,
377-
struct attribute *attr, char *buf)
377+
struct kobj_attribute *attr, char *buf)
378378
{
379379
struct cpudata *cpu;
380380
int total, no_turbo, turbo_pct;
@@ -390,7 +390,7 @@ static ssize_t show_turbo_pct(struct kobject *kobj,
390390
}
391391

392392
static ssize_t show_num_pstates(struct kobject *kobj,
393-
struct attribute *attr, char *buf)
393+
struct kobj_attribute *attr, char *buf)
394394
{
395395
struct cpudata *cpu;
396396
int total;
@@ -401,7 +401,7 @@ static ssize_t show_num_pstates(struct kobject *kobj,
401401
}
402402

403403
static ssize_t show_no_turbo(struct kobject *kobj,
404-
struct attribute *attr, char *buf)
404+
struct kobj_attribute *attr, char *buf)
405405
{
406406
ssize_t ret;
407407

@@ -414,7 +414,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
414414
return ret;
415415
}
416416

417-
static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
417+
static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
418418
const char *buf, size_t count)
419419
{
420420
unsigned int input;
@@ -438,7 +438,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
438438
return count;
439439
}
440440

441-
static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
441+
static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
442442
const char *buf, size_t count)
443443
{
444444
unsigned int input;
@@ -463,7 +463,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
463463
return count;
464464
}
465465

466-
static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
466+
static ssize_t store_min_perf_pct(struct kobject *a, struct kobj_attribute *b,
467467
const char *buf, size_t count)
468468
{
469469
unsigned int input;

include/linux/cpufreq.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,12 @@ __ATTR(_name, _perm, show_##_name, NULL)
203203
static struct freq_attr _name = \
204204
__ATTR(_name, 0644, show_##_name, store_##_name)
205205

206-
struct global_attr {
207-
struct attribute attr;
208-
ssize_t (*show)(struct kobject *kobj,
209-
struct attribute *attr, char *buf);
210-
ssize_t (*store)(struct kobject *a, struct attribute *b,
211-
const char *c, size_t count);
212-
};
213-
214206
#define define_one_global_ro(_name) \
215-
static struct global_attr _name = \
207+
static struct kobj_attribute _name = \
216208
__ATTR(_name, 0444, show_##_name, NULL)
217209

218210
#define define_one_global_rw(_name) \
219-
static struct global_attr _name = \
211+
static struct kobj_attribute _name = \
220212
__ATTR(_name, 0644, show_##_name, store_##_name)
221213

222214

0 commit comments

Comments
 (0)