public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Len Brown <len.brown@intel.com>, Rui Zhang <rui.zhang@intel.com>
Cc: linux-acpi@vger.kernel.org
Subject: [patch 2/8] ACPI: video - add missing input_free_device()
Date: Mon, 05 Nov 2007 11:43:30 -0500	[thread overview]
Message-ID: <20071105165011.808572323@anvil.corenet.prv> (raw)
In-Reply-To: 20071105164328.982283020@anvil.corenet.prv

[-- Attachment #1: acpi-video-fix-error-registering.patch --]
[-- Type: text/plain, Size: 3671 bytes --]

ACPI: video - add missing input_free_device()

If input_register_device() fails input_free_device() must
be called to release memory allocated for the device.
Also consolidate error handling in acpi_bus_video_add()
and handle input_allocate_device() failures.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---
 drivers/acpi/video.c |   71 +++++++++++++++++++++++++--------------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

Index: work/drivers/acpi/video.c
===================================================================
--- work.orig/drivers/acpi/video.c
+++ work/drivers/acpi/video.c
@@ -1897,14 +1897,10 @@ static void acpi_video_device_notify(acp
 static int instance;
 static int acpi_video_bus_add(struct acpi_device *device)
 {
-	int result = 0;
-	acpi_status status = 0;
-	struct acpi_video_bus *video = NULL;
+	acpi_status status;
+	struct acpi_video_bus *video;
 	struct input_dev *input;
-
-
-	if (!device)
-		return -EINVAL;
+	int error;
 
 	video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
 	if (!video)
@@ -1923,13 +1919,13 @@ static int acpi_video_bus_add(struct acp
 	acpi_driver_data(device) = video;
 
 	acpi_video_bus_find_cap(video);
-	result = acpi_video_bus_check(video);
-	if (result)
-		goto end;
-
-	result = acpi_video_bus_add_fs(device);
-	if (result)
-		goto end;
+	error = acpi_video_bus_check(video);
+	if (error)
+		goto err_free_video;
+
+	error = acpi_video_bus_add_fs(device);
+	if (error)
+		goto err_free_video;
 
 	init_MUTEX(&video->sem);
 	INIT_LIST_HEAD(&video->video_device_list);
@@ -1943,16 +1939,15 @@ static int acpi_video_bus_add(struct acp
 	if (ACPI_FAILURE(status)) {
 		ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
 				  "Error installing notify handler\n"));
-		acpi_video_bus_stop_devices(video);
-		acpi_video_bus_put_devices(video);
-		kfree(video->attached_array);
-		acpi_video_bus_remove_fs(device);
-		result = -ENODEV;
-		goto end;
+		error = -ENODEV;
+		goto err_stop_video;
 	}
 
-
 	video->input = input = input_allocate_device();
+	if (!input) {
+		error = -ENOMEM;
+		goto err_uninstall_notify;
+	}
 
 	snprintf(video->phys, sizeof(video->phys),
 		"%s/video/input0", acpi_device_hid(video->device));
@@ -1972,18 +1967,10 @@ static int acpi_video_bus_add(struct acp
 	set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
 	set_bit(KEY_DISPLAY_OFF, input->keybit);
 	set_bit(KEY_UNKNOWN, input->keybit);
-	result = input_register_device(input);
-	if (result) {
-		acpi_remove_notify_handler(video->device->handle,
-						ACPI_DEVICE_NOTIFY,
-						acpi_video_bus_notify);
-		acpi_video_bus_stop_devices(video);
-		acpi_video_bus_put_devices(video);
-		kfree(video->attached_array);
-		acpi_video_bus_remove_fs(device);
-		goto end;
-        }
 
+	error = input_register_device(input);
+	if (error)
+		goto err_free_input_dev;
 
 	printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s  rom: %s  post: %s)\n",
 	       ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
@@ -1991,11 +1978,23 @@ static int acpi_video_bus_add(struct acp
 	       video->flags.rom ? "yes" : "no",
 	       video->flags.post ? "yes" : "no");
 
- end:
-	if (result)
-		kfree(video);
+	return 0;
+
+ err_free_input_dev:
+	input_free_device(input);
+ err_uninstall_notify:
+	acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
+				   acpi_video_bus_notify);
+ err_stop_video:
+	acpi_video_bus_stop_devices(video);
+	acpi_video_bus_put_devices(video);
+	kfree(video->attached_array);
+	acpi_video_bus_remove_fs(device);
+ err_free_video:
+	kfree(video);
+	acpi_driver_data(device) = NULL;
 
-	return result;
+	return error;
 }
 
 static int acpi_video_bus_remove(struct acpi_device *device, int type)

-- 
Dmitry


  parent reply	other threads:[~2007-11-05 16:52 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-05 16:43 [patch 0/8] ACPI Video various cleanups & fixes Dmitry Torokhov
2007-11-05 16:43 ` [patch 1/8] ACPI: video - fit input device into sysfs tree Dmitry Torokhov
2007-11-14  7:17   ` Zhang Rui
2007-11-14 16:49     ` Len Brown
2007-11-05 16:43 ` Dmitry Torokhov [this message]
2007-11-14  7:17   ` [patch 2/8] ACPI: video - add missing input_free_device() Zhang Rui
2007-11-14 17:00   ` Len Brown
2007-11-05 16:43 ` [patch 3/8] ACPI: video - remove unsafe uses of list_for_each_safe() Dmitry Torokhov
2007-11-14  7:17   ` Zhang Rui
2007-11-14 17:46   ` Len Brown
2007-11-05 16:43 ` [patch 4/8] ACPI: video - convert semaphore to a mutex Dmitry Torokhov
2007-11-14  7:17   ` Zhang Rui
2007-11-14 17:18     ` Len Brown
2007-11-05 16:43 ` [patch 5/8] ACPI: video - simplify handling of attached devices Dmitry Torokhov
2007-11-14  7:17   ` Zhang Rui
2007-11-14 17:34     ` Len Brown
2007-11-05 16:43 ` [patch 6/8] ACPI: video - properly handle errors when registering proc elements Dmitry Torokhov
2007-11-14  7:18   ` Zhang Rui
2007-11-14 13:36     ` Henrique de Moraes Holschuh
2007-11-14 15:06       ` Dmitry Torokhov
2007-11-14 17:22         ` Len Brown
2007-11-14 17:38     ` Len Brown
2007-11-05 16:43 ` [patch 7/8] ACPI: video - more cleanups Dmitry Torokhov
2007-11-14  7:18   ` Zhang Rui
2007-11-14 17:42     ` Len Brown
2007-11-14 17:47       ` Len Brown
2007-11-05 16:43 ` [patch 8/8] ACPI: video - fix permissions on some proc entries Dmitry Torokhov
2007-11-14  7:18   ` Zhang Rui
2007-11-14  7:17 ` [patch 0/8] ACPI Video various cleanups & fixes Zhang Rui
2007-11-14 15:04   ` Dmitry Torokhov

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=20071105165011.808572323@anvil.corenet.prv \
    --to=dmitry.torokhov@gmail.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=rui.zhang@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