acpi: check for allocation errors in dock_link_device()
Subsystems (2)
PATCH 1/1 acpi: check for allocation errors in dock_link_device()
This is error checking pedantry to keep the static checkers happy. In the original code the kmalloc() wasn't checked for allocation failures.
Signed-off-by Dan Carpenter <[email protected]>
drivers/acpi/dock.c +26 -15
@@ -281,21 +281,22 @@ EXPORT_SYMBOL_GPL(is_dock_device);*/ struct device **dock_link_device (acpi_handle handle) { -struct device *dev =acpi_get_physical_device (handle); +struct device *dev;struct dock_station *dock_station;int ret, dock =0 ;struct device **devices; - devices =kmalloc (dock_station_count *sizeof (struct device *), -GFP_KERNEL ); - + dev =acpi_get_physical_device (handle);if (!dev)return NULL ; +if (is_dock (handle)) + goto out_put; + + devices =kmalloc (dock_station_count *sizeof (struct device *), +GFP_KERNEL ); +if (!devices) + goto out_put; -if (is_dock (handle)) { -put_device (dev); -return NULL ; - }list_for_each_entry (dock_station, &dock_stations, sibling) {if (find_dock_dependent_device (dock_station, handle)) {
@@ -311,6 +312,10 @@ struct device **dock_link_device(acpi_handle handle) devices[dock] =NULL ;return devices; + +out_put: +put_device (dev); +return NULL ; }EXPORT_SYMBOL_GPL (dock_link_device);
@@ -320,20 +325,21 @@ EXPORT_SYMBOL_GPL(dock_link_device);*/ struct device **dock_unlink_device (acpi_handle handle) { -struct device *dev =acpi_get_physical_device (handle); +struct device *dev;struct dock_station *dock_station;int dock =0 ; - struct device **devices - kmalloc(dock_station_count * sizeof(struct device *), -GFP_KERNEL ); +struct device **devices; + dev =acpi_get_physical_device (handle);if (!dev)return NULL ; +if (is_dock (handle)) + goto out_put; -if (is_dock (handle)) { -put_device (dev); -return NULL ; - } + devices =kmalloc (dock_station_count *sizeof (struct device *), +GFP_KERNEL ); +if (!devices) + goto out_put;list_for_each_entry (dock_station, &dock_stations, sibling) {if (find_dock_dependent_device (dock_station, handle)) {
@@ -350,6 +356,10 @@ struct device **dock_unlink_device(acpi_handle handle)put_device (dev); devices[dock] =NULL ;return devices; + +out_put: +put_device (dev); +return NULL ; }EXPORT_SYMBOL_GPL (dock_unlink_device);