]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.0/cpufreq-use-struct-kobj_attribute-instead-of-struct-global_attr.patch
5.0-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.0 / cpufreq-use-struct-kobj_attribute-instead-of-struct-global_attr.patch
1 From 625c85a62cb7d3c79f6e16de3cfa972033658250 Mon Sep 17 00:00:00 2001
2 From: Viresh Kumar <viresh.kumar@linaro.org>
3 Date: Fri, 25 Jan 2019 12:53:07 +0530
4 Subject: cpufreq: Use struct kobj_attribute instead of struct global_attr
5
6 From: Viresh Kumar <viresh.kumar@linaro.org>
7
8 commit 625c85a62cb7d3c79f6e16de3cfa972033658250 upstream.
9
10 The cpufreq_global_kobject is created using kobject_create_and_add()
11 helper, which assigns the kobj_type as dynamic_kobj_ktype and show/store
12 routines are set to kobj_attr_show() and kobj_attr_store().
13
14 These routines pass struct kobj_attribute as an argument to the
15 show/store callbacks. But all the cpufreq files created using the
16 cpufreq_global_kobject expect the argument to be of type struct
17 attribute. Things work fine currently as no one accesses the "attr"
18 argument. We may not see issues even if the argument is used, as struct
19 kobj_attribute has struct attribute as its first element and so they
20 will both get same address.
21
22 But this is logically incorrect and we should rather use struct
23 kobj_attribute instead of struct global_attr in the cpufreq core and
24 drivers and the show/store callbacks should take struct kobj_attribute
25 as argument instead.
26
27 This bug is caught using CFI CLANG builds in android kernel which
28 catches mismatch in function prototypes for such callbacks.
29
30 Reported-by: Donghee Han <dh.han@samsung.com>
31 Reported-by: Sangkyu Kim <skwith.kim@samsung.com>
32 Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
33 Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
34 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36 ---
37 drivers/cpufreq/cpufreq.c | 6 +++---
38 drivers/cpufreq/intel_pstate.c | 23 ++++++++++++-----------
39 include/linux/cpufreq.h | 12 ++----------
40 3 files changed, 17 insertions(+), 24 deletions(-)
41
42 --- a/drivers/cpufreq/cpufreq.c
43 +++ b/drivers/cpufreq/cpufreq.c
44 @@ -545,13 +545,13 @@ EXPORT_SYMBOL_GPL(cpufreq_policy_transit
45 * SYSFS INTERFACE *
46 *********************************************************************/
47 static ssize_t show_boost(struct kobject *kobj,
48 - struct attribute *attr, char *buf)
49 + struct kobj_attribute *attr, char *buf)
50 {
51 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
52 }
53
54 -static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
55 - const char *buf, size_t count)
56 +static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr,
57 + const char *buf, size_t count)
58 {
59 int ret, enable;
60
61 --- a/drivers/cpufreq/intel_pstate.c
62 +++ b/drivers/cpufreq/intel_pstate.c
63 @@ -895,7 +895,7 @@ static void intel_pstate_update_policies
64 /************************** sysfs begin ************************/
65 #define show_one(file_name, object) \
66 static ssize_t show_##file_name \
67 - (struct kobject *kobj, struct attribute *attr, char *buf) \
68 + (struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
69 { \
70 return sprintf(buf, "%u\n", global.object); \
71 }
72 @@ -904,7 +904,7 @@ static ssize_t intel_pstate_show_status(
73 static int intel_pstate_update_status(const char *buf, size_t size);
74
75 static ssize_t show_status(struct kobject *kobj,
76 - struct attribute *attr, char *buf)
77 + struct kobj_attribute *attr, char *buf)
78 {
79 ssize_t ret;
80
81 @@ -915,7 +915,7 @@ static ssize_t show_status(struct kobjec
82 return ret;
83 }
84
85 -static ssize_t store_status(struct kobject *a, struct attribute *b,
86 +static ssize_t store_status(struct kobject *a, struct kobj_attribute *b,
87 const char *buf, size_t count)
88 {
89 char *p = memchr(buf, '\n', count);
90 @@ -929,7 +929,7 @@ static ssize_t store_status(struct kobje
91 }
92
93 static ssize_t show_turbo_pct(struct kobject *kobj,
94 - struct attribute *attr, char *buf)
95 + struct kobj_attribute *attr, char *buf)
96 {
97 struct cpudata *cpu;
98 int total, no_turbo, turbo_pct;
99 @@ -955,7 +955,7 @@ static ssize_t show_turbo_pct(struct kob
100 }
101
102 static ssize_t show_num_pstates(struct kobject *kobj,
103 - struct attribute *attr, char *buf)
104 + struct kobj_attribute *attr, char *buf)
105 {
106 struct cpudata *cpu;
107 int total;
108 @@ -976,7 +976,7 @@ static ssize_t show_num_pstates(struct k
109 }
110
111 static ssize_t show_no_turbo(struct kobject *kobj,
112 - struct attribute *attr, char *buf)
113 + struct kobj_attribute *attr, char *buf)
114 {
115 ssize_t ret;
116
117 @@ -998,7 +998,7 @@ static ssize_t show_no_turbo(struct kobj
118 return ret;
119 }
120
121 -static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
122 +static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
123 const char *buf, size_t count)
124 {
125 unsigned int input;
126 @@ -1045,7 +1045,7 @@ static ssize_t store_no_turbo(struct kob
127 return count;
128 }
129
130 -static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
131 +static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
132 const char *buf, size_t count)
133 {
134 unsigned int input;
135 @@ -1075,7 +1075,7 @@ static ssize_t store_max_perf_pct(struct
136 return count;
137 }
138
139 -static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
140 +static ssize_t store_min_perf_pct(struct kobject *a, struct kobj_attribute *b,
141 const char *buf, size_t count)
142 {
143 unsigned int input;
144 @@ -1107,12 +1107,13 @@ static ssize_t store_min_perf_pct(struct
145 }
146
147 static ssize_t show_hwp_dynamic_boost(struct kobject *kobj,
148 - struct attribute *attr, char *buf)
149 + struct kobj_attribute *attr, char *buf)
150 {
151 return sprintf(buf, "%u\n", hwp_boost);
152 }
153
154 -static ssize_t store_hwp_dynamic_boost(struct kobject *a, struct attribute *b,
155 +static ssize_t store_hwp_dynamic_boost(struct kobject *a,
156 + struct kobj_attribute *b,
157 const char *buf, size_t count)
158 {
159 unsigned int input;
160 --- a/include/linux/cpufreq.h
161 +++ b/include/linux/cpufreq.h
162 @@ -254,20 +254,12 @@ __ATTR(_name, 0644, show_##_name, store_
163 static struct freq_attr _name = \
164 __ATTR(_name, 0200, NULL, store_##_name)
165
166 -struct global_attr {
167 - struct attribute attr;
168 - ssize_t (*show)(struct kobject *kobj,
169 - struct attribute *attr, char *buf);
170 - ssize_t (*store)(struct kobject *a, struct attribute *b,
171 - const char *c, size_t count);
172 -};
173 -
174 #define define_one_global_ro(_name) \
175 -static struct global_attr _name = \
176 +static struct kobj_attribute _name = \
177 __ATTR(_name, 0444, show_##_name, NULL)
178
179 #define define_one_global_rw(_name) \
180 -static struct global_attr _name = \
181 +static struct kobj_attribute _name = \
182 __ATTR(_name, 0644, show_##_name, store_##_name)
183
184