ACPI / fan: avoid null pointer deference error
authorColin Ian King <colin.king@canonical.com>
Mon, 25 Mar 2013 10:50:05 +0000 (10:50 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 25 Mar 2013 22:01:00 +0000 (23:01 +0100)
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)

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/fan.c

index f815da82c765299a42300ae837fd574bedb8e429..8d1c0105e1138141aa2b6c988657d261617546ee 100644 (file)
@@ -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");