aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2013-02-20 03:44:34 -0500
committerMatthew Garrett <matthew.garrett@nebula.com>2013-02-27 08:30:43 -0500
commitc165b80cfecc5f253e93ebd133f7c53cf81d82d5 (patch)
treef2b116203238dce30af1226574b6451f38905d6f /drivers/platform/x86
parent34cf1df34aba1a6274deeef92ad6d02d5f52dab0 (diff)
hp-wmi: fix handling of platform device
The driver will not quite work if someone unbinds the platform device from the platform driver via sysfs (moreover it will bomb is the driver built into the kernel as hp_wmi_bios_remove is marked as __exit and will not be present in the kernel). To fix it let's use platform_driver_probe() instead of platform_driver_register(), which disables binding/unbinding via sysfs. This also allows us to mark hp_wmi_bios_setup as __init and discard it once module is initialized. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
Diffstat (limited to 'drivers/platform/x86')
-rw-r--r--drivers/platform/x86/hp-wmi.c69
1 files changed, 30 insertions, 39 deletions
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index be9227dd82be..45cacf79f3a7 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -73,10 +73,6 @@ enum hp_wmi_event_ids {
73 HPWMI_LOCK_SWITCH = 7, 73 HPWMI_LOCK_SWITCH = 7,
74}; 74};
75 75
76static int hp_wmi_bios_setup(struct platform_device *device);
77static int __exit hp_wmi_bios_remove(struct platform_device *device);
78static int hp_wmi_resume_handler(struct device *device);
79
80struct bios_args { 76struct bios_args {
81 u32 signature; 77 u32 signature;
82 u32 command; 78 u32 command;
@@ -160,21 +156,6 @@ struct rfkill2_device {
160static int rfkill2_count; 156static int rfkill2_count;
161static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES]; 157static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];
162 158
163static const struct dev_pm_ops hp_wmi_pm_ops = {
164 .resume = hp_wmi_resume_handler,
165 .restore = hp_wmi_resume_handler,
166};
167
168static struct platform_driver hp_wmi_driver = {
169 .driver = {
170 .name = "hp-wmi",
171 .owner = THIS_MODULE,
172 .pm = &hp_wmi_pm_ops,
173 },
174 .probe = hp_wmi_bios_setup,
175 .remove = hp_wmi_bios_remove,
176};
177
178/* 159/*
179 * hp_wmi_perform_query 160 * hp_wmi_perform_query
180 * 161 *
@@ -812,7 +793,7 @@ fail:
812 return err; 793 return err;
813} 794}
814 795
815static int hp_wmi_bios_setup(struct platform_device *device) 796static int __init hp_wmi_bios_setup(struct platform_device *device)
816{ 797{
817 int err; 798 int err;
818 799
@@ -917,12 +898,29 @@ static int hp_wmi_resume_handler(struct device *device)
917 return 0; 898 return 0;
918} 899}
919 900
901static const struct dev_pm_ops hp_wmi_pm_ops = {
902 .resume = hp_wmi_resume_handler,
903 .restore = hp_wmi_resume_handler,
904};
905
906static struct platform_driver hp_wmi_driver = {
907 .driver = {
908 .name = "hp-wmi",
909 .owner = THIS_MODULE,
910 .pm = &hp_wmi_pm_ops,
911 },
912 .remove = __exit_p(hp_wmi_bios_remove),
913};
914
920static int __init hp_wmi_init(void) 915static int __init hp_wmi_init(void)
921{ 916{
922 int err; 917 int err;
923 int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); 918 int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
924 int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); 919 int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
925 920
921 if (!bios_capable && !event_capable)
922 return -ENODEV;
923
926 if (event_capable) { 924 if (event_capable) {
927 err = hp_wmi_input_setup(); 925 err = hp_wmi_input_setup();
928 if (err) 926 if (err)
@@ -933,34 +931,29 @@ static int __init hp_wmi_init(void)
933 } 931 }
934 932
935 if (bios_capable) { 933 if (bios_capable) {
936 err = platform_driver_register(&hp_wmi_driver); 934 hp_wmi_platform_dev =
937 if (err) 935 platform_device_register_simple("hp-wmi", -1, NULL, 0);
938 goto err_driver_reg; 936 if (IS_ERR(hp_wmi_platform_dev)) {
939 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); 937 err = PTR_ERR(hp_wmi_platform_dev);
940 if (!hp_wmi_platform_dev) { 938 goto err_destroy_input;
941 err = -ENOMEM;
942 goto err_device_alloc;
943 } 939 }
944 err = platform_device_add(hp_wmi_platform_dev); 940
941 err = platform_driver_probe(&hp_wmi_driver, hp_wmi_bios_setup);
945 if (err) 942 if (err)
946 goto err_device_add; 943 goto err_unregister_device;
947 } 944 }
948 945
949 if (!bios_capable && !event_capable)
950 return -ENODEV;
951
952 return 0; 946 return 0;
953 947
954err_device_add: 948err_unregister_device:
955 platform_device_put(hp_wmi_platform_dev); 949 platform_device_unregister(hp_wmi_platform_dev);
956err_device_alloc: 950err_destroy_input:
957 platform_driver_unregister(&hp_wmi_driver);
958err_driver_reg:
959 if (event_capable) 951 if (event_capable)
960 hp_wmi_input_destroy(); 952 hp_wmi_input_destroy();
961 953
962 return err; 954 return err;
963} 955}
956module_init(hp_wmi_init);
964 957
965static void __exit hp_wmi_exit(void) 958static void __exit hp_wmi_exit(void)
966{ 959{
@@ -972,6 +965,4 @@ static void __exit hp_wmi_exit(void)
972 platform_driver_unregister(&hp_wmi_driver); 965 platform_driver_unregister(&hp_wmi_driver);
973 } 966 }
974} 967}
975
976module_init(hp_wmi_init);
977module_exit(hp_wmi_exit); 968module_exit(hp_wmi_exit);