From: Anisse Astier <anisse@astier.eu>
To: linux-acpi@vger.kernel.org, linux-input@vger.kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Len Brown <lenb@kernel.org>,
Matthew Garrett <mjg59@srcf.ucam.org>,
Thomas Renninger <trenn@suse.de>,
Carlos Corbacho <carlos@strangeworlds.co.uk>,
Matt Chen <machen@novell.com>, Anisse Astier <anisse@astier.eu>
Subject: [PATCH 3/7] msi-wmi: rework init
Date: Thu, 10 Dec 2009 14:18:15 +0100 [thread overview]
Message-ID: <1260451099-25620-4-git-send-email-anisse@astier.eu> (raw)
In-Reply-To: <1260451099-25620-1-git-send-email-anisse@astier.eu>
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>
---
drivers/platform/x86/msi-wmi.c | 64 ++++++++++++++++++++++------------------
1 files changed, 35 insertions(+), 29 deletions(-)
diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
index fb988d8..dcb048c 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)
int err;
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->phys = "wmi/input0";
@@ -314,40 +316,44 @@ static int __init msi_wmi_init(void)
{
int err;
- if (wmi_has_guid(MSIWMI_EVENT_GUID)) {
- err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
- msi_wmi_notify, NULL);
- if (err)
- return -EINVAL;
-
- err = msi_wmi_input_setup();
- if (err) {
- wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
- return -EINVAL;
- }
+ if (!wmi_has_guid(MSIWMI_EVENT_GUID)) {
+ printk(KERN_ERR
+ "This machine doesn't have MSI-hotkeys through WMI\n");
+ return -ENODEV;
+ }
+ err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
+ msi_wmi_notify, NULL);
+ if (err)
+ return -EINVAL;
- if (!acpi_video_backlight_support()) {
- backlight = backlight_device_register(DRV_NAME,
- NULL, NULL, &msi_backlight_ops);
- if (IS_ERR(backlight)) {
- wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
- input_unregister_device(msi_wmi_input_dev);
- return -EINVAL;
- }
+ err = msi_wmi_input_setup();
+ if (err)
+ goto err_uninstall_notifier;
- backlight->props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
- err = bl_get(NULL);
- if (err < 0) {
- wmi_remove_notify_handler(MSIWMI_EVENT_GUID);
- input_unregister_device(msi_wmi_input_dev);
- backlight_device_unregister(backlight);
- return -EINVAL;
- }
- backlight->props.brightness = err;
- }
+ if (!acpi_video_backlight_support()) {
+ backlight = backlight_device_register(DRV_NAME,
+ NULL, NULL, &msi_backlight_ops);
+ if (IS_ERR(backlight))
+ goto err_free_input;
+
+ backlight->props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
+ err = bl_get(NULL);
+ if (err < 0)
+ goto err_free_backlight;
+
+ backlight->props.brightness = err;
}
printk(KERN_INFO DRV_PFX "Event handler installed\n");
+
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)
--
1.6.5.3
next prev parent reply other threads:[~2009-12-10 13:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-10 13:18 [PATCH 0/7] msi-wmi driver and cleanups Anisse Astier
2009-12-10 13:18 ` [PATCH 1/7] X86 drivers: Introduce msi-wmi driver Anisse Astier
2009-12-12 17:37 ` Alan Jenkins
2009-12-12 19:21 ` Anisse Astier
2009-12-14 9:55 ` Anisse Astier
2009-12-14 11:31 ` Alan Jenkins
2009-12-16 17:44 ` Len Brown
2009-12-17 10:28 ` [PATCH] MAINTAINERS: add maintainer for " Anisse Astier
2009-12-23 7:26 ` Len Brown
2009-12-10 13:18 ` [PATCH 2/7] msi-wmi: remove useless includes Anisse Astier
2009-12-10 13:18 ` Anisse Astier [this message]
2009-12-10 13:18 ` [PATCH 4/7] msi-wmi: remove custom runtime debug implementation Anisse Astier
2009-12-10 13:18 ` [PATCH 5/7] msi-wmi: remove unused field 'instance' in key_entry structure Anisse Astier
2009-12-10 13:18 ` [PATCH 6/7] msi-wmi: replace one-condition switch-case with if statement Anisse Astier
2009-12-10 13:18 ` [PATCH 7/7] msi-wmi: switch to using input sparse keymap library Anisse Astier
2009-12-10 15:18 ` [PATCH 0/7] msi-wmi driver and cleanups Thomas Renninger
2009-12-10 18:07 ` Anisse Astier
2009-12-10 17:47 ` Dmitry Torokhov
2009-12-10 18:14 ` Anisse Astier
2009-12-14 11:34 ` [PATCH 8/7] msi-wmi: depend on backlight and fix corner-cases problems Anisse Astier
2009-12-15 9:55 ` [PATCH 0/7] msi-wmi driver and cleanups Anisse Astier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1260451099-25620-4-git-send-email-anisse@astier.eu \
--to=anisse@astier.eu \
--cc=carlos@strangeworlds.co.uk \
--cc=dmitry.torokhov@gmail.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=machen@novell.com \
--cc=mjg59@srcf.ucam.org \
--cc=trenn@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).