aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
authorAnisse Astier <anisse@astier.eu>2009-12-10 08:18:15 -0500
committerLen Brown <len.brown@intel.com>2009-12-16 12:40:53 -0500
commit46b51eb9e14afb3bde4bc2fe3bbc22ce012647d4 (patch)
tree05ab778507e4ba9a13c8dec630fccb8646cf9623 /drivers/platform
parentaddd65aac7bcfed7348048b3ce24774718fc44c3 (diff)
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>
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/msi-wmi.c64
1 files changed, 35 insertions, 29 deletions
diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
index fb988d8f4267..dcb048c0793f 100644
--- a/drivers/platform/x86/msi-wmi.c
+++ b/drivers/platform/x86/msi-wmi.c
@@ -284,6 +284,8 @@ static int __init msi_wmi_input_setup(void)
284 int err; 284 int err;
285 285
286 msi_wmi_input_dev = input_allocate_device(); 286 msi_wmi_input_dev = input_allocate_device();
287 if (!msi_wmi_input_dev)
288 return -ENOMEM;
287 289
288 msi_wmi_input_dev->name = "MSI WMI hotkeys"; 290 msi_wmi_input_dev->name = "MSI WMI hotkeys";
289 msi_wmi_input_dev->phys = "wmi/input0"; 291 msi_wmi_input_dev->phys = "wmi/input0";
@@ -314,40 +316,44 @@ static int __init msi_wmi_init(void)
314{ 316{
315 int err; 317 int err;
316 318
317 if (wmi_has_guid(MSIWMI_EVENT_GUID)) { 319 if (!wmi_has_guid(MSIWMI_EVENT_GUID)) {
318 err = wmi_install_notify_handler(MSIWMI_EVENT_GUID, 320 printk(KERN_ERR
319 msi_wmi_notify, NULL); 321 "This machine doesn't have MSI-hotkeys through WMI\n");
320 if (err) 322 return -ENODEV;
321 return -EINVAL; 323 }
322 324 err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
323 err = msi_wmi_input_setup(); 325 msi_wmi_notify, NULL);
324 if (err) { 326 if (err)
325 wmi_remove_notify_handler(MSIWMI_EVENT_GUID); 327 return -EINVAL;
326 return -EINVAL;
327 }
328 328
329 if (!acpi_video_backlight_support()) { 329 err = msi_wmi_input_setup();
330 backlight = backlight_device_register(DRV_NAME, 330 if (err)
331 NULL, NULL, &msi_backlight_ops); 331 goto err_uninstall_notifier;
332 if (IS_ERR(backlight)) {
333 wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
334 input_unregister_device(msi_wmi_input_dev);
335 return -EINVAL;
336 }
337 332
338 backlight->props.max_brightness = ARRAY_SIZE(backlight_map) - 1; 333 if (!acpi_video_backlight_support()) {
339 err = bl_get(NULL); 334 backlight = backlight_device_register(DRV_NAME,
340 if (err < 0) { 335 NULL, NULL, &msi_backlight_ops);
341 wmi_remove_notify_handler(MSIWMI_EVENT_GUID); 336 if (IS_ERR(backlight))
342 input_unregister_device(msi_wmi_input_dev); 337 goto err_free_input;
343 backlight_device_unregister(backlight); 338
344 return -EINVAL; 339 backlight->props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
345 } 340 err = bl_get(NULL);
346 backlight->props.brightness = err; 341 if (err < 0)
347 } 342 goto err_free_backlight;
343
344 backlight->props.brightness = err;
348 } 345 }
349 printk(KERN_INFO DRV_PFX "Event handler installed\n"); 346 printk(KERN_INFO DRV_PFX "Event handler installed\n");
347
350 return 0; 348 return 0;
349
350err_free_backlight:
351 backlight_device_unregister(backlight);
352err_free_input:
353 input_unregister_device(msi_wmi_input_dev);
354err_uninstall_notifier:
355 wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
356 return err;
351} 357}
352 358
353static void __exit msi_wmi_exit(void) 359static void __exit msi_wmi_exit(void)