mirror of https://gitee.com/openkylin/linux.git
platform/x86: fujitsu-laptop: add and remove platform device in separate functions
Platform device handling adds a lot of complexity to fujitsu_init(), which hinders its readability. Extract code responsible for adding and removing the platform device to separate functions. Adjust whitespace to make checkpatch happy. Signed-off-by: Michał Kępień <kernel@kempniu.pl> Tested-by: Jonathan Woithe <jwoithe@just42.net> Reviewed-by: Jonathan Woithe <jwoithe@just42.net> Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
This commit is contained in:
parent
b0c4b9c64e
commit
d811b511c1
|
@ -765,6 +765,40 @@ static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
|
|||
|
||||
/* ACPI device for hotkey handling */
|
||||
|
||||
static int fujitsu_laptop_platform_add(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
|
||||
if (!fujitsu_bl->pf_device)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = platform_device_add(fujitsu_bl->pf_device);
|
||||
if (ret)
|
||||
goto err_put_platform_device;
|
||||
|
||||
ret = sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
|
||||
&fujitsu_pf_attribute_group);
|
||||
if (ret)
|
||||
goto err_del_platform_device;
|
||||
|
||||
return 0;
|
||||
|
||||
err_del_platform_device:
|
||||
platform_device_del(fujitsu_bl->pf_device);
|
||||
err_put_platform_device:
|
||||
platform_device_put(fujitsu_bl->pf_device);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void fujitsu_laptop_platform_remove(void)
|
||||
{
|
||||
sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
|
||||
&fujitsu_pf_attribute_group);
|
||||
platform_device_unregister(fujitsu_bl->pf_device);
|
||||
}
|
||||
|
||||
static int acpi_fujitsu_laptop_add(struct acpi_device *device)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -1146,25 +1180,13 @@ static int __init fujitsu_init(void)
|
|||
|
||||
/* Register platform stuff */
|
||||
|
||||
fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
|
||||
if (!fujitsu_bl->pf_device) {
|
||||
ret = -ENOMEM;
|
||||
ret = fujitsu_laptop_platform_add();
|
||||
if (ret)
|
||||
goto err_unregister_acpi;
|
||||
}
|
||||
|
||||
ret = platform_device_add(fujitsu_bl->pf_device);
|
||||
if (ret)
|
||||
goto err_put_platform_device;
|
||||
|
||||
ret =
|
||||
sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
|
||||
&fujitsu_pf_attribute_group);
|
||||
if (ret)
|
||||
goto err_del_platform_device;
|
||||
|
||||
ret = platform_driver_register(&fujitsu_pf_driver);
|
||||
if (ret)
|
||||
goto err_remove_sysfs_group;
|
||||
goto err_remove_platform_device;
|
||||
|
||||
/* Register laptop driver */
|
||||
|
||||
|
@ -1186,13 +1208,8 @@ static int __init fujitsu_init(void)
|
|||
kfree(fujitsu_laptop);
|
||||
err_unregister_platform_driver:
|
||||
platform_driver_unregister(&fujitsu_pf_driver);
|
||||
err_remove_sysfs_group:
|
||||
sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
|
||||
&fujitsu_pf_attribute_group);
|
||||
err_del_platform_device:
|
||||
platform_device_del(fujitsu_bl->pf_device);
|
||||
err_put_platform_device:
|
||||
platform_device_put(fujitsu_bl->pf_device);
|
||||
err_remove_platform_device:
|
||||
fujitsu_laptop_platform_remove();
|
||||
err_unregister_acpi:
|
||||
acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
|
||||
err_free_fujitsu_bl:
|
||||
|
@ -1209,10 +1226,7 @@ static void __exit fujitsu_cleanup(void)
|
|||
|
||||
platform_driver_unregister(&fujitsu_pf_driver);
|
||||
|
||||
sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
|
||||
&fujitsu_pf_attribute_group);
|
||||
|
||||
platform_device_unregister(fujitsu_bl->pf_device);
|
||||
fujitsu_laptop_platform_remove();
|
||||
|
||||
acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
|
||||
|
||||
|
|
Loading…
Reference in New Issue