diff mbox series

[net-next,2/2] net: phy: aquantia: use new function strreplace_nonalnum

Message ID 42f2e064-181c-087e-68b1-64d2d6f13e0e@gmail.com
State Deferred
Delegated to: David Miller
Headers show
Series lib: string: add strreplace_nonalnum | expand

Commit Message

Heiner Kallweit March 3, 2019, 5:21 p.m. UTC
Use new function strreplace_nonalnum to simplify the code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/aquantia_hwmon.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

Comments

Andrew Lunn March 3, 2019, 5:31 p.m. UTC | #1
On Sun, Mar 03, 2019 at 06:21:53PM +0100, Heiner Kallweit wrote:
> Use new function strreplace_nonalnum to simplify the code.

Hi Heiner

Both Marvell PHY drivers could use this.

sfp.c has a variant of this as well.

     Andrew
Heiner Kallweit March 3, 2019, 5:41 p.m. UTC | #2
On 03.03.2019 18:31, Andrew Lunn wrote:
> On Sun, Mar 03, 2019 at 06:21:53PM +0100, Heiner Kallweit wrote:
>> Use new function strreplace_nonalnum to simplify the code.
> 
> Hi Heiner
> 
> Both Marvell PHY drivers could use this.
> 
> sfp.c has a variant of this as well.
> 
Thanks! My plan was to provide a first user so that the new
function gets accepted, and then look for more places where it
could be used. Most likely there are few HWMON drivers also
open-coding this functionality.

>      Andrew
> 
Heiner
diff mbox series

Patch

diff --git a/drivers/net/phy/aquantia_hwmon.c b/drivers/net/phy/aquantia_hwmon.c
index 19c4c280a..d47b3ed16 100644
--- a/drivers/net/phy/aquantia_hwmon.c
+++ b/drivers/net/phy/aquantia_hwmon.c
@@ -226,20 +226,12 @@  int aqr_hwmon_probe(struct phy_device *phydev)
 	struct device *dev = &phydev->mdio.dev;
 	struct device *hwmon_dev;
 	char *hwmon_name;
-	int i, j;
 
 	hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
 	if (!hwmon_name)
 		return -ENOMEM;
 
-	for (i = j = 0; hwmon_name[i]; i++) {
-		if (isalnum(hwmon_name[i])) {
-			if (i != j)
-				hwmon_name[j] = hwmon_name[i];
-			j++;
-		}
-	}
-	hwmon_name[j] = '\0';
+	strreplace_nonalnum(hwmon_name, 0);
 
 	hwmon_dev = devm_hwmon_device_register_with_info(dev, hwmon_name,
 					phydev, &aqr_hwmon_chip_info, NULL);