public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Shaohua Li <shaohua.li@intel.com>, Matthew Garrett <mjg@redhat.com>
Cc: Len Brown <lenb@kernel.org>,
	linux-acpi@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] acpi: check for allocation errors in dock_link_device()
Date: Tue, 14 Feb 2012 12:29:31 +0300	[thread overview]
Message-ID: <20120214092931.GA18662@elgon.mountain> (raw)

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);
 

                 reply	other threads:[~2012-02-14  9:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120214092931.GA18662@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=mjg@redhat.com \
    --cc=shaohua.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox