2022-04-05 23:41:54

by Michael Walle

[permalink] [raw]
Subject: [PATCH v4 0/2] hwmon: introduce hwmon_sanitize()

During development of the support for the temperature sensor on the GPY
PHY, I've noticed that there is ususually a loop over the name to
replace any invalid characters. Instead of open coding it in the drivers
provide a convenience function.

changes since v3:
- don't return NULL but ERR_PTR(-ENOMEM)
- check !dev in devm_ variant

changes since v2:
- doc update
- dropped last three patches, the net patches will be submitted
seperately

changes since v1:
- split patches
- add hwmon-kernel-api.rst documentation
- move the strdup into the hwmon core
- also provide a resource managed variant

Michael Walle (2):
hwmon: introduce hwmon_sanitize_name()
hwmon: intel-m10-bmc-hwmon: use devm_hwmon_sanitize_name()

Documentation/hwmon/hwmon-kernel-api.rst | 16 +++++++
drivers/hwmon/hwmon.c | 53 ++++++++++++++++++++++++
drivers/hwmon/intel-m10-bmc-hwmon.c | 11 ++---
include/linux/hwmon.h | 3 ++
4 files changed, 75 insertions(+), 8 deletions(-)

--
2.30.2


2022-04-06 00:19:55

by Michael Walle

[permalink] [raw]
Subject: [PATCH v4 2/2] hwmon: intel-m10-bmc-hwmon: use devm_hwmon_sanitize_name()

Instead of open-coding the bad characters replacement in the hwmon name,
use the new devm_hwmon_sanitize_name().

Signed-off-by: Michael Walle <[email protected]>
Acked-by: Xu Yilun <[email protected]>
---
drivers/hwmon/intel-m10-bmc-hwmon.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/hwmon/intel-m10-bmc-hwmon.c b/drivers/hwmon/intel-m10-bmc-hwmon.c
index 7a08e4c44a4b..6e82f7200d1c 100644
--- a/drivers/hwmon/intel-m10-bmc-hwmon.c
+++ b/drivers/hwmon/intel-m10-bmc-hwmon.c
@@ -515,7 +515,6 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev)
struct intel_m10bmc *m10bmc = dev_get_drvdata(pdev->dev.parent);
struct device *hwmon_dev, *dev = &pdev->dev;
struct m10bmc_hwmon *hw;
- int i;

hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
if (!hw)
@@ -528,13 +527,9 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev)
hw->chip.info = hw->bdata->hinfo;
hw->chip.ops = &m10bmc_hwmon_ops;

- hw->hw_name = devm_kstrdup(dev, id->name, GFP_KERNEL);
- if (!hw->hw_name)
- return -ENOMEM;
-
- for (i = 0; hw->hw_name[i]; i++)
- if (hwmon_is_bad_char(hw->hw_name[i]))
- hw->hw_name[i] = '_';
+ hw->hw_name = devm_hwmon_sanitize_name(dev, id->name);
+ if (IS_ERR(hw->hw_name))
+ return PTR_ERR(hw->hw_name);

hwmon_dev = devm_hwmon_device_register_with_info(dev, hw->hw_name,
hw, &hw->chip, NULL);
--
2.30.2

2022-04-06 14:53:11

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] hwmon: intel-m10-bmc-hwmon: use devm_hwmon_sanitize_name()


On 4/5/22 2:24 AM, Michael Walle wrote:
> Instead of open-coding the bad characters replacement in the hwmon name,
> use the new devm_hwmon_sanitize_name().
>
> Signed-off-by: Michael Walle <[email protected]>
> Acked-by: Xu Yilun <[email protected]>
> ---
> drivers/hwmon/intel-m10-bmc-hwmon.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/hwmon/intel-m10-bmc-hwmon.c b/drivers/hwmon/intel-m10-bmc-hwmon.c
> index 7a08e4c44a4b..6e82f7200d1c 100644
> --- a/drivers/hwmon/intel-m10-bmc-hwmon.c
> +++ b/drivers/hwmon/intel-m10-bmc-hwmon.c
> @@ -515,7 +515,6 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev)
> struct intel_m10bmc *m10bmc = dev_get_drvdata(pdev->dev.parent);
> struct device *hwmon_dev, *dev = &pdev->dev;
> struct m10bmc_hwmon *hw;
> - int i;
>
> hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
> if (!hw)
> @@ -528,13 +527,9 @@ static int m10bmc_hwmon_probe(struct platform_device *pdev)
> hw->chip.info = hw->bdata->hinfo;
> hw->chip.ops = &m10bmc_hwmon_ops;
>
> - hw->hw_name = devm_kstrdup(dev, id->name, GFP_KERNEL);
> - if (!hw->hw_name)
> - return -ENOMEM;
> -
> - for (i = 0; hw->hw_name[i]; i++)
> - if (hwmon_is_bad_char(hw->hw_name[i]))
> - hw->hw_name[i] = '_';
> + hw->hw_name = devm_hwmon_sanitize_name(dev, id->name);
> + if (IS_ERR(hw->hw_name))
> + return PTR_ERR(hw->hw_name);
Reviewed-by: Tom Rix <[email protected]>
>
> hwmon_dev = devm_hwmon_device_register_with_info(dev, hw->hw_name,
> hw, &hw->chip, NULL);

2022-04-12 07:20:31

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] hwmon: intel-m10-bmc-hwmon: use devm_hwmon_sanitize_name()

On Tue, Apr 05, 2022 at 11:24:52AM +0200, Michael Walle wrote:
> Instead of open-coding the bad characters replacement in the hwmon name,
> use the new devm_hwmon_sanitize_name().
>
> Signed-off-by: Michael Walle <[email protected]>
> Acked-by: Xu Yilun <[email protected]>
> Reviewed-by: Tom Rix <[email protected]>

Applied.

Thanks,
Guenter