aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2013-03-25 10:50:06 +0000
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-03-25 23:01:01 +0100
commit99aa36386351488d12ad5d302e096a77f22705d9 (patch)
tree50b45b5ca7eed2c95502b5b86e7a488fbb65bf00 /drivers/acpi
parentACPI / fan: avoid null pointer deference error (diff)
downloadlinux-dev-99aa36386351488d12ad5d302e096a77f22705d9.tar.xz
linux-dev-99aa36386351488d12ad5d302e096a77f22705d9.zip
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')
-rw-r--r--drivers/acpi/processor_thermal.c24
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,
unsigned long *state)
{
struct acpi_device *device = cdev->devdata;
- struct acpi_processor *pr = acpi_driver_data(device);
+ struct acpi_processor *pr;
- if (!device || !pr)
+ if (!device)
+ return -EINVAL;
+
+ pr = acpi_driver_data(device);
+ if (!pr)
return -EINVAL;
*state = acpi_processor_max_state(pr);
@@ -232,9 +236,13 @@ processor_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *cur_state)
{
struct acpi_device *device = cdev->devdata;
- struct acpi_processor *pr = acpi_driver_data(device);
+ struct acpi_processor *pr;
- if (!device || !pr)
+ if (!device)
+ return -EINVAL;
+
+ pr = acpi_driver_data(device);
+ if (!pr)
return -EINVAL;
*cur_state = cpufreq_get_cur_state(pr->id);
@@ -248,11 +256,15 @@ processor_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
{
struct acpi_device *device = cdev->devdata;
- struct acpi_processor *pr = acpi_driver_data(device);
+ struct acpi_processor *pr;
int result = 0;
int max_pstate;
- if (!device || !pr)
+ if (!device)
+ return -EINVAL;
+
+ pr = acpi_driver_data(device);
+ if (!pr)
return -EINVAL;
max_pstate = cpufreq_get_max_state(pr->id);