Device managed platform_profile_register()
Subsystems (3)
Kurt Borja
maintainercover Device managed platform_profile_register()
Hi :)
Now that the platform profile is tied to a device, this would be a nice thing to have. Let me know what you think!
I can also replace existing users of platform_profile_register() where it makes sense, if that's ok.
This is meant to be merged on the pdx86 tree.
~ Kurt
Kurt Borja (2):
ACPI: platform_profile: Add devm_platform_profile_register()
alienware-wmi: Use devm_platform_profile_register()
drivers/acpi/platform_profile.c | 27 +++++++++++++++++++++++ drivers/platform/x86/dell/alienware-wmi.c | 10 +-------- include/linux/platform_profile.h | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-)
base-commit: 9e0894d07072e50b83ef077ce91e504bdb7484a3
Signature · 1 line
2.47.1
Kurt Borja
maintainerPATCH 1/2 ACPI: platform_profile: Add devm_platform_profile_register()
Platform profile's lifetime is usually tied to a device's lifetime, therefore add a device managed version of platform_profile_register().
--- drivers/acpi/platform_profile.c | 27 +++++++++++++++++++++++++++ include/linux/platform_profile.h | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-)
drivers/acpi/platform_profile.c +27 -0
@@ -519,6 +519,33 @@ int platform_profile_remove(struct platform_profile_handler *pprof) }EXPORT_SYMBOL_GPL (platform_profile_remove); +static void devm_platform_profile_release (struct device *dev,void *res) +{ +platform_profile_remove (*(struct platform_profile_handler **) res); +} + +int devm_platform_profile_register (struct platform_profile_handler *pprof) +{ +struct platform_profile_handler **dr; +int ret; + + dr =devres_alloc (devm_platform_profile_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + ret =platform_profile_register (pprof); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = pprof; +devres_add (pprof->dev, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_platform_profile_register); +static int __init platform_profile_init (void ) {int err;
include/linux/platform_profile.h +1 -1
@@ -41,7 +41,7 @@ struct platform_profile_handler {int platform_profile_register (struct platform_profile_handler *pprof);int platform_profile_remove (struct platform_profile_handler *pprof); +int devm_platform_profile_register (struct platform_profile_handler *pprof);int platform_profile_cycle (void );void platform_profile_notify (struct platform_profile_handler *pprof); -#endif /*_PLATFORM_PROFILE_H_*/
Signature · 1 line
2.47.1
Re: [PATCH 1/2] ACPI: platform_profile: Add devm_platform_profile_register()
Am 21.12.24 um 08:08 schrieb Kurt Borja:
Quoted 14 lines
Platform profile's lifetime is usually tied to a device's lifetime, therefore add a device managed version of
platform_profile_register().Signed-off-by Kurt Borja <[email protected]>--- drivers/acpi/platform_profile.c | 27 +++++++++++++++++++++++++++ include/linux/platform_profile.h | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-)drivers/acpi/platform_profile.c +0
-0
drivers/acpi/platform_profile.c int platform_profile_remove(struct platform_profile_handler *pprof) · line 524
Quoted 6 lines
drivers/acpi/platform_profile.c +3
-0@@ -519,6 +519,33 @@ int platform_profile_remove(struct platform_profile_handler *pprof) }EXPORT_SYMBOL_GPL (platform_profile_remove); +static void devm_platform_profile_release (struct device *dev,void *res) +{ +platform_profile_remove (*(struct platform_profile_handler **) res);
Please introduce a local variable instead of using a convoluted cast like this.
drivers/acpi/platform_profile.c int platform_profile_remove(struct platform_profile_handler *pprof) · line 534
Quoted 10 lines
drivers/acpi/platform_profile.c +10
-0+} + +int devm_platform_profile_register (struct platform_profile_handler *pprof) +{ +struct platform_profile_handler **dr; +int ret; + + dr =devres_alloc (devm_platform_profile_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ;
Maybe it would make sense to turn dr into a normal pointer? AFAIK there is no benefit in having another pointer if we can just use the original pointer.
Thanks,
Armin Wolf
Quoted 30 lines
drivers/acpi/platform_profile.c +14
-0+ + ret =platform_profile_register (pprof); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = pprof; +devres_add (pprof->dev, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_platform_profile_register); +static int __init platform_profile_init (void ) {int err;include/linux/platform_profile.h +1
-1@@ -41,7 +41,7 @@ struct platform_profile_handler {int platform_profile_register (struct platform_profile_handler *pprof);int platform_profile_remove (struct platform_profile_handler *pprof); +int devm_platform_profile_register (struct platform_profile_handler *pprof);int platform_profile_cycle (void );void platform_profile_notify (struct platform_profile_handler *pprof); -#endif /*_PLATFORM_PROFILE_H_*/
Kurt Borja
maintainerRe: [PATCH 1/2] ACPI: platform_profile: Add devm_platform_profile_register()
Quoted 19 lines · Armin Wolf
Am 21.12.24 um 08:08 schrieb Kurt Borja:
Quoted 17 lines
Platform profile's lifetime is usually tied to a device's lifetime, therefore add a device managed version of
platform_profile_register().Signed-off-by Kurt Borja <[email protected]>--- drivers/acpi/platform_profile.c | 27 +++++++++++++++++++++++++++ include/linux/platform_profile.h | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-)drivers/acpi/platform_profile.c +0
-0@@ -519,6 +519,33 @@ int platform_profile_remove(struct platform_profile_handler *pprof) }EXPORT_SYMBOL_GPL (platform_profile_remove);
Quoted 5 lines
drivers/acpi/platform_profile.c int platform_profile_remove(struct platform_profile_handler *pprof) · line 524
Quoted 3 lines
drivers/acpi/platform_profile.c +3
-0+static void devm_platform_profile_release (struct device *dev,void *res) +{ +platform_profile_remove (*(struct platform_profile_handler **) res);Please introduce a local variable instead of using a convoluted cast like this.
Sure!
Quoted 14 lines
drivers/acpi/platform_profile.c int platform_profile_remove(struct platform_profile_handler *pprof) · line 534
Quoted 11 lines
drivers/acpi/platform_profile.c +10
-0+} + +int devm_platform_profile_register (struct platform_profile_handler *pprof) +{ +struct platform_profile_handler **dr; +int ret; + + dr =devres_alloc (devm_platform_profile_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return -ENOMEM ;Maybe it would make sense to turn dr into a normal pointer? AFAIK there is no benefit in having another pointer if we can just use the original pointer.
Please, tell me if I'm wrong. devres_alloc returns a pointer to the data buffer of the devres struct and the handler is already allocated by the driver, so the only way to store *pprof is to have dr be **.
Quoted 27 lines
Thanks,
Armin WolfQuoted 23 lines
drivers/acpi/platform_profile.c +14
-0+ + ret =platform_profile_register (pprof); +if (ret) { +devres_free (dr); +return ret; + } + + *dr = pprof; +devres_add (pprof->dev, dr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_platform_profile_register); +static int __init platform_profile_init (void ) {int err;include/linux/platform_profile.h +0
-0@@ -41,7 +41,7 @@ struct platform_profile_handler {
Quoted 6 lines
include/linux/platform_profile.h struct platform_profile_handler { · line 46
Quoted 6 lines
include/linux/platform_profile.h +1
-1int platform_profile_register (struct platform_profile_handler *pprof);int platform_profile_remove (struct platform_profile_handler *pprof); +int devm_platform_profile_register (struct platform_profile_handler *pprof);int platform_profile_cycle (void );void platform_profile_notify (struct platform_profile_handler *pprof); -
BTW, I just saw this -. I'll remove it on v2.
Quoted 1 line
Quoted 1 line
include/linux/platform_profile.h +0
-0#endif /*_PLATFORM_PROFILE_H_*/
Kurt Borja
maintainerPATCH 2/2 alienware-wmi: Use devm_platform_profile_register()
In reply to Kurt BorjaReplace platform_profile_register() with it's device managed version. Drop remove_thermal_profile() because it's no longer needed.
--- drivers/platform/x86/dell/alienware-wmi.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/platform/x86/dell/alienware-wmi.c +1 -9
@@ -1159,13 +1159,7 @@ static int create_thermal_profile(struct platform_device *platform_device) pp_handler.name ="alienware-wmi" ; pp_handler.dev = &platform_device->dev; -return platform_profile_register (&pp_handler); -} - -static void remove_thermal_profile (void ) -{ -if (quirks->thermal) -platform_profile_remove (&pp_handler); +return devm_platform_profile_register (&pp_handler); }static int __init alienware_wmi_init (void )
@@ -1239,7 +1233,6 @@ static int __init alienware_wmi_init(void) fail_prep_zones:alienware_zone_exit (platform_device); -remove_thermal_profile (); fail_prep_thermal_profile: fail_prep_deepsleep: fail_prep_amplifier:
@@ -1260,7 +1253,6 @@ static void __exit alienware_wmi_exit(void)if (platform_device) {alienware_zone_exit (platform_device);remove_hdmi (platform_device); -remove_thermal_profile ();platform_device_unregister (platform_device);platform_driver_unregister (&platform_driver); }
Signature · 1 line
2.47.1
Re: [PATCH 2/2] alienware-wmi: Use devm_platform_profile_register()
Am 21.12.24 um 08:08 schrieb Kurt Borja:
Quoted 2 lines
Replace
platform_profile_register()with it's device managed version. Dropremove_thermal_profile()because it's no longer needed.
Quoted 40 lines
Signed-off-by Kurt Borja <[email protected]>--- drivers/platform/x86/dell/alienware-wmi.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/platform/x86/dell/alienware-wmi.c +1
-9@@ -1159,13 +1159,7 @@ static int create_thermal_profile(struct platform_device *platform_device) pp_handler.name ="alienware-wmi" ; pp_handler.dev = &platform_device->dev; -return platform_profile_register (&pp_handler); -} - -static void remove_thermal_profile (void ) -{ -if (quirks->thermal) -platform_profile_remove (&pp_handler); +return devm_platform_profile_register (&pp_handler); }static int __init alienware_wmi_init (void )@@ -1239,7 +1233,6 @@ static int __init alienware_wmi_init(void) fail_prep_zones:alienware_zone_exit (platform_device); -remove_thermal_profile (); fail_prep_thermal_profile: fail_prep_deepsleep: fail_prep_amplifier:@@ -1260,7 +1253,6 @@ static void __exit alienware_wmi_exit(void)if (platform_device) {alienware_zone_exit (platform_device);remove_hdmi (platform_device); -remove_thermal_profile ();platform_device_unregister (platform_device);platform_driver_unregister (&platform_driver); }
Am 21.12.24 um 08:08 schrieb Kurt Borja:
Quoted 4 lines
Hi :)
Now that the platform profile is tied to a device, this would be a nice thing to have. Let me know what you think!
Hi,
i like this patch series, having a devres version of platform_profile_register() will be very helpful in simplifying the error handling of such drivers.
Quoted 2 lines
I can also replace existing users of
platform_profile_register()where it makes sense, if that's ok.
Sure. However keep in mind that this is entirely optional :).
Thanks,
Armin Wolf
Quoted 16 lines
This is meant to be merged on the pdx86 tree.
~ Kurt
Kurt Borja (2):
ACPI:platform_profile: Adddevm_platform_profile_register()
alienware-wmi: Usedevm_platform_profile_register()drivers/acpi/platform_profile.c | 27 +++++++++++++++++++++++ drivers/platform/x86/dell/alienware-wmi.c | 10 +-------- include/linux/platform_profile.h | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-)base-commit:
9e0894d07072e50b83ef077ce91e504bdb7484a3