ACPI: avoid null pointer dereference error
Subsystems (2)
cover ACPI: avoid null pointer dereference error
From: Colin Ian King <[email protected]>
Fix a null pointer deference by acpi_driver_data() if device is null.
Colin Ian King (2):
ACPI / fan: avoid null pointer deference error ACPI / processor_thermal: avoid null pointer deference error
drivers/acpi/fan.c | 8 ++++++-- drivers/acpi/processor_thermal.c | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 ACPI / fan: avoid null pointer deference error
From: Colin Ian King <[email protected]>
Fix a null pointer deference by acpi_driver_data() if device is null. We should only set cdev and check this is OK after we are sure device is not null.
Smatch analysis:
drivers/acpi/fan.c:179 acpi_fan_remove() warn: variable dereferenced
before check 'device' (see line 177)
--- drivers/acpi/fan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +6 -2
@@ -174,9 +174,13 @@ static int acpi_fan_add(struct acpi_device *device)static int acpi_fan_remove (struct acpi_device *device) { -struct thermal_cooling_device *cdev =acpi_driver_data (device); +struct thermal_cooling_device *cdev; + +if (!device) +return -EINVAL ; -if (!device || !cdev) + cdev =acpi_driver_data (device); +if (!cdev)return -EINVAL ;sysfs_remove_link (&device->dev.kobj,"thermal_cooling" );
Signature · 1 line
1.7.9.5
PATCH 2/2 ACPI / processor_thermal: avoid null pointer deference error
In reply to Colin KingFrom: Colin Ian King <[email protected]>
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)
--- drivers/acpi/processor_thermal.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/acpi/processor_thermal.c +18 -6
@@ -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);
Signature · 1 line
1.7.9.5
Quoted 5 lines · Colin King
From: Colin Ian King <[email protected]>
Fix a null pointer deference by
acpi_driver_data()if device is null.
Quoted 7 lines
Colin Ian King (2):
ACPI / fan: avoid null pointer deference error ACPI /processor_thermal: avoid null pointer deference errordrivers/acpi/fan.c | 8 ++++++-- drivers/acpi/processor_thermal.c | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-)
Both patches applied to linux-pm.git/linux-next.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.