ACPI: update acpi_bus_register_driver() signature
Subsystems (3)
cover ACPI: update acpi_bus_register_driver() signature
Registering a driver makes the driver available for devices, even devices that may be hot-added later. So the registration itself should return only success or failure, not the number of devices found.
pci_register_driver(), platform_driver_register(), and driver_register() already work this way. This series makes acpi_bus_register_driver() also work that way.
PATCH 1/4 ACPI: update asus_acpi driver registration
Remove the assumption that acpi_bus_register_driver() returns the number of devices claimed. Returning the count is unreliable because devices may be hot-plugged in the future (admittedly not applicable for this driver).
Since the hardware for this driver is not hot-pluggable, determine whether the hardware is present by noticing calls to the .add() method. It would be better to probe the ACPI namespace for the ASUS HIDs, and load the driver only when we find one, but ACPI doesn't support that yet.
I don't have an ASUS laptop to test on, but on my HP dl360, it does report the appropriate error when attempting to load the module:
$ sudo insmod drivers/acpi/asus_acpi.ko
insmod: error inserting 'drivers/acpi/asus_acpi.ko': -1 No such devicedrivers/acpi/asus_acpi.c +17 -1
@@ -1119,6 +1119,8 @@return result; } +static int asus_hotk_found; +static int __init asus_hotk_add (struct acpi_device *device) {acpi_status status =AE_OK ;
@@ -1180,6 +1182,8 @@ } } + asus_hotk_found =1 ; + end:if (result) {kfree (hotk);
@@ -1226,7 +1230,19 @@ asus_proc_dir->owner =THIS_MODULE ; result =acpi_bus_register_driver (&asus_hotk_driver); -if (result <1 ) { +if (result <0 ) { +remove_proc_entry (PROC_ASUS , acpi_root_dir); +return -ENODEV ; + } + +/* +* This is a bit of a kludge. We only want this module loaded +* for ASUS systems, but there's currently no way to probe the +* ACPI namespace for ASUS HIDs. So we just return failure if +* we didn't find one, which will cause the module to be +* unloaded. +*/ +if (!asus_hotk_found) {acpi_bus_unregister_driver (&asus_hotk_driver);remove_proc_entry (PROC_ASUS , acpi_root_dir);return -ENODEV ;
PATCH 2/4 ACPI: fix sonypi ACPI driver registration
In reply to Bjorn HelgaasRemove the assumption that acpi_bus_register_driver() returns the number of devices claimed. Returning the count is unreliable because devices may be hot-plugged in the future (admittedly not applicable for this driver).
This also fixes a bug: if sonypi_acpi_driver was registered but found no devices, sonypi_exit() did not unregister it.
drivers/char/sonypi.c +5 -5
@@ -512,7 +512,7 @@#ifdef CONFIG_ACPI static struct acpi_device *sonypi_acpi_device; -static int acpi_enabled; +static int acpi_driver_registered;#endif static int sonypi_ec_write (u8 addr,u8 value)
@@ -869,7 +869,7 @@sonypi_report_input_event (event);#ifdef CONFIG_ACPI -if (acpi_enabled) +if (sonypi_acpi_device)acpi_bus_generate_event (sonypi_acpi_device,1 , event);#endif
@@ -1548,8 +1548,8 @@ goto err_free_device;#ifdef CONFIG_ACPI -if (acpi_bus_register_driver (&sonypi_acpi_driver) >0 ) - acpi_enabled =1 ; +if (acpi_bus_register_driver (&sonypi_acpi_driver) >=0 ) + acpi_driver_registered =1 ;#endif return 0 ;
@@ -1564,7 +1564,7 @@ static void __exit sonypi_exit(void) {#ifdef CONFIG_ACPI -if (acpi_enabled) +if (acpi_driver_registered)acpi_bus_unregister_driver (&sonypi_acpi_driver);#endif platform_device_unregister (sonypi_platform_device);
PATCH 3/4 ACPI: make acpi_bus_register_driver() return success/failure, not device count
In reply to Bjorn Helgaasacpi_bus_register_driver() should not return the number of devices claimed. We're not asking to find devices, we're making a driver available to devices, including hot-pluggable devices that may appear in the future.
I audited all callers of acpi_bus_register_driver(), and except asus_acpi.c and sonypi.c (fixed in previous patches), all either ignore the return value or test only for failure (<0).
drivers/acpi/scan.c +5 -11
@@ -550,10 +550,9 @@return_VALUE (result); } -static int acpi_driver_attach (struct acpi_driver *drv) +static void acpi_driver_attach (struct acpi_driver *drv) {struct list_head *node, *next; -int count =0 ;ACPI_FUNCTION_TRACE ("acpi_driver_attach" );
@@ -570,7 +569,6 @@if (!acpi_bus_driver_init (dev, drv)) {acpi_start_single_object (dev);atomic_inc (&drv->references); - count++;ACPI_DEBUG_PRINT ((ACPI_DB_INFO ,"Found driver [%s] for device [%s]\n" , drv->name, dev->pnp.bus_id));
@@ -579,7 +577,6 @@spin_lock (&acpi_device_lock); }spin_unlock (&acpi_device_lock); -return_VALUE (count); }static int acpi_driver_detach (struct acpi_driver *drv)
@@ -612,14 +609,11 @@* @driver: driver being registered * * Registers a driver with the ACPI bus. Searches the namespace for all -* devices that match the driver's criteria and binds. Returns the -* number of devices that were claimed by the driver, or a negative -* error status for failure. +* devices that match the driver's criteria and binds. Returns zero for +* success or a negative error status for failure. */ int acpi_bus_register_driver (struct acpi_driver *driver) { -int count; -ACPI_FUNCTION_TRACE ("acpi_bus_register_driver" );if (acpi_disabled)
@@ -631,9 +625,9 @@spin_lock (&acpi_device_lock);list_add_tail (&driver->node, &acpi_bus_drivers);spin_unlock (&acpi_device_lock); - count =acpi_driver_attach (driver); +acpi_driver_attach (driver); -return_VALUE (count); +return_VALUE (0 ); }EXPORT_SYMBOL (acpi_bus_register_driver);
PATCH 4/4 ACPI: simplify scan.c coding
In reply to Bjorn HelgaasNo functional changes; just remove leftover, unused "buffer" and simplify control flow (no need to remember error values and goto the end, when we can simply return the value directly).
drivers/acpi/scan.c +13 -23
@@ -236,12 +236,9 @@int acpi_match_ids (struct acpi_device *device,char *ids) { -int error =0 ; -struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; -if (device->flags.hardware_id)if (strstr (ids, device->pnp.hardware_id)) - goto Done; +return 0 ;if (device->flags.compatible_ids) {struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
@@ -250,15 +247,10 @@/* compare multiple _CID entries against driver ids */ for (i =0 ; i < cid_list->count; i++) {if (strstr (ids, cid_list->id[i].value)) - goto Done; +return 0 ; } } - error = -ENOENT ; - - Done: -if (buffer.pointer) -acpi_os_free (buffer.pointer); -return error; +return -ENOENT ; } static acpi_status
@@ -641,21 +633,19 @@*/ int acpi_bus_unregister_driver (struct acpi_driver *driver) { -int error =0 ; -ACPI_FUNCTION_TRACE ("acpi_bus_unregister_driver" ); -if (driver) { -acpi_driver_detach (driver); +if (!driver) +return_VALUE (-EINVAL ); -if (!atomic_read (&driver->references)) { -spin_lock (&acpi_device_lock); -list_del_init (&driver->node); -spin_unlock (&acpi_device_lock); - } - }else - error = -EINVAL ; -return_VALUE (error); +acpi_driver_detach (driver); + +if (!atomic_read (&driver->references)) { +spin_lock (&acpi_device_lock); +list_del_init (&driver->node); +spin_unlock (&acpi_device_lock); + } +return_VALUE (0 ); }EXPORT_SYMBOL (acpi_bus_unregister_driver);