acer-wmi: add error checks in module_init
PATCH 1/1 acer-wmi: add error checks in module_init
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 <[email protected]>
Cc Carlos Corbacho <[email protected]>
--- drivers/misc/acer-wmi.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-)
drivers/misc/acer-wmi.c +27 -21
@@ -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);
Quoted 1 line · On Sunday 21 September 2008 15:29:59 Akinobu Mita wrote:
This patch fixes these bugs by using
platform_device_register_simple()
[Adding Greg KH to CC]
Last I heard, platform_device_register_simple() was in the process of being deprecated and then slated for future removal. Has this changed?
-Carlos
Signature · 3 lines
E-Mail: [email protected] Web: strangeworlds.co.uk GPG Key ID: 0x23EE722D