* [patch] acpi: check for allocation errors in dock_link_device()
@ 2012-02-14 9:29 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2012-02-14 9:29 UTC (permalink / raw)
To: Shaohua Li, Matthew Garrett; +Cc: Len Brown, linux-acpi, kernel-janitors
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 <dan.carpenter@oracle.com>
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index b5e4142..38e8212 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -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);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-02-14 9:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-14 9:29 [patch] acpi: check for allocation errors in dock_link_device() Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox