lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20080921143459.GD8790@localhost.localdomain>
Date:	Sun, 21 Sep 2008 23:35:00 +0900
From:	Akinobu Mita <akinobu.mita@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	Carlos Corbacho <carlos@...angeworlds.co.uk>
Subject: [PATCH] tc1100-wmi: add error checks in module_init

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@...il.com>
Cc: Carlos Corbacho <carlos@...angeworlds.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");
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ