Skip to content

Commit

Permalink
ACPI / dock: Do not leak memory on falilures to add a dock station
Browse files Browse the repository at this point in the history
The function creating and registering dock station objects,
dock_add(), leaks memory if there's an error after it's walked
the ACPI namespace calling find_dock_devices(), because it doesn't
free the list of dependent devices it's just created in those cases.

Fix that issue by adding the missing code to free the list of
dependent devices on errors.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Rafael J. Wysocki committed Jul 14, 2013
1 parent f716fc2 commit a30c4c5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/acpi/dock.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ add_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
return 0;
}

static void remove_dock_dependent_devices(struct dock_station *ds)
{
struct dock_dependent_device *dd, *aux;

list_for_each_entry_safe(dd, aux, &ds->dependent_devices, list) {
list_del(&dd->list);
kfree(dd);
}
}

/**
* dock_init_hotplug - Initialize a hotplug device on a docking station.
* @dd: Dock-dependent device.
Expand Down Expand Up @@ -895,6 +905,7 @@ static int __init dock_add(acpi_handle handle)
return 0;

err_rmgroup:
remove_dock_dependent_devices(dock_station);
sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
err_unregister:
platform_device_unregister(dd);
Expand Down

0 comments on commit a30c4c5

Please sign in to comment.