2022-03-28 18:06:06

by Michael Walle

[permalink] [raw]
Subject: [PATCH v1 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.

I'm not sure how to handle this correctly, as this touches both the
network tree and the hwmon tree. Also, the GPY PHY temperature senors
driver would use it.

Michael Walle (2):
hwmon: introduce hwmon_sanitize_name()
net: phy: use hwmon_sanitize_name()

drivers/hwmon/intel-m10-bmc-hwmon.c | 5 +----
drivers/net/phy/nxp-tja11xx.c | 5 +----
drivers/net/phy/sfp.c | 6 ++----
include/linux/hwmon.h | 16 ++++++++++++++++
4 files changed, 20 insertions(+), 12 deletions(-)

--
2.30.2


2022-03-28 19:54:18

by Andrew Lunn

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

> I'm not sure how to handle this correctly, as this touches both the
> network tree and the hwmon tree. Also, the GPY PHY temperature senors
> driver would use it.

There are a few options:

1) Get the hwmon_sanitize_name() merged into hwmon, ask for a stable
branch, and get it merged into netdev net-next.

2) Have the hwmon maintainers ACK the change and agree that it can be
merged via netdev.

Probably the second option is easiest, and since it is not touching
the core of hwmon, it is unlikely to cause merge conflicts.

Andrew

2022-03-28 21:16:00

by Guenter Roeck

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

On 3/28/22 05:56, Andrew Lunn wrote:
>> I'm not sure how to handle this correctly, as this touches both the
>> network tree and the hwmon tree. Also, the GPY PHY temperature senors
>> driver would use it.
>
> There are a few options:
>
> 1) Get the hwmon_sanitize_name() merged into hwmon, ask for a stable
> branch, and get it merged into netdev net-next.
>
> 2) Have the hwmon maintainers ACK the change and agree that it can be
> merged via netdev.
>
> Probably the second option is easiest, and since it is not touching
> the core of hwmon, it is unlikely to cause merge conflicts.
>

No, it isn't the easiest solution because it also modifies a hwmon
driver to use it.

Guenter

2022-03-28 21:17:52

by Michael Walle

[permalink] [raw]
Subject: [PATCH v1 2/2] net: phy: use hwmon_sanitize_name()

Instead of open-coding it, use the new hwmon_sanitize_name() in th
nxp-tja11xx and sfp driver.

Signed-off-by: Michael Walle <[email protected]>
---
drivers/net/phy/nxp-tja11xx.c | 5 +----
drivers/net/phy/sfp.c | 6 ++----
2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index 9944cc501806..3973aa1b90dc 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -444,15 +444,12 @@ static int tja11xx_hwmon_register(struct phy_device *phydev,
struct tja11xx_priv *priv)
{
struct device *dev = &phydev->mdio.dev;
- int i;

priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
if (!priv->hwmon_name)
return -ENOMEM;

- for (i = 0; priv->hwmon_name[i]; i++)
- if (hwmon_is_bad_char(priv->hwmon_name[i]))
- priv->hwmon_name[i] = '_';
+ hwmon_sanitize_name(priv->hwmon_name);

priv->hwmon_dev =
devm_hwmon_device_register_with_info(dev, priv->hwmon_name,
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 4dfb79807823..35a4641303eb 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -1289,7 +1289,7 @@ static const struct hwmon_chip_info sfp_hwmon_chip_info = {
static void sfp_hwmon_probe(struct work_struct *work)
{
struct sfp *sfp = container_of(work, struct sfp, hwmon_probe.work);
- int err, i;
+ int err;

/* hwmon interface needs to access 16bit registers in atomic way to
* guarantee coherency of the diagnostic monitoring data. If it is not
@@ -1323,9 +1323,7 @@ static void sfp_hwmon_probe(struct work_struct *work)
return;
}

- for (i = 0; sfp->hwmon_name[i]; i++)
- if (hwmon_is_bad_char(sfp->hwmon_name[i]))
- sfp->hwmon_name[i] = '_';
+ hwmon_sanitize_name(sfp->hwmon_name);

sfp->hwmon_dev = hwmon_device_register_with_info(sfp->dev,
sfp->hwmon_name, sfp,
--
2.30.2

2022-03-28 23:27:17

by Michael Walle

[permalink] [raw]
Subject: Re: [PATCH v1 2/2] net: phy: use hwmon_sanitize_name()

Am 2022-03-28 13:52, schrieb Michael Walle:
> Instead of open-coding it, use the new hwmon_sanitize_name() in th

s/th/the/ btw, will be fixed in the next version.

> nxp-tja11xx and sfp driver.
>
> Signed-off-by: Michael Walle <[email protected]>
> ---
> drivers/net/phy/nxp-tja11xx.c | 5 +----
> drivers/net/phy/sfp.c | 6 ++----

Andrew, do you also prefer two seperate patches?

-michael

2022-03-28 23:29:58

by Michael Walle

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

Am 2022-03-28 18:27, schrieb Guenter Roeck:
> On 3/28/22 05:56, Andrew Lunn wrote:
>>> I'm not sure how to handle this correctly, as this touches both the
>>> network tree and the hwmon tree. Also, the GPY PHY temperature senors
>>> driver would use it.
>>
>> There are a few options:
>>
>> 1) Get the hwmon_sanitize_name() merged into hwmon, ask for a stable
>> branch, and get it merged into netdev net-next.
>>
>> 2) Have the hwmon maintainers ACK the change and agree that it can be
>> merged via netdev.
>>
>> Probably the second option is easiest, and since it is not touching
>> the core of hwmon, it is unlikely to cause merge conflicts.
>>
>
> No, it isn't the easiest solution because it also modifies a hwmon
> driver to use it.

So that leaves us with option 1? The next version will contain the
additional patch which moves the hwmon_is_bad_char() from the include
to the core and make it private. That will then need an immutable
branch from netdev to get merged back into hwmon before that patch
can be applied, right?

-michael

2022-03-28 23:35:41

by Jakub Kicinski

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

On Tue, 29 Mar 2022 00:50:28 +0200 Michael Walle wrote:
> > No, it isn't the easiest solution because it also modifies a hwmon
> > driver to use it.
>
> So that leaves us with option 1? The next version will contain the
> additional patch which moves the hwmon_is_bad_char() from the include
> to the core and make it private. That will then need an immutable
> branch from netdev to get merged back into hwmon before that patch
> can be applied, right?

If anything immutable branch from hwmon that we can pull, because hwmon
is the home of the API, and netdev is just _a_ consumer.

Either way I think you can post the patch that adds the new helper
for review.

2022-03-30 12:09:48

by Guenter Roeck

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

On 3/28/22 15:50, Michael Walle wrote:
> Am 2022-03-28 18:27, schrieb Guenter Roeck:
>> On 3/28/22 05:56, Andrew Lunn wrote:
>>>> I'm not sure how to handle this correctly, as this touches both the
>>>> network tree and the hwmon tree. Also, the GPY PHY temperature senors
>>>> driver would use it.
>>>
>>> There are a few options:
>>>
>>> 1) Get the hwmon_sanitize_name() merged into hwmon, ask for a stable
>>> branch, and get it merged into netdev net-next.
>>>
>>> 2) Have the hwmon maintainers ACK the change and agree that it can be
>>> merged via netdev.
>>>
>>> Probably the second option is easiest, and since it is not touching
>>> the core of hwmon, it is unlikely to cause merge conflicts.
>>>
>>
>> No, it isn't the easiest solution because it also modifies a hwmon
>> driver to use it.
>
> So that leaves us with option 1? The next version will contain the
> additional patch which moves the hwmon_is_bad_char() from the include
> to the core and make it private. That will then need an immutable
> branch from netdev to get merged back into hwmon before that patch
> can be applied, right?

We can not control if someone else starts using the function before
it is removed. As pointed out, the immutable branch needs to be from hwmon,
and the patch to make hwmon_is_bad_char private can only be applied
after all of its users are gone from the mainline kernel.

I would actually suggest to allocate the new string as part of the
function and have it return a pointer to a new string. Something like
char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
and
char *hwmon_sanitize_name(const char *name);

because the string duplication is also part of all calling code.

Guenter