Skip to contentSkip to conversation

ACPI: avoid null pointer dereference error

PATCH In review Colin King 2 participants 4 messages Mar 25, 2013 – Mar 26, 2013

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

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
author
#1 lore raw

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
index f815da8..8d1c010 100644
@@ -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
author
#2 lore raw

PATCH 2/2 ACPI / processor_thermal: avoid null pointer deference error

In reply to Colin King

From: 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
index 641b545..e8e6527 100644
@@ -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
#3 lore raw
In reply to Colin King
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 error

 drivers/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.