Commit 99aa3638 authored by Colin Ian King's avatar Colin Ian King Committed by Rafael J. Wysocki

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: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent f0c29583
...@@ -218,9 +218,13 @@ processor_get_max_state(struct thermal_cooling_device *cdev, ...@@ -218,9 +218,13 @@ processor_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state) unsigned long *state)
{ {
struct acpi_device *device = cdev->devdata; 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; return -EINVAL;
*state = acpi_processor_max_state(pr); *state = acpi_processor_max_state(pr);
...@@ -232,9 +236,13 @@ processor_get_cur_state(struct thermal_cooling_device *cdev, ...@@ -232,9 +236,13 @@ processor_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *cur_state) unsigned long *cur_state)
{ {
struct acpi_device *device = cdev->devdata; 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; return -EINVAL;
*cur_state = cpufreq_get_cur_state(pr->id); *cur_state = cpufreq_get_cur_state(pr->id);
...@@ -248,11 +256,15 @@ processor_set_cur_state(struct thermal_cooling_device *cdev, ...@@ -248,11 +256,15 @@ processor_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state) unsigned long state)
{ {
struct acpi_device *device = cdev->devdata; struct acpi_device *device = cdev->devdata;
struct acpi_processor *pr = acpi_driver_data(device); struct acpi_processor *pr;
int result = 0; int result = 0;
int max_pstate; int max_pstate;
if (!device || !pr) if (!device)
return -EINVAL;
pr = acpi_driver_data(device);
if (!pr)
return -EINVAL; return -EINVAL;
max_pstate = cpufreq_get_max_state(pr->id); max_pstate = cpufreq_get_max_state(pr->id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment