2007-08-08 08:42:42

by Dave Young

[permalink] [raw]
Subject: [PATCH] thinkpad acpi module_exit fix

Hi,

[This fix is not very good for the global variable, any comments are
welcome.]

The thinkpad_acpi module_init fail out entrace is not very properly. if
failing before register driver or before create sysfs file, the
module_exit will try to remove nonexist sysfs files, the kernel will
oops.

Signed-off-by: Dave Young <[email protected]>

---
drivers/misc/thinkpad_acpi.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff -upr linux/drivers/misc/thinkpad_acpi.c linux.new/drivers/misc/thinkpad_acpi.c
--- linux/drivers/misc/thinkpad_acpi.c 2007-08-08 16:28:19.000000000 +0000
+++ linux.new/drivers/misc/thinkpad_acpi.c 2007-08-08 16:35:11.000000000 +0000
@@ -91,6 +91,8 @@ MODULE_LICENSE("GPL");

/* Please remove this in year 2009 */
MODULE_ALIAS("ibm_acpi");
+static int sysfs_ret = 1;
+static int driver_ret = 1;

/*
* DMI matching for module autoloading
@@ -4662,14 +4664,14 @@ static int __init thinkpad_acpi_module_i
}
proc_dir->owner = THIS_MODULE;

- ret = platform_driver_register(&tpacpi_pdriver);
- if (ret) {
+ driver_ret = platform_driver_register(&tpacpi_pdriver);
+ if (driver_ret) {
printk(IBM_ERR "unable to register platform driver\n");
thinkpad_acpi_module_exit();
return ret;
}
- ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
- if (ret) {
+ sysfs_ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
+ if (sysfs_ret) {
printk(IBM_ERR "unable to create sysfs driver attributes\n");
thinkpad_acpi_module_exit();
return ret;
@@ -4756,8 +4758,13 @@ static void thinkpad_acpi_module_exit(vo
if (tpacpi_pdev)
platform_device_unregister(tpacpi_pdev);

- tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
- platform_driver_unregister(&tpacpi_pdriver);
+ if(!sysfs_ret){
+ tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
+ }
+
+ if(!driver_ret){
+ platform_driver_unregister(&tpacpi_pdriver);
+ }

if (proc_dir)
remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);


2007-08-08 09:48:57

by Thomas Renninger

[permalink] [raw]
Subject: Re: [PATCH] thinkpad acpi module_exit fix

On Wed, 2007-08-08 at 16:43 +0000, Dave Young wrote:
> Hi,
>
> [This fix is not very good for the global variable, any comments are
> welcome.]
>
> The thinkpad_acpi module_init fail out entrace is not very properly. if
> failing before register driver or before create sysfs file, the
> module_exit will try to remove nonexist sysfs files, the kernel will
> oops.
This one is already fixed in Len's git tree in the test branch and will
get merged to Linus soon (commit id:
ac36393de6034be7266264a435360e7628849005).

The (similar) patch got posted on linux-acpi with subject:
[PATCH 05/12] ACPI: thinkpad-acpi: fix the module init failure path
(Fri, 3 Aug 2007 18:33:38)

Thomas

Subject: Re: [PATCH] thinkpad acpi module_exit fix

On Wed, 08 Aug 2007, Dave Young wrote:
> [This fix is not very good for the global variable, any comments are
> welcome.]
>
> The thinkpad_acpi module_init fail out entrace is not very properly. if
> failing before register driver or before create sysfs file, the
> module_exit will try to remove nonexist sysfs files, the kernel will
> oops.
>
> Signed-off-by: Dave Young <[email protected]>

NAK, this is already fixed in Len's tree.

--
"One disk to rule them all, One disk to find them. One disk to bring
them all and in the darkness grind them. In the Land of Redmond
where the shadows lie." -- The Silicon Valley Tarot
Henrique Holschuh