All of lore.kernel.org
 help / color / mirror / Atom feed
From: Corentin Chary <corentincj@iksaif.net>
To: lenb@kernel.org
Cc: linux-acpi@vger.kernel.org, alan-jenkins@tuffmail.co.uk,
	Corentin Chary <corentincj@iksaif.net>
Subject: [PATCH 04/24] eeepc-laptop: fix ordering of init and exit functions
Date: Fri, 28 Aug 2009 14:56:35 +0200	[thread overview]
Message-ID: <1251464215-6540-5-git-send-email-corentincj@iksaif.net> (raw)
In-Reply-To: <1251464215-6540-4-git-send-email-corentincj@iksaif.net>

From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>

1. input and backlight devices were registered after acpi notifications
   are enabled.  This left a window where eeepc_hotk_notify() might
   find these devices in an inconsistent (half-initialized) state.

-> Move all device registration into eeepc_hotk_add(), which is called
   before enabling acpi notifications.

2. input and backlight devices were unregistered before acpi
   notifications are disabled.  This left a window where
   eeepc_hotk_notify() might find these devices in an inconsistent
   (half-destroyed) state.

-> Move all device unregistration into eeepc_hotk_remove(), which is
   called after disabling acpi notifications.

3. The acpi driver was not freed if an error occured further down in
   eeepc_laptop_init().

-> The rest of eeepc_laptop_init() has been moved to eeepc_hotk_add(),
   so this is no longer a problem.

4. The acpi driver was unregistered before the platform driver.  This
   left a window where a sysfs access could attempt to read the ehotk
   structure after it had been freed by eeepc_hotk_remove().

-> The acpi driver is now unregistered as the last step in
   eeepc_laptop_exit(), so this is no longer a problem.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 drivers/platform/x86/eeepc-laptop.c |  120 +++++++++++++++++------------------
 1 files changed, 59 insertions(+), 61 deletions(-)

diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 8dd86f7..cf47d1c 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -847,44 +847,6 @@ error_slot:
 	return ret;
 }
 
-static int eeepc_hotk_add(struct acpi_device *device)
-{
-	int result;
-
-	if (!device)
-		 return -EINVAL;
-	pr_notice(EEEPC_HOTK_NAME "\n");
-	ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
-	if (!ehotk)
-		return -ENOMEM;
-	ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
-	ehotk->handle = device->handle;
-	strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
-	strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
-	device->driver_data = ehotk;
-	ehotk->device = device;
-	result = eeepc_hotk_check();
-	if (result)
-		goto ehotk_fail;
-
-	return 0;
-
- ehotk_fail:
-	kfree(ehotk);
-	ehotk = NULL;
-
-	return result;
-}
-
-static int eeepc_hotk_remove(struct acpi_device *device, int type)
-{
-	if (!device || !acpi_driver_data(device))
-		 return -EINVAL;
-
-	kfree(ehotk);
-	return 0;
-}
-
 static int eeepc_hotk_resume(struct acpi_device *device)
 {
 	if (ehotk->wlan_rfkill) {
@@ -1066,19 +1028,6 @@ static void eeepc_hwmon_exit(void)
 	eeepc_hwmon_device = NULL;
 }
 
-static void __exit eeepc_laptop_exit(void)
-{
-	eeepc_backlight_exit();
-	eeepc_rfkill_exit();
-	eeepc_input_exit();
-	eeepc_hwmon_exit();
-	acpi_bus_unregister_driver(&eeepc_hotk_driver);
-	sysfs_remove_group(&platform_device->dev.kobj,
-			   &platform_attribute_group);
-	platform_device_unregister(platform_device);
-	platform_driver_unregister(&platform_driver);
-}
-
 static int eeepc_new_rfkill(struct rfkill **rfkill,
 			    const char *name, struct device *dev,
 			    enum rfkill_type type, int cm)
@@ -1193,21 +1142,27 @@ static int eeepc_hwmon_init(struct device *dev)
 	return result;
 }
 
-static int __init eeepc_laptop_init(void)
+static int eeepc_hotk_add(struct acpi_device *device)
 {
 	struct device *dev;
 	int result;
 
-	if (acpi_disabled)
-		return -ENODEV;
-	result = acpi_bus_register_driver(&eeepc_hotk_driver);
-	if (result < 0)
-		return result;
-	if (!ehotk) {
-		acpi_bus_unregister_driver(&eeepc_hotk_driver);
-		return -ENODEV;
-	}
+	if (!device)
+		 return -EINVAL;
+	pr_notice(EEEPC_HOTK_NAME "\n");
+	ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
+	if (!ehotk)
+		return -ENOMEM;
+	ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
+	ehotk->handle = device->handle;
+	strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
+	strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
+	device->driver_data = ehotk;
+	ehotk->device = device;
 
+	result = eeepc_hotk_check();
+	if (result)
+		goto fail_check;
 	eeepc_enable_camera();
 
 	/* Register platform stuff */
@@ -1246,6 +1201,7 @@ static int __init eeepc_laptop_init(void)
 		goto fail_rfkill;
 
 	return 0;
+
 fail_rfkill:
 	eeepc_hwmon_exit();
 fail_hwmon:
@@ -1261,8 +1217,50 @@ fail_platform_device1:
 	platform_driver_unregister(&platform_driver);
 fail_platform_driver:
 	eeepc_input_exit();
+fail_check:
+	kfree(ehotk);
+
 	return result;
 }
 
+static int eeepc_hotk_remove(struct acpi_device *device, int type)
+{
+	if (!device || !acpi_driver_data(device))
+		 return -EINVAL;
+
+	eeepc_backlight_exit();
+	eeepc_rfkill_exit();
+	eeepc_input_exit();
+	eeepc_hwmon_exit();
+	sysfs_remove_group(&platform_device->dev.kobj,
+			   &platform_attribute_group);
+	platform_device_unregister(platform_device);
+	platform_driver_unregister(&platform_driver);
+
+	kfree(ehotk);
+	return 0;
+}
+
+static int __init eeepc_laptop_init(void)
+{
+	int result;
+
+	if (acpi_disabled)
+		return -ENODEV;
+	result = acpi_bus_register_driver(&eeepc_hotk_driver);
+	if (result < 0)
+		return result;
+	if (!ehotk) {
+		acpi_bus_unregister_driver(&eeepc_hotk_driver);
+		return -ENODEV;
+	}
+	return 0;
+}
+
+static void __exit eeepc_laptop_exit(void)
+{
+	acpi_bus_unregister_driver(&eeepc_hotk_driver);
+}
+
 module_init(eeepc_laptop_init);
 module_exit(eeepc_laptop_exit);
-- 
1.6.4



  reply	other threads:[~2009-08-28 13:09 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28 12:56 [PATCH 00/24] acpi4asus updates Corentin Chary
2009-08-28 12:56 ` [PATCH 01/24] eeepc-laptop: don't touch the pci slot if it was claimed by a different driver Corentin Chary
2009-08-28 12:56   ` [PATCH 02/24] eeepc-laptop: use a mutex to serialize pci hotplug (resume vs. notify) Corentin Chary
2009-08-28 12:56     ` [PATCH 03/24] eeepc-laptop: fix pci hotplug race on load and unload Corentin Chary
2009-08-28 12:56       ` Corentin Chary [this message]
2009-08-28 12:56         ` [PATCH 05/24] eeepc-laptop: make input device a child of the platform device Corentin Chary
2009-08-28 12:56           ` [PATCH 06/24] eeepc-laptop: remove redundant rfkill_set_sw_state in resume handler Corentin Chary
2009-08-28 12:56             ` [PATCH 07/24] eeepc-laptop: check the 3G rfkill state on resume Corentin Chary
2009-08-28 12:56               ` [PATCH 08/24] eeepc-laptop: correct the description of the hibernation abort bug Corentin Chary
2009-08-28 12:56                 ` [PATCH 09/24] eeepc-laptop: switch to dev_pm_ops Corentin Chary
2009-08-28 12:56                   ` [PATCH 10/24] eeepc-laptop: add rfkill support for the Wimax in ASUS Eee PC 1000HG Corentin Chary
2009-08-28 12:56                     ` [PATCH 11/24] eeepc-laptop: document sysfs interface Corentin Chary
2009-08-28 12:56                       ` [PATCH 12/24] video/backlight: " Corentin Chary
2009-08-28 12:56                         ` [PATCH 13/24] video/lcd: " Corentin Chary
2009-08-28 12:56                           ` [PATCH 14/24] led: " Corentin Chary
2009-08-28 12:56                             ` [PATCH 15/24] asus-laptop: Show HRWS in infos and fix output format Corentin Chary
2009-08-28 12:56                               ` [PATCH 16/24] asus-laptop: Add *_led_get() functions Corentin Chary
2009-08-28 12:56                                 ` [PATCH 17/24] asus-laptop: Map X50R hotkeys Corentin Chary
2009-08-28 12:56                                   ` [PATCH 18/24] asus-laptop: set maximum led brightness Corentin Chary
2009-08-28 12:56                                     ` [PATCH 19/24] asus-laptop: Add support for Keyboard backlight Corentin Chary
2009-08-28 12:56                                       ` [PATCH 20/24] asus-laptop: handle keyboard backlight keys Corentin Chary
2009-08-28 12:56                                         ` [PATCH 21/24] asus-laptop: Add suport for another "Media" key Corentin Chary
2009-08-28 12:56                                           ` [PATCH 22/24] asus-laptop: Add "calculator" hotkey Corentin Chary
2009-08-28 12:56                                             ` [PATCH 23/24] asus-laptop: document the module Corentin Chary
2009-08-28 12:56                                               ` [PATCH 24/24] asus-laptop: document sysfs interface Corentin Chary
2009-09-01 14:42                             ` [PATCH 14/24] led: " Richard Purdie
2009-09-01 14:43                           ` [PATCH 13/24] video/lcd: " Richard Purdie
2009-08-28 15:02 ` [PATCH 00/24] acpi4asus updates Alan Jenkins
2009-08-29 18:14   ` Len Brown
2009-08-28 19:33 ` [PATCH 00/24] acpi4asus update Len Brown
2009-08-29  8:27   ` Corentin Chary
2009-08-29  8:28   ` [PATCH 1/3] asus-laptop: Fix coding style for comments Corentin Chary
2009-08-29  8:28     ` [PATCH 2/3] eeepc-laptop: fix rfkill memory leak on unload Corentin Chary
2009-08-29  8:28       ` [PATCH 3/3] eeepc-laptop: allow rfkill hotplug to work on the 900A model Corentin Chary
2009-08-29 18:17         ` Len Brown
2009-08-29 18:16       ` [PATCH 2/3] eeepc-laptop: fix rfkill memory leak on unload Len Brown
2009-08-29 18:16     ` [PATCH 1/3] asus-laptop: Fix coding style for comments Len Brown

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=1251464215-6540-5-git-send-email-corentincj@iksaif.net \
    --to=corentincj@iksaif.net \
    --cc=alan-jenkins@tuffmail.co.uk \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.