All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Carlos Corbacho <carlos@strangeworlds.co.uk>
Subject: [PATCH] acer-wmi: add error checks in module_init
Date: Sun, 21 Sep 2008 23:29:59 +0900	[thread overview]
Message-ID: <20080921142958.GC8790@localhost.localdomain> (raw)

There are sevaral bugs in module_init and module_exit for acer-wmi.

- No error handlings for platform_device_alloc() and platform_device_add()

- acer_platform_device is not freeed in module_exit

This patch fixes these bugs by using platform_device_register_simple()
and platform_device_unregister() respectively.

This patch also makes create_sysfs() take a argument struct
platform_device pointer so that it looks symmetrical to remove_sysfs().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Carlos Corbacho <carlos@strangeworlds.co.uk>
---
 drivers/misc/acer-wmi.c |   48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

Index: 2.6-git/drivers/misc/acer-wmi.c
===================================================================
--- 2.6-git.orig/drivers/misc/acer-wmi.c
+++ 2.6-git/drivers/misc/acer-wmi.c
@@ -1129,40 +1129,36 @@ static int remove_sysfs(struct platform_
 	return 0;
 }
 
-static int create_sysfs(void)
+static int create_sysfs(struct platform_device *device)
 {
 	int retval = -ENOMEM;
 
 	if (has_cap(ACER_CAP_WIRELESS)) {
-		retval = device_create_file(&acer_platform_device->dev,
-			&dev_attr_wireless);
+		retval = device_create_file(&device->dev, &dev_attr_wireless);
 		if (retval)
 			goto error_sysfs;
 	}
 
 	if (has_cap(ACER_CAP_BLUETOOTH)) {
-		retval = device_create_file(&acer_platform_device->dev,
-			&dev_attr_bluetooth);
+		retval = device_create_file(&device->dev, &dev_attr_bluetooth);
 		if (retval)
 			goto error_sysfs;
 	}
 
 	if (has_cap(ACER_CAP_THREEG)) {
-		retval = device_create_file(&acer_platform_device->dev,
-			&dev_attr_threeg);
+		retval = device_create_file(&device->dev, &dev_attr_threeg);
 		if (retval)
 			goto error_sysfs;
 	}
 
-	retval = device_create_file(&acer_platform_device->dev,
-		&dev_attr_interface);
+	retval = device_create_file(&device->dev, &dev_attr_interface);
 	if (retval)
 		goto error_sysfs;
 
 	return 0;
 
 error_sysfs:
-		remove_sysfs(acer_platform_device);
+	remove_sysfs(device);
 	return retval;
 }
 
@@ -1242,22 +1238,27 @@ static int __init acer_wmi_init(void)
 
 	set_quirks();
 
-	if (platform_driver_register(&acer_platform_driver)) {
+	err = platform_driver_register(&acer_platform_driver);
+	if (err) {
 		printk(ACER_ERR "Unable to register platform driver.\n");
-		goto error_platform_register;
+		return err;
+	}
+	acer_platform_device = platform_device_register_simple("acer-wmi", -1,
+								NULL, 0);
+	if (IS_ERR(acer_platform_device)) {
+		err = PTR_ERR(acer_platform_device);
+		goto out1;
 	}
-	acer_platform_device = platform_device_alloc("acer-wmi", -1);
-	platform_device_add(acer_platform_device);
 
-	err = create_sysfs();
+	err = create_sysfs(acer_platform_device);
 	if (err)
-		return err;
+		goto out2;
 
 	if (wmi_has_guid(WMID_GUID2)) {
 		interface->debug.wmid_devices = get_wmid_devices();
 		err = create_debugfs();
 		if (err)
-			return err;
+			goto out3;
 	}
 
 	/* Override any initial settings with values from the commandline */
@@ -1265,19 +1266,24 @@ static int __init acer_wmi_init(void)
 
 	return 0;
 
-error_platform_register:
-	return -ENODEV;
+out3:
+	remove_sysfs(acer_platform_device);
+out2:
+	platform_device_unregister(acer_platform_device);
+out1:
+	platform_driver_unregister(&acer_platform_driver);
+
+	return err;
 }
 
 static void __exit acer_wmi_exit(void)
 {
 	remove_sysfs(acer_platform_device);
 	remove_debugfs();
-	platform_device_del(acer_platform_device);
+	platform_device_unregister(acer_platform_device);
 	platform_driver_unregister(&acer_platform_driver);
 
 	printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
-	return;
 }
 
 module_init(acer_wmi_init);

             reply	other threads:[~2008-09-21 14:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-21 14:29 Akinobu Mita [this message]
2008-09-21 17:52 ` [PATCH] acer-wmi: add error checks in module_init Carlos Corbacho
  -- strict thread matches above, loose matches on Subject: below --
2008-09-21 17:53 Carlos Corbacho
2008-09-22  2:25 ` Akinobu Mita
2008-09-22 12:35   ` Akinobu Mita
2008-09-22 15:59 ` Greg KH
2008-09-22 17:54   ` Carlos Corbacho
2008-09-22 18:47     ` Greg KH

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=20080921142958.GC8790@localhost.localdomain \
    --to=akinobu.mita@gmail.com \
    --cc=carlos@strangeworlds.co.uk \
    --cc=linux-kernel@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.