From 83b2fd58de23db385b509cd5b1edd0b960354f7e Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Fri, 27 Jul 2007 16:23:42 -0300 Subject: [PATCH] ACPI: thinkpad-acpi: fix the module init failure path Thomas Renninger reports that if one tries to load thinkpad-acpi in a non-thinkpad, one gets: Call Trace: [] kref_get+0x2f/0x36 [] kobject_get+0x12/0x17 [] get_driver+0x14/0x1a [] driver_remove_file+0x11/0x32 [] :thinkpad_acpi:thinkpad_acpi_module_exit+0xa8/0xfc [] :thinkpad_acpi:thinkpad_acpi_module_init+0x74a/0x776 [] __link_module+0x0/0x25 [] sys_init_module+0x162c/0x178f [] system_call+0x7e/0x83 So, track if the platform driver and its driver attributes were registered, and only deallocate them in that case. This patch is based on Thomas Renninger's patch for the issue. Signed-off-by: Henrique de Moraes Holschuh Cc: Thomas Renninger --- drivers/misc/thinkpad_acpi.c | 10 ++++++++-- drivers/misc/thinkpad_acpi.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index fffbe5fa37c..04754ef1746 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -4657,12 +4657,15 @@ static int __init thinkpad_acpi_module_init(void) thinkpad_acpi_module_exit(); return ret; } + tp_features.platform_drv_registered = 1; + ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); if (ret) { printk(IBM_ERR "unable to create sysfs driver attributes\n"); thinkpad_acpi_module_exit(); return ret; } + tp_features.platform_drv_attrs_registered = 1; /* Device initialization */ @@ -4745,8 +4748,11 @@ static void thinkpad_acpi_module_exit(void) if (tpacpi_pdev) platform_device_unregister(tpacpi_pdev); - tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); - platform_driver_unregister(&tpacpi_pdriver); + if (tp_features.platform_drv_attrs_registered) + tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); + + if (tp_features.platform_drv_registered) + platform_driver_unregister(&tpacpi_pdriver); if (proc_dir) remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index b7a4a888cc8..a0b950e332f 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -246,6 +246,8 @@ static struct { u16 wan:1; u16 fan_ctrl_status_undef:1; u16 input_device_registered:1; + u16 platform_drv_registered:1; + u16 platform_drv_attrs_registered:1; } tp_features; struct thinkpad_id_data { -- 2.11.4.GIT