ACPI: platform_profile: Improve platform_profile_unregister
Subsystems (2)
PATCH v2 1/1 ACPI: platform_profile: Improve platform_profile_unregister
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.
---
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(-)
drivers/acpi/platform_profile.c +9 -10
@@ -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);
include/linux/platform_profile.h +1 -1
@@ -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
Signature · 1 line
2.48.1
Hi Kurt
Quoted 5 lines · Kurt Borja
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
Quoted 79 lines
While at it improve the style and make the function safer by checking for
IS_ERR_OR_NULLbefore dereferencing the device pointer.Signed-off-by Kurt Borja <[email protected]>---
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 forIS_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(-)drivers/acpi/platform_profile.c +9
-10@@ -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);include/linux/platform_profile.h +1
-1@@ -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,include/linux/platform_profile.h +0
-0void *drvdata, const struct platform_profile_ops *ops);
Quoted 3 lines
base-commit:
3e3e377dd1f300bbdd230533686ce9c9f4f8a90dSignature · 1 line
2.48.1
Looks good to me
Mark
Hi Mark,
Quoted 9 lines · Mark Pearson
Hi Kurt
Quoted 5 lines · Kurt Borja
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 :)
Quoted 80 lines
Quoted 80 lines
While at it improve the style and make the function safer by checking for
IS_ERR_OR_NULLbefore dereferencing the device pointer.Signed-off-by Kurt Borja <[email protected]>---
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 forIS_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(-)drivers/acpi/platform_profile.c +9
-10@@ -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);include/linux/platform_profile.h +1
-1@@ -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,include/linux/platform_profile.h +0
-0void *drvdata, const struct platform_profile_ops *ops);
Quoted 5 lines
Quoted 3 lines
base-commit:
3e3e377dd1f300bbdd230533686ce9c9f4f8a90dSignature · 1 line
2.48.1Looks good to me
Reviewed-by Mark Pearson <[email protected]>
Thank you very much!
Signature · 1 line
~ Kurt
Quoted 2 lines
Mark
Quoted 82 lines · Kurt Borja
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_NULLbefore dereferencing the device pointer.Signed-off-by Kurt Borja <[email protected]>---
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 forIS_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(-)drivers/acpi/platform_profile.c +9
-10@@ -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);include/linux/platform_profile.h +1
-1@@ -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);
Quoted 2 lines
base-commit:
3e3e377dd1f300bbdd230533686ce9c9f4f8a90d--
Applied as 6.15 material with minor edits in the changelog, thanks!