Skip to content

Commit c165b80

Browse files
dtorMatthew Garrett
authored andcommitted
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 <[email protected]> Signed-off-by: Matthew Garrett <[email protected]>
1 parent 34cf1df commit c165b80

File tree

1 file changed

+30
-39
lines changed

1 file changed

+30
-39
lines changed

drivers/platform/x86/hp-wmi.c

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ enum hp_wmi_event_ids {
7373
HPWMI_LOCK_SWITCH = 7,
7474
};
7575

76-
static int hp_wmi_bios_setup(struct platform_device *device);
77-
static int __exit hp_wmi_bios_remove(struct platform_device *device);
78-
static int hp_wmi_resume_handler(struct device *device);
79-
8076
struct bios_args {
8177
u32 signature;
8278
u32 command;
@@ -160,21 +156,6 @@ struct rfkill2_device {
160156
static int rfkill2_count;
161157
static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];
162158

163-
static const struct dev_pm_ops hp_wmi_pm_ops = {
164-
.resume = hp_wmi_resume_handler,
165-
.restore = hp_wmi_resume_handler,
166-
};
167-
168-
static 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-
178159
/*
179160
* hp_wmi_perform_query
180161
*
@@ -812,7 +793,7 @@ static int hp_wmi_rfkill2_setup(struct platform_device *device)
812793
return err;
813794
}
814795

815-
static int hp_wmi_bios_setup(struct platform_device *device)
796+
static int __init hp_wmi_bios_setup(struct platform_device *device)
816797
{
817798
int err;
818799

@@ -917,12 +898,29 @@ static int hp_wmi_resume_handler(struct device *device)
917898
return 0;
918899
}
919900

901+
static const struct dev_pm_ops hp_wmi_pm_ops = {
902+
.resume = hp_wmi_resume_handler,
903+
.restore = hp_wmi_resume_handler,
904+
};
905+
906+
static 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+
920915
static int __init hp_wmi_init(void)
921916
{
922917
int err;
923918
int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
924919
int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
925920

921+
if (!bios_capable && !event_capable)
922+
return -ENODEV;
923+
926924
if (event_capable) {
927925
err = hp_wmi_input_setup();
928926
if (err)
@@ -933,34 +931,29 @@ static int __init hp_wmi_init(void)
933931
}
934932

935933
if (bios_capable) {
936-
err = platform_driver_register(&hp_wmi_driver);
937-
if (err)
938-
goto err_driver_reg;
939-
hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
940-
if (!hp_wmi_platform_dev) {
941-
err = -ENOMEM;
942-
goto err_device_alloc;
934+
hp_wmi_platform_dev =
935+
platform_device_register_simple("hp-wmi", -1, NULL, 0);
936+
if (IS_ERR(hp_wmi_platform_dev)) {
937+
err = PTR_ERR(hp_wmi_platform_dev);
938+
goto err_destroy_input;
943939
}
944-
err = platform_device_add(hp_wmi_platform_dev);
940+
941+
err = platform_driver_probe(&hp_wmi_driver, hp_wmi_bios_setup);
945942
if (err)
946-
goto err_device_add;
943+
goto err_unregister_device;
947944
}
948945

949-
if (!bios_capable && !event_capable)
950-
return -ENODEV;
951-
952946
return 0;
953947

954-
err_device_add:
955-
platform_device_put(hp_wmi_platform_dev);
956-
err_device_alloc:
957-
platform_driver_unregister(&hp_wmi_driver);
958-
err_driver_reg:
948+
err_unregister_device:
949+
platform_device_unregister(hp_wmi_platform_dev);
950+
err_destroy_input:
959951
if (event_capable)
960952
hp_wmi_input_destroy();
961953

962954
return err;
963955
}
956+
module_init(hp_wmi_init);
964957

965958
static void __exit hp_wmi_exit(void)
966959
{
@@ -972,6 +965,4 @@ static void __exit hp_wmi_exit(void)
972965
platform_driver_unregister(&hp_wmi_driver);
973966
}
974967
}
975-
976-
module_init(hp_wmi_init);
977968
module_exit(hp_wmi_exit);

0 commit comments

Comments
 (0)