* [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister
@ 2025-02-12 19:03 Kurt Borja
2025-02-12 20:41 ` Mark Pearson
2025-02-18 18:04 ` Rafael J. Wysocki
0 siblings, 2 replies; 4+ messages in thread
From: Kurt Borja @ 2025-02-12 19:03 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Len Brown, linux-acpi, linux-kernel, Ilpo Järvinen,
Mario Limonciello, platform-driver-x86, Kurt Borja, Mark Pearson
Drivers usually call this method on error/exit paths and do not check
for it's return value, which is always 0 anyway, so make it void. This
is safe to do as currently all drivers use
devm_platform_profile_register().
While at it improve the style and make the function safer by checking
for IS_ERR_OR_NULL before dereferencing the device pointer.
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
Hi all,
I made a little modification that I forgot in the last version.
Rafael, please tell me if you prefer different commits for this. Also
should we WARN_ON(IS_ERR_OR_NULL)?
Based on the acpi branch of the linux-pm tree.
~ Kurt
Changes in v2:
- Get reference to pprof after checking for IS_ERR_OR_NULL(dev)
- CC Mark Pearson (sorry!)
drivers/acpi/platform_profile.c | 19 +++++++++----------
include/linux/platform_profile.h | 2 +-
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index fc92e43d0fe9..ed9c0cc9ea9c 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -569,24 +569,23 @@ EXPORT_SYMBOL_GPL(platform_profile_register);
/**
* platform_profile_remove - Unregisters a platform profile class device
* @dev: Class device
- *
- * Return: 0
*/
-int platform_profile_remove(struct device *dev)
+void platform_profile_remove(struct device *dev)
{
- struct platform_profile_handler *pprof = to_pprof_handler(dev);
- int id;
+ struct platform_profile_handler *pprof;
+
+ if (IS_ERR_OR_NULL(dev))
+ return;
+
+ pprof = to_pprof_handler(dev);
+
guard(mutex)(&profile_lock);
- id = pprof->minor;
+ ida_free(&platform_profile_ida, pprof->minor);
device_unregister(&pprof->dev);
- ida_free(&platform_profile_ida, id);
sysfs_notify(acpi_kobj, NULL, "platform_profile");
-
sysfs_update_group(acpi_kobj, &platform_profile_group);
-
- return 0;
}
EXPORT_SYMBOL_GPL(platform_profile_remove);
diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h
index 8ab5b0e8eb2c..d5499eca9e1d 100644
--- a/include/linux/platform_profile.h
+++ b/include/linux/platform_profile.h
@@ -47,7 +47,7 @@ struct platform_profile_ops {
struct device *platform_profile_register(struct device *dev, const char *name,
void *drvdata,
const struct platform_profile_ops *ops);
-int platform_profile_remove(struct device *dev);
+void platform_profile_remove(struct device *dev);
struct device *devm_platform_profile_register(struct device *dev, const char *name,
void *drvdata,
const struct platform_profile_ops *ops);
base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister
2025-02-12 19:03 [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister Kurt Borja
@ 2025-02-12 20:41 ` Mark Pearson
2025-02-13 0:49 ` Kurt Borja
2025-02-18 18:04 ` Rafael J. Wysocki
1 sibling, 1 reply; 4+ messages in thread
From: Mark Pearson @ 2025-02-12 20:41 UTC (permalink / raw)
To: Kurt Borja, Rafael J. Wysocki
Cc: Len Brown, linux-acpi@vger.kernel.org, linux-kernel,
Ilpo Järvinen, Limonciello, Mario,
platform-driver-x86@vger.kernel.org
Hi Kurt
On Wed, Feb 12, 2025, at 2:03 PM, Kurt Borja wrote:
> Drivers usually call this method on error/exit paths and do not check
> for it's return value, which is always 0 anyway, so make it void. This
> is safe to do as currently all drivers use
> devm_platform_profile_register().
>
I was worried I had mucked that up with the revert done in thinkpad_acpi? But it's not checking the return there so I think it's fine
> While at it improve the style and make the function safer by checking
> for IS_ERR_OR_NULL before dereferencing the device pointer.
>
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
> ---
> Hi all,
>
> I made a little modification that I forgot in the last version.
>
> Rafael, please tell me if you prefer different commits for this. Also
> should we WARN_ON(IS_ERR_OR_NULL)?
>
> Based on the acpi branch of the linux-pm tree.
>
> ~ Kurt
>
> Changes in v2:
> - Get reference to pprof after checking for IS_ERR_OR_NULL(dev)
> - CC Mark Pearson (sorry!)
>
> drivers/acpi/platform_profile.c | 19 +++++++++----------
> include/linux/platform_profile.h | 2 +-
> 2 files changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index fc92e43d0fe9..ed9c0cc9ea9c 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -569,24 +569,23 @@ EXPORT_SYMBOL_GPL(platform_profile_register);
> /**
> * platform_profile_remove - Unregisters a platform profile class device
> * @dev: Class device
> - *
> - * Return: 0
> */
> -int platform_profile_remove(struct device *dev)
> +void platform_profile_remove(struct device *dev)
> {
> - struct platform_profile_handler *pprof = to_pprof_handler(dev);
> - int id;
> + struct platform_profile_handler *pprof;
> +
> + if (IS_ERR_OR_NULL(dev))
> + return;
> +
> + pprof = to_pprof_handler(dev);
> +
> guard(mutex)(&profile_lock);
>
> - id = pprof->minor;
> + ida_free(&platform_profile_ida, pprof->minor);
> device_unregister(&pprof->dev);
> - ida_free(&platform_profile_ida, id);
>
> sysfs_notify(acpi_kobj, NULL, "platform_profile");
> -
> sysfs_update_group(acpi_kobj, &platform_profile_group);
> -
> - return 0;
> }
> EXPORT_SYMBOL_GPL(platform_profile_remove);
>
> diff --git a/include/linux/platform_profile.h
> b/include/linux/platform_profile.h
> index 8ab5b0e8eb2c..d5499eca9e1d 100644
> --- a/include/linux/platform_profile.h
> +++ b/include/linux/platform_profile.h
> @@ -47,7 +47,7 @@ struct platform_profile_ops {
> struct device *platform_profile_register(struct device *dev, const
> char *name,
> void *drvdata,
> const struct platform_profile_ops *ops);
> -int platform_profile_remove(struct device *dev);
> +void platform_profile_remove(struct device *dev);
> struct device *devm_platform_profile_register(struct device *dev,
> const char *name,
> void *drvdata,
> const struct platform_profile_ops *ops);
>
> base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d
> --
> 2.48.1
Looks good to me
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister
2025-02-12 20:41 ` Mark Pearson
@ 2025-02-13 0:49 ` Kurt Borja
0 siblings, 0 replies; 4+ messages in thread
From: Kurt Borja @ 2025-02-13 0:49 UTC (permalink / raw)
To: Mark Pearson, Rafael J. Wysocki
Cc: Len Brown, linux-acpi@vger.kernel.org, linux-kernel,
Ilpo Järvinen, Limonciello, Mario,
platform-driver-x86@vger.kernel.org
Hi Mark,
On Wed Feb 12, 2025 at 3:41 PM -05, Mark Pearson wrote:
> Hi Kurt
>
> On Wed, Feb 12, 2025, at 2:03 PM, Kurt Borja wrote:
>> Drivers usually call this method on error/exit paths and do not check
>> for it's return value, which is always 0 anyway, so make it void. This
>> is safe to do as currently all drivers use
>> devm_platform_profile_register().
>>
> I was worried I had mucked that up with the revert done in thinkpad_acpi? But it's not checking the return there so I think it's fine
Don't worry. I was aware of that :)
>
>> While at it improve the style and make the function safer by checking
>> for IS_ERR_OR_NULL before dereferencing the device pointer.
>>
>> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
>> ---
>> Hi all,
>>
>> I made a little modification that I forgot in the last version.
>>
>> Rafael, please tell me if you prefer different commits for this. Also
>> should we WARN_ON(IS_ERR_OR_NULL)?
>>
>> Based on the acpi branch of the linux-pm tree.
>>
>> ~ Kurt
>>
>> Changes in v2:
>> - Get reference to pprof after checking for IS_ERR_OR_NULL(dev)
>> - CC Mark Pearson (sorry!)
>>
>> drivers/acpi/platform_profile.c | 19 +++++++++----------
>> include/linux/platform_profile.h | 2 +-
>> 2 files changed, 10 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
>> index fc92e43d0fe9..ed9c0cc9ea9c 100644
>> --- a/drivers/acpi/platform_profile.c
>> +++ b/drivers/acpi/platform_profile.c
>> @@ -569,24 +569,23 @@ EXPORT_SYMBOL_GPL(platform_profile_register);
>> /**
>> * platform_profile_remove - Unregisters a platform profile class device
>> * @dev: Class device
>> - *
>> - * Return: 0
>> */
>> -int platform_profile_remove(struct device *dev)
>> +void platform_profile_remove(struct device *dev)
>> {
>> - struct platform_profile_handler *pprof = to_pprof_handler(dev);
>> - int id;
>> + struct platform_profile_handler *pprof;
>> +
>> + if (IS_ERR_OR_NULL(dev))
>> + return;
>> +
>> + pprof = to_pprof_handler(dev);
>> +
>> guard(mutex)(&profile_lock);
>>
>> - id = pprof->minor;
>> + ida_free(&platform_profile_ida, pprof->minor);
>> device_unregister(&pprof->dev);
>> - ida_free(&platform_profile_ida, id);
>>
>> sysfs_notify(acpi_kobj, NULL, "platform_profile");
>> -
>> sysfs_update_group(acpi_kobj, &platform_profile_group);
>> -
>> - return 0;
>> }
>> EXPORT_SYMBOL_GPL(platform_profile_remove);
>>
>> diff --git a/include/linux/platform_profile.h
>> b/include/linux/platform_profile.h
>> index 8ab5b0e8eb2c..d5499eca9e1d 100644
>> --- a/include/linux/platform_profile.h
>> +++ b/include/linux/platform_profile.h
>> @@ -47,7 +47,7 @@ struct platform_profile_ops {
>> struct device *platform_profile_register(struct device *dev, const
>> char *name,
>> void *drvdata,
>> const struct platform_profile_ops *ops);
>> -int platform_profile_remove(struct device *dev);
>> +void platform_profile_remove(struct device *dev);
>> struct device *devm_platform_profile_register(struct device *dev,
>> const char *name,
>> void *drvdata,
>> const struct platform_profile_ops *ops);
>>
>> base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d
>> --
>> 2.48.1
> Looks good to me
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Thank you very much!
--
~ Kurt
>
> Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister
2025-02-12 19:03 [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister Kurt Borja
2025-02-12 20:41 ` Mark Pearson
@ 2025-02-18 18:04 ` Rafael J. Wysocki
1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2025-02-18 18:04 UTC (permalink / raw)
To: Kurt Borja
Cc: Rafael J. Wysocki, Len Brown, linux-acpi, linux-kernel,
Ilpo Järvinen, Mario Limonciello, platform-driver-x86,
Mark Pearson
On Wed, Feb 12, 2025 at 8:03 PM Kurt Borja <kuurtb@gmail.com> wrote:
>
> Drivers usually call this method on error/exit paths and do not check
> for it's return value, which is always 0 anyway, so make it void. This
> is safe to do as currently all drivers use
> devm_platform_profile_register().
>
> While at it improve the style and make the function safer by checking
> for IS_ERR_OR_NULL before dereferencing the device pointer.
>
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
> ---
> Hi all,
>
> I made a little modification that I forgot in the last version.
>
> Rafael, please tell me if you prefer different commits for this. Also
> should we WARN_ON(IS_ERR_OR_NULL)?
>
> Based on the acpi branch of the linux-pm tree.
>
> ~ Kurt
>
> Changes in v2:
> - Get reference to pprof after checking for IS_ERR_OR_NULL(dev)
> - CC Mark Pearson (sorry!)
>
> drivers/acpi/platform_profile.c | 19 +++++++++----------
> include/linux/platform_profile.h | 2 +-
> 2 files changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index fc92e43d0fe9..ed9c0cc9ea9c 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -569,24 +569,23 @@ EXPORT_SYMBOL_GPL(platform_profile_register);
> /**
> * platform_profile_remove - Unregisters a platform profile class device
> * @dev: Class device
> - *
> - * Return: 0
> */
> -int platform_profile_remove(struct device *dev)
> +void platform_profile_remove(struct device *dev)
> {
> - struct platform_profile_handler *pprof = to_pprof_handler(dev);
> - int id;
> + struct platform_profile_handler *pprof;
> +
> + if (IS_ERR_OR_NULL(dev))
> + return;
> +
> + pprof = to_pprof_handler(dev);
> +
> guard(mutex)(&profile_lock);
>
> - id = pprof->minor;
> + ida_free(&platform_profile_ida, pprof->minor);
> device_unregister(&pprof->dev);
> - ida_free(&platform_profile_ida, id);
>
> sysfs_notify(acpi_kobj, NULL, "platform_profile");
> -
> sysfs_update_group(acpi_kobj, &platform_profile_group);
> -
> - return 0;
> }
> EXPORT_SYMBOL_GPL(platform_profile_remove);
>
> diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h
> index 8ab5b0e8eb2c..d5499eca9e1d 100644
> --- a/include/linux/platform_profile.h
> +++ b/include/linux/platform_profile.h
> @@ -47,7 +47,7 @@ struct platform_profile_ops {
> struct device *platform_profile_register(struct device *dev, const char *name,
> void *drvdata,
> const struct platform_profile_ops *ops);
> -int platform_profile_remove(struct device *dev);
> +void platform_profile_remove(struct device *dev);
> struct device *devm_platform_profile_register(struct device *dev, const char *name,
> void *drvdata,
> const struct platform_profile_ops *ops);
>
> base-commit: 3e3e377dd1f300bbdd230533686ce9c9f4f8a90d
> --
Applied as 6.15 material with minor edits in the changelog, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-18 18:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 19:03 [PATCH v2] ACPI: platform_profile: Improve platform_profile_unregister Kurt Borja
2025-02-12 20:41 ` Mark Pearson
2025-02-13 0:49 ` Kurt Borja
2025-02-18 18:04 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox