msi-wmi: rework init
There should be less code duplication with usage of gotos Driver won't load if there's no hardware to control Safer error handling at input driver allocation Signed-off-by: Anisse Astier <anisse@astier.eu> Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
addd65aac7
commit
46b51eb9e1
@ -284,6 +284,8 @@ static int __init msi_wmi_input_setup(void)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
msi_wmi_input_dev = input_allocate_device();
|
msi_wmi_input_dev = input_allocate_device();
|
||||||
|
if (!msi_wmi_input_dev)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
msi_wmi_input_dev->name = "MSI WMI hotkeys";
|
msi_wmi_input_dev->name = "MSI WMI hotkeys";
|
||||||
msi_wmi_input_dev->phys = "wmi/input0";
|
msi_wmi_input_dev->phys = "wmi/input0";
|
||||||
@ -314,40 +316,44 @@ static int __init msi_wmi_init(void)
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (wmi_has_guid(MSIWMI_EVENT_GUID)) {
|
if (!wmi_has_guid(MSIWMI_EVENT_GUID)) {
|
||||||
err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
|
printk(KERN_ERR
|
||||||
msi_wmi_notify, NULL);
|
"This machine doesn't have MSI-hotkeys through WMI\n");
|
||||||
if (err)
|
return -ENODEV;
|
||||||
return -EINVAL;
|
}
|
||||||
|
err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
|
||||||
|
msi_wmi_notify, NULL);
|
||||||
|
if (err)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
err = msi_wmi_input_setup();
|
err = msi_wmi_input_setup();
|
||||||
if (err) {
|
if (err)
|
||||||
wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
|
goto err_uninstall_notifier;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!acpi_video_backlight_support()) {
|
if (!acpi_video_backlight_support()) {
|
||||||
backlight = backlight_device_register(DRV_NAME,
|
backlight = backlight_device_register(DRV_NAME,
|
||||||
NULL, NULL, &msi_backlight_ops);
|
NULL, NULL, &msi_backlight_ops);
|
||||||
if (IS_ERR(backlight)) {
|
if (IS_ERR(backlight))
|
||||||
wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
|
goto err_free_input;
|
||||||
input_unregister_device(msi_wmi_input_dev);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
backlight->props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
|
backlight->props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
|
||||||
err = bl_get(NULL);
|
err = bl_get(NULL);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
|
goto err_free_backlight;
|
||||||
input_unregister_device(msi_wmi_input_dev);
|
|
||||||
backlight_device_unregister(backlight);
|
backlight->props.brightness = err;
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
backlight->props.brightness = err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
printk(KERN_INFO DRV_PFX "Event handler installed\n");
|
printk(KERN_INFO DRV_PFX "Event handler installed\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_free_backlight:
|
||||||
|
backlight_device_unregister(backlight);
|
||||||
|
err_free_input:
|
||||||
|
input_unregister_device(msi_wmi_input_dev);
|
||||||
|
err_uninstall_notifier:
|
||||||
|
wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit msi_wmi_exit(void)
|
static void __exit msi_wmi_exit(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user