diff options
author | Colin Ian King <colin.king@canonical.com> | 2013-03-25 06:50:06 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-03-25 18:01:01 -0400 |
commit | 99aa36386351488d12ad5d302e096a77f22705d9 (patch) | |
tree | 50b45b5ca7eed2c95502b5b86e7a488fbb65bf00 /drivers/acpi/processor_thermal.c | |
parent | f0c29583db51104a7bc223b1e9c88d818f24ba4d (diff) |
ACPI / processor_thermal: avoid null pointer deference error
Fix a null pointer deference by acpi_driver_data() if device is
null. We should only set pr and check this is OK after we are
sure device is not null.
Smatch analysis:
drivers/acpi/processor_thermal.c:223 processor_get_max_state() warn:
variable dereferenced before check 'device' (see line 221)
drivers/acpi/processor_thermal.c:237 processor_get_cur_state() warn:
variable dereferenced before check 'device' (see line 235)
drivers/acpi/processor_thermal.c:255 processor_set_cur_state() warn:
variable dereferenced before check 'device' (see line 251)
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/processor_thermal.c')
-rw-r--r-- | drivers/acpi/processor_thermal.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c index 641b5450a0db..e8e652710e65 100644 --- a/drivers/acpi/processor_thermal.c +++ b/drivers/acpi/processor_thermal.c | |||
@@ -218,9 +218,13 @@ processor_get_max_state(struct thermal_cooling_device *cdev, | |||
218 | unsigned long *state) | 218 | unsigned long *state) |
219 | { | 219 | { |
220 | struct acpi_device *device = cdev->devdata; | 220 | struct acpi_device *device = cdev->devdata; |
221 | struct acpi_processor *pr = acpi_driver_data(device); | 221 | struct acpi_processor *pr; |
222 | 222 | ||
223 | if (!device || !pr) | 223 | if (!device) |
224 | return -EINVAL; | ||
225 | |||
226 | pr = acpi_driver_data(device); | ||
227 | if (!pr) | ||
224 | return -EINVAL; | 228 | return -EINVAL; |
225 | 229 | ||
226 | *state = acpi_processor_max_state(pr); | 230 | *state = acpi_processor_max_state(pr); |
@@ -232,9 +236,13 @@ processor_get_cur_state(struct thermal_cooling_device *cdev, | |||
232 | unsigned long *cur_state) | 236 | unsigned long *cur_state) |
233 | { | 237 | { |
234 | struct acpi_device *device = cdev->devdata; | 238 | struct acpi_device *device = cdev->devdata; |
235 | struct acpi_processor *pr = acpi_driver_data(device); | 239 | struct acpi_processor *pr; |
236 | 240 | ||
237 | if (!device || !pr) | 241 | if (!device) |
242 | return -EINVAL; | ||
243 | |||
244 | pr = acpi_driver_data(device); | ||
245 | if (!pr) | ||
238 | return -EINVAL; | 246 | return -EINVAL; |
239 | 247 | ||
240 | *cur_state = cpufreq_get_cur_state(pr->id); | 248 | *cur_state = cpufreq_get_cur_state(pr->id); |
@@ -248,11 +256,15 @@ processor_set_cur_state(struct thermal_cooling_device *cdev, | |||
248 | unsigned long state) | 256 | unsigned long state) |
249 | { | 257 | { |
250 | struct acpi_device *device = cdev->devdata; | 258 | struct acpi_device *device = cdev->devdata; |
251 | struct acpi_processor *pr = acpi_driver_data(device); | 259 | struct acpi_processor *pr; |
252 | int result = 0; | 260 | int result = 0; |
253 | int max_pstate; | 261 | int max_pstate; |
254 | 262 | ||
255 | if (!device || !pr) | 263 | if (!device) |
264 | return -EINVAL; | ||
265 | |||
266 | pr = acpi_driver_data(device); | ||
267 | if (!pr) | ||
256 | return -EINVAL; | 268 | return -EINVAL; |
257 | 269 | ||
258 | max_pstate = cpufreq_get_max_state(pr->id); | 270 | max_pstate = cpufreq_get_max_state(pr->id); |