From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Carlos Corbacho <carlos@strangeworlds.co.uk>
Subject: [PATCH] tc1100-wmi: add error checks in module_init
Date: Sun, 21 Sep 2008 23:35:00 +0900 [thread overview]
Message-ID: <20080921143459.GD8790@localhost.localdomain> (raw)
There are sevaral bugs in module_init and module_exit for tc1100-wmi.
- No error handlings for platform_device_alloc() and platform_device_add()
- tc1100_device is not freeed in module_exit
This patch fixes these bugs by using platform_device_register_simple()
and platform_device_unregister() respectively.
This change needs to change the probe function to pass platform_device
to add_fs() and makes add_fs() use it rather than the variable tc1100_device.
Because tc1100_device is not initialized yet when probe function
is called. (tc1100_device is initialized as the return value from
platform_device_register_simple() but probe function is called in
platform_device_register_simple())
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Carlos Corbacho <carlos@strangeworlds.co.uk>
---
drivers/misc/tc1100-wmi.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
Index: 2.6-git/drivers/misc/tc1100-wmi.c
===================================================================
--- 2.6-git.orig/drivers/misc/tc1100-wmi.c
+++ 2.6-git/drivers/misc/tc1100-wmi.c
@@ -185,28 +185,28 @@ static DEVICE_ATTR(value, S_IWUGO | S_IR
show_set_bool(wireless, TC1100_INSTANCE_WIRELESS);
show_set_bool(jogdial, TC1100_INSTANCE_JOGDIAL);
-static void remove_fs(void)
+static void remove_fs(struct platform_device *pdev)
{
- device_remove_file(&tc1100_device->dev, &dev_attr_wireless);
- device_remove_file(&tc1100_device->dev, &dev_attr_jogdial);
+ device_remove_file(&pdev->dev, &dev_attr_wireless);
+ device_remove_file(&pdev->dev, &dev_attr_jogdial);
}
-static int add_fs(void)
+static int add_fs(struct platform_device *pdev)
{
int ret;
- ret = device_create_file(&tc1100_device->dev, &dev_attr_wireless);
+ ret = device_create_file(&pdev->dev, &dev_attr_wireless);
if (ret)
goto add_sysfs_error;
- ret = device_create_file(&tc1100_device->dev, &dev_attr_jogdial);
+ ret = device_create_file(&pdev->dev, &dev_attr_jogdial);
if (ret)
goto add_sysfs_error;
return ret;
add_sysfs_error:
- remove_fs();
+ remove_fs(pdev);
return ret;
}
@@ -216,16 +216,12 @@ add_sysfs_error:
static int tc1100_probe(struct platform_device *device)
{
- int result = 0;
-
- result = add_fs();
- return result;
+ return add_fs(device);
}
-
static int tc1100_remove(struct platform_device *device)
{
- remove_fs();
+ remove_fs(device);
return 0;
}
@@ -261,7 +257,7 @@ static int tc1100_resume(struct platform
static int __init tc1100_init(void)
{
- int result = 0;
+ int result;
if (!wmi_has_guid(GUID))
return -ENODEV;
@@ -270,17 +266,21 @@ static int __init tc1100_init(void)
if (result)
return result;
- tc1100_device = platform_device_alloc("tc1100-wmi", -1);
- platform_device_add(tc1100_device);
+ tc1100_device = platform_device_register_simple("tc1100-wmi", -1,
+ NULL, 0);
+ if (IS_ERR(tc1100_device)) {
+ platform_driver_unregister(&tc1100_driver);
+ return PTR_ERR(tc1100_device);
+ }
printk(TC1100_INFO "HP Compaq TC1100 Tablet WMI Extras loaded\n");
- return result;
+ return 0;
}
static void __exit tc1100_exit(void)
{
- platform_device_del(tc1100_device);
+ platform_device_unregister(tc1100_device);
platform_driver_unregister(&tc1100_driver);
printk(TC1100_INFO "HP Compaq TC1100 Tablet WMI Extras unloaded\n");
reply other threads:[~2008-09-21 14:35 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=20080921143459.GD8790@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.