Skip to content

Commit

Permalink
ACPI / fan: avoid null pointer deference error
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Colin Ian King authored and Rafael J. Wysocki committed Mar 25, 2013
1 parent 994fa63 commit f0c2958
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/acpi/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f0c2958

Please sign in to comment.