Skip to contentSkip to conversation

Device managed platform_profile_register()

PATCH Superseded Kurt Borja 2 participants 7 messages Dec 21, 2024 – Dec 23, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kurt Borja

author maintainer
#0 lore raw

cover 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
author maintainer
#1 lore raw

PATCH 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
index 75a1415190ac..d0c88decef8b 100644
@@ -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
index 0682bb4c57e5..d8114435865b 100644
@@ -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
#2 lore raw

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().

---
  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
index 75a1415190ac..d0c88decef8b 100644

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
index 0682bb4c57e5..d8114435865b 100644
@@ -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_*/
author maintainer
#3 lore raw

Re: [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().

---
  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
index 75a1415190ac..d0c88decef8b 100644
@@ -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 Wolf

Quoted 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
index 0682bb4c57e5..d8114435865b 100644
@@ -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 -1
  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);
-

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_*/
author maintainer
#4 lore raw

PATCH 2/2 alienware-wmi: Use devm_platform_profile_register()

In reply to Kurt Borja

Replace 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
index e95d22c7b60c..7b3ee2d6a23d 100644
@@ -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
Reviewed-by on v1 2/2
#5 lore raw

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. Drop remove_thermal_profile() because it's no longer needed.

Quoted 40 lines
---
  drivers/platform/x86/dell/alienware-wmi.c | 10 +---------
  1 file changed, 1 insertion(+), 9 deletions(-)
drivers/platform/x86/dell/alienware-wmi.c +1 -9
index e95d22c7b60c..7b3ee2d6a23d 100644
@@ -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);
  	}
#6 lore raw
In reply to Kurt Borja

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: 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