Skip to contentSkip to conversation

drivers: acpi: fan.c move a dereference below the NULL test

PATCH In review Darren Jenkins 4 participants 4 messages Feb 11, 2010 – Feb 22, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: acpi: fan.c move a dereference below the NULL test

In acpi_fan_remove() device is being dereferenced before the NULL test. This reorders the code to ensure it is checked for NULL first.

Coverity CID: 2758

---
 drivers/acpi/fan.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +7 -2
index acf2ab2..dc39640 100644
@@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device *device)
 
 static int acpi_fan_remove(struct acpi_device *device, int type)
 {
-	struct thermal_cooling_device *cdev = acpi_driver_data(device);
+	struct thermal_cooling_device *cdev;
+
+	if (!device)
+		return -EINVAL;
+
+	cdev = acpi_driver_data(device);
 
-	if (!device || !cdev)
+	if (!cdev)
 		return -EINVAL;
 
 	acpi_fan_remove_fs(device);
Signature · 1 line
1.6.3.3
reviewer
#1 lore raw

I think think this is a run-time check for a programming error, and the current fashion is to delete the check and take a fault if this happens so the caller can be fixed.

There are a couple of checks like this in fan.c -- perhaps Rui can clean them up when he comes back next week.

thanks,
Len Brown, Intel Open Source Technology Center

Quoted 43 lines · Darren Jenkins

In acpi_fan_remove() device is being dereferenced before the NULL test. This reorders the code to ensure it is checked for NULL first.

Coverity CID: 2758

---
 drivers/acpi/fan.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +7 -2
index acf2ab2..dc39640 100644
@@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device *device)
 
 static int acpi_fan_remove(struct acpi_device *device, int type)
 {
-	struct thermal_cooling_device *cdev = acpi_driver_data(device);
+	struct thermal_cooling_device *cdev;
+
+	if (!device)
+		return -EINVAL;
+
+	cdev = acpi_driver_data(device);
 
-	if (!device || !cdev)
+	if (!cdev)
 		return -EINVAL;
 
 	acpi_fan_remove_fs(device);
Signature · 10 lines
1.6.3.3




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#2 lore raw
Quoted 6 lines · On Friday 19 February 2010 06:27:46 Len Brown wrote:

I think think this is a run-time check for a programming error, and the current fashion is to delete the check and take a fault if this happens so the caller can be fixed.

There are a couple of checks like this in fan.c -- perhaps Rui can clean them up when he comes back next week.

Please let us clean this up first and remove:
static inline void *acpi_driver_data(struct acpi_device *d)

{
        return d->driver_data;
}

This has nothing to do with acpica code, it's in kernel code only. Is there a reason for above abstraction?
If not, it's error prone and really should get eliminated.

Thomas

Quoted 6 lines

thanks,
Len Brown, Intel Open Source Technology Center

Quoted 1 line · Darren Jenkins

In acpi_fan_remove() device is being dereferenced before the NULL

test.

Quoted 9 lines
Quoted 9 lines

This reorders the code to ensure it is checked for NULL first.

Coverity CID: 2758

---
 drivers/acpi/fan.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
Quoted 5 lines

drivers/acpi/fan.c static int acpi_fan_add(struct acpi_device

Quoted 5 lines
drivers/acpi/fan.c +0 -0
index acf2ab2..dc39640 100644
@@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device 

*device)

Quoted 22 lines
Quoted 22 lines
drivers/acpi/fan.c +7 -2
 static int acpi_fan_remove(struct acpi_device *device, int type)
 {
-	struct thermal_cooling_device *cdev = acpi_driver_data(device);
+	struct thermal_cooling_device *cdev;
+
+	if (!device)
+		return -EINVAL;
+
+	cdev = acpi_driver_data(device);
 
-	if (!device || !cdev)
+	if (!cdev)
 		return -EINVAL;
 
 	acpi_fan_remove_fs(device);
Signature · 1 line
1.6.3.3
Quoted 2 lines
Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-

kernel" in

Quoted 5 lines
Quoted 4 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw
In reply to Len Brown
Quoted 4 lines · Len Brown

I think think this is a run-time check for a programming error, and the current fashion is to delete the check and take a fault if this happens so the caller can be fixed.

I agree.

Quoted 3 lines

There are a couple of checks like this in fan.c -- perhaps Rui can clean them up when he comes back next week.

I'll send the cleanup patch later.

thanks,
rui

Quoted 48 lines

thanks,
Len Brown, Intel Open Source Technology Center

Quoted 43 lines · Darren Jenkins

In acpi_fan_remove() device is being dereferenced before the NULL test. This reorders the code to ensure it is checked for NULL first.

Coverity CID: 2758

---
 drivers/acpi/fan.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +7 -2
index acf2ab2..dc39640 100644
@@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device *device)
 
 static int acpi_fan_remove(struct acpi_device *device, int type)
 {
-	struct thermal_cooling_device *cdev = acpi_driver_data(device);
+	struct thermal_cooling_device *cdev;
+
+	if (!device)
+		return -EINVAL;
+
+	cdev = acpi_driver_data(device);
 
-	if (!device || !cdev)
+	if (!cdev)
 		return -EINVAL;
 
 	acpi_fan_remove_fs(device);
Signature · 10 lines
1.6.3.3




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/