Skip to contentSkip to conversation

Fix some non-NULL terminated strings in the networking subsystem

PATCH In review Vladimir Oltean 2 participants 49 messages Sep 27, 2021 – Sep 28, 2021

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Fix some non-NULL terminated strings in the networking subsystem

This series is the result of a small patching spree, which started off by noticing some truncation that might take place when setting the MDIO bus name in one driver, and then looked at what other drivers do, and then.....

Vladimir Oltean (25):
arch: powerpc: mpc85xx: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
board: gdsys: a38x: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: armada100_fec: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: at91_emac: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: bcm-sf2: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: eepro100: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: ep93xx: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN
truncation
net: mcdmafec: ensure bus->name is NULL terminated after MDIO_NAME_LEN
truncation
net: ftmac110: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: lpc32xx: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: macb: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN
truncation
net: mpc8xx_fec: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: dsa: felix: ensure mii_bus->name is NULL terminated after
MDIO_NAME_LEN truncation
net: mvgbe: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: sh_eth: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: smc911x: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: davinci_emac: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: qe: uec: ensure mdiodev->name is NULL terminated after
MDIO_NAME_LEN truncation
net: mdio-uclass: rewrite dm_mdio_post_probe using strlcpy
scripts: ensure the cocci script for miiphy_register does not leave
NULL-unterminated strings
net: dsa: felix: check return code of mdio_alloc and mdio_register
net: dsa: ensure port names are NULL-terminated after
DSA_PORT_NAME_LENGTH truncation
arch: powerpc: mpc85xx: free MDIO bus if mdio_register fails
scripts: ensure the cocci script for miiphy_register does not leak the
MDIO bus

 arch/powerpc/cpu/mpc85xx/ether_fcc.c       |  6 ++++--
 board/gdsys/a38x/ihs_phys.c                |  4 +---
 drivers/net/armada100_fec.c                |  2 +-
 drivers/net/at91_emac.c                    |  2 +-
 drivers/net/bcm-sf2-eth.c                  |  2 +-
 drivers/net/eepro100.c                     |  2 +-
 drivers/net/ep93xx_eth.c                   |  2 +-
 drivers/net/fsl_enetc.c                    |  2 +-
 drivers/net/fsl_mcdmafec.c                 |  2 +-
 drivers/net/ftmac110.c                     |  2 +-
 drivers/net/lpc32xx_eth.c                  |  2 +-
 drivers/net/macb.c                         |  4 ++--
 drivers/net/mpc8xx_fec.c                   |  2 +-
 drivers/net/mscc_eswitch/felix_switch.c    | 14 +++++++++++---
 drivers/net/mvgbe.c                        |  2 +-
 drivers/net/sh_eth.c                       |  2 +-
 drivers/net/smc911x.c                      |  2 +-
 drivers/net/ti/davinci_emac.c              |  2 +-
 drivers/qe/uec.c                           |  2 +-
 net/dsa-uclass.c                           |  4 ++--
 net/mdio-uclass.c                          |  2 +-
 scripts/coccinelle/net/mdio_register.cocci |  4 ++--
 22 files changed, 38 insertions(+), 30 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/25 arch: powerpc: mpc85xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 arch/powerpc/cpu/mpc85xx/ether_fcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/ether_fcc.c +1 -1
index 3c4eb1a7eba9..1f6f55707321 100644
@@ -444,7 +444,7 @@ int fec_initialize(struct bd_info *bis)
 		struct mii_dev *mdiodev = mdio_alloc();
 		if (!mdiodev)
 			return -ENOMEM;
-		strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+		strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 		mdiodev->read = bb_miiphy_read;
 		mdiodev->write = bb_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/25
#2 lore raw

Re: [PATCH 01/25] arch: powerpc: mpc85xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 arch/powerpc/cpu/mpc85xx/ether_fcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/ether_fcc.c +1 -2
index 3c4eb1a7eba9..1f6f55707321 100644
@@ -444,7 +444,7 @@ int fec_initialize(struct bd_info *bis)
                struct mii_dev *mdiodev = mdio_alloc();
                if (!mdiodev)
                        return -ENOMEM;
-               strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+               strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
                mdiodev->read = bb_miiphy_read;
                mdiodev->write = bb_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#3 lore raw

PATCH 2/25 board: gdsys: a38x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 board/gdsys/a38x/ihs_phys.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
board/gdsys/a38x/ihs_phys.c +1 -3
index c23d15092144..e09c0006b76f 100644
@@ -110,9 +110,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus)
 
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name,
-		name,
-		MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, name, MDIO_NAME_LEN);
 	mdiodev->read = bb_miiphy_read;
 	mdiodev->write = bb_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 2/25
#4 lore raw

Re: [PATCH 02/25] board: gdsys: a38x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 36 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 board/gdsys/a38x/ihs_phys.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
board/gdsys/a38x/ihs_phys.c +1 -4
index c23d15092144..e09c0006b76f 100644
@@ -110,9 +110,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus)
 
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name,
-               name,
-               MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, name, MDIO_NAME_LEN);
        mdiodev->read = bb_miiphy_read;
        mdiodev->write = bb_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#5 lore raw

PATCH 3/25 net: armada100_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/armada100_fec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/armada100_fec.c +1 -1
index 018891e173c3..5d4b90c6ba72 100644
@@ -717,7 +717,7 @@ int armada100_fec_register(unsigned long base_addr)
 	struct mii_dev *mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = smi_reg_read;
 	mdiodev->write = smi_reg_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 3/25
#6 lore raw

Re: [PATCH 03/25] net: armada100_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/armada100_fec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/armada100_fec.c +1 -2
index 018891e173c3..5d4b90c6ba72 100644
@@ -717,7 +717,7 @@ int armada100_fec_register(unsigned long base_addr)
        struct mii_dev *mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = smi_reg_read;
        mdiodev->write = smi_reg_write;
 
--
Quoted 2 lines

2.25.1

#7 lore raw

PATCH 4/25 net: at91_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/at91_emac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/at91_emac.c +1 -1
index e40b94ad892d..b4581d8c9320 100644
@@ -507,7 +507,7 @@ int at91emac_register(struct bd_info *bis, unsigned long iobase)
 	struct mii_dev *mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = at91emac_mii_read;
 	mdiodev->write = at91emac_mii_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 4/25
#8 lore raw

Re: [PATCH 04/25] net: at91_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/at91_emac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/at91_emac.c +1 -2
index e40b94ad892d..b4581d8c9320 100644
@@ -507,7 +507,7 @@ int at91emac_register(struct bd_info *bis, unsigned long iobase)
        struct mii_dev *mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = at91emac_mii_read;
        mdiodev->write = at91emac_mii_write;
 
--
Quoted 2 lines

2.25.1

#9 lore raw

PATCH 5/25 net: bcm-sf2: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/bcm-sf2-eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bcm-sf2-eth.c +1 -1
index c862c141461c..88dc3ab38466 100644
@@ -250,7 +250,7 @@ int bcm_sf2_eth_register(struct bd_info *bis, u8 dev_num)
 
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = eth->miiphy_read;
 	mdiodev->write = eth->miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 5/25
#10 lore raw

Re: [PATCH 05/25] net: bcm-sf2: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/bcm-sf2-eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bcm-sf2-eth.c +1 -2
index c862c141461c..88dc3ab38466 100644
@@ -250,7 +250,7 @@ int bcm_sf2_eth_register(struct bd_info *bis, u8 dev_num)
 
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = eth->miiphy_read;
        mdiodev->write = eth->miiphy_write;
 
--
Quoted 2 lines

2.25.1

#11 lore raw

PATCH 6/25 net: eepro100: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/eepro100.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eepro100.c +1 -1
index 934b881219e9..935cd9c99cef 100644
@@ -493,7 +493,7 @@ static int eepro100_initialize_mii(struct eepro100_priv *priv)
 	if (!mdiodev)
 		return -ENOMEM;
 
-	strncpy(mdiodev->name, priv->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, priv->name, MDIO_NAME_LEN);
 	mdiodev->read = eepro100_miiphy_read;
 	mdiodev->write = eepro100_miiphy_write;
 	mdiodev->priv = priv;
Signature · 1 line
2.25.1
Reviewed-by on v1 6/25
#12 lore raw

Re: [PATCH 06/25] net: eepro100: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/eepro100.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/eepro100.c +1 -2
index 934b881219e9..935cd9c99cef 100644
@@ -493,7 +493,7 @@ static int eepro100_initialize_mii(struct eepro100_priv *priv)
        if (!mdiodev)
                return -ENOMEM;
 
-       strncpy(mdiodev->name, priv->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, priv->name, MDIO_NAME_LEN);
        mdiodev->read = eepro100_miiphy_read;
        mdiodev->write = eepro100_miiphy_write;
        mdiodev->priv = priv;
--
Quoted 2 lines

2.25.1

#13 lore raw

PATCH 7/25 net: ep93xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/ep93xx_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ep93xx_eth.c +1 -1
index 0218349b0450..9f8df7de0609 100644
@@ -427,7 +427,7 @@ int ep93xx_miiphy_initialize(struct bd_info * const bd)
 	struct mii_dev *mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN);
 	mdiodev->read = ep93xx_miiphy_read;
 	mdiodev->write = ep93xx_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 7/25
#14 lore raw

Re: [PATCH 07/25] net: ep93xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/ep93xx_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ep93xx_eth.c +1 -2
index 0218349b0450..9f8df7de0609 100644
@@ -427,7 +427,7 @@ int ep93xx_miiphy_initialize(struct bd_info * const bd)
        struct mii_dev *mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN);
        mdiodev->read = ep93xx_miiphy_read;
        mdiodev->write = ep93xx_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#15 lore raw

PATCH 8/25 net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/fsl_enetc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fsl_enetc.c +1 -1
index 566cdc7e546a..b7e2c1f0880c 100644
@@ -270,7 +270,7 @@ static void enetc_start_pcs(struct udevice *dev)
 		priv->imdio.read = enetc_mdio_read;
 		priv->imdio.write = enetc_mdio_write;
 		priv->imdio.priv = priv->port_regs + ENETC_PM_IMDIO_BASE;
-		strncpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
+		strlcpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
 		if (!miiphy_get_dev_by_name(priv->imdio.name))
 			mdio_register(&priv->imdio);
 	}
Signature · 1 line
2.25.1
Reviewed-by on v1 8/25
#16 lore raw

Re: [PATCH 08/25] net: enetc: ensure imdio.name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/fsl_enetc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fsl_enetc.c +1 -2
index 566cdc7e546a..b7e2c1f0880c 100644
@@ -270,7 +270,7 @@ static void enetc_start_pcs(struct udevice *dev)
                priv->imdio.read = enetc_mdio_read;
                priv->imdio.write = enetc_mdio_write;
                priv->imdio.priv = priv->port_regs + ENETC_PM_IMDIO_BASE;
-               strncpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
+               strlcpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
                if (!miiphy_get_dev_by_name(priv->imdio.name))
                        mdio_register(&priv->imdio);
        }
--
Quoted 2 lines

2.25.1

#17 lore raw

PATCH 9/25 net: mcdmafec: ensure bus->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/fsl_mcdmafec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fsl_mcdmafec.c +1 -1
index c20aef4ab28d..e103f79305e7 100644
@@ -541,7 +541,7 @@ static int mcdmafec_probe(struct udevice *dev)
 	info->bus = mdio_alloc();
 	if (!info->bus)
 		return -ENOMEM;
-	strncpy(info->bus->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(info->bus->name, dev->name, MDIO_NAME_LEN);
 	info->bus->read = mcffec_miiphy_read;
 	info->bus->write = mcffec_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 9/25
#18 lore raw

Re: [PATCH 09/25] net: mcdmafec: ensure bus->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/fsl_mcdmafec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/fsl_mcdmafec.c +1 -2
index c20aef4ab28d..e103f79305e7 100644
@@ -541,7 +541,7 @@ static int mcdmafec_probe(struct udevice *dev)
        info->bus = mdio_alloc();
        if (!info->bus)
                return -ENOMEM;
-       strncpy(info->bus->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(info->bus->name, dev->name, MDIO_NAME_LEN);
        info->bus->read = mcffec_miiphy_read;
        info->bus->write = mcffec_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#19 lore raw

PATCH 10/25 net: ftmac110: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/ftmac110.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ftmac110.c +1 -1
index 265d813c4f89..7e54d4642ddf 100644
@@ -476,7 +476,7 @@ int ftmac110_initialize(struct bd_info *bis)
 	struct mii_dev *mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = ftmac110_mdio_read;
 	mdiodev->write = ftmac110_mdio_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 10/25
#20 lore raw

Re: [PATCH 10/25] net: ftmac110: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/ftmac110.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ftmac110.c +1 -2
index 265d813c4f89..7e54d4642ddf 100644
@@ -476,7 +476,7 @@ int ftmac110_initialize(struct bd_info *bis)
        struct mii_dev *mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = ftmac110_mdio_read;
        mdiodev->write = ftmac110_mdio_write;
 
--
Quoted 2 lines

2.25.1

#21 lore raw

PATCH 11/25 net: lpc32xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/lpc32xx_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/lpc32xx_eth.c +1 -1
index 3f281a515c6a..1a5734343935 100644
@@ -638,7 +638,7 @@ int lpc32xx_eth_initialize(struct bd_info *bis)
 	struct mii_dev *mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = mii_reg_read;
 	mdiodev->write = mii_reg_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 11/25
#22 lore raw

Re: [PATCH 11/25] net: lpc32xx: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/lpc32xx_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/lpc32xx_eth.c +1 -2
index 3f281a515c6a..1a5734343935 100644
@@ -638,7 +638,7 @@ int lpc32xx_eth_initialize(struct bd_info *bis)
        struct mii_dev *mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = mii_reg_read;
        mdiodev->write = mii_reg_write;
 
--
Quoted 2 lines

2.25.1

#23 lore raw

PATCH 12/25 net: macb: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/macb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/macb.c +2 -2
index 57ea45e2dc7f..8151104acfc0 100644
@@ -1245,7 +1245,7 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
 	struct mii_dev *mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, netdev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, netdev->name, MDIO_NAME_LEN);
 	mdiodev->read = macb_miiphy_read;
 	mdiodev->write = macb_miiphy_write;
 
@@ -1403,7 +1403,7 @@ static int macb_eth_probe(struct udevice *dev)
 	macb->bus = mdio_alloc();
 	if (!macb->bus)
 		return -ENOMEM;
-	strncpy(macb->bus->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(macb->bus->name, dev->name, MDIO_NAME_LEN);
 	macb->bus->read = macb_miiphy_read;
 	macb->bus->write = macb_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 12/25
#24 lore raw

Re: [PATCH 12/25] net: macb: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 43 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/macb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/macb.c +2 -3
index 57ea45e2dc7f..8151104acfc0 100644
@@ -1245,7 +1245,7 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
        struct mii_dev *mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, netdev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, netdev->name, MDIO_NAME_LEN);
        mdiodev->read = macb_miiphy_read;
        mdiodev->write = macb_miiphy_write;
 
@@ -1403,7 +1403,7 @@ static int macb_eth_probe(struct udevice *dev)
        macb->bus = mdio_alloc();
        if (!macb->bus)
                return -ENOMEM;
-       strncpy(macb->bus->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(macb->bus->name, dev->name, MDIO_NAME_LEN);
        macb->bus->read = macb_miiphy_read;
        macb->bus->write = macb_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#25 lore raw

PATCH 13/25 net: mpc8xx_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/mpc8xx_fec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mpc8xx_fec.c +1 -1
index 282c2599d3c4..4eb826028111 100644
@@ -160,7 +160,7 @@ int fec_initialize(struct bd_info *bis)
 		struct mii_dev *mdiodev = mdio_alloc();
 		if (!mdiodev)
 			return -ENOMEM;
-		strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+		strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 		mdiodev->read = fec8xx_miiphy_read;
 		mdiodev->write = fec8xx_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 13/25
#26 lore raw

Re: [PATCH 13/25] net: mpc8xx_fec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/mpc8xx_fec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mpc8xx_fec.c +1 -2
index 282c2599d3c4..4eb826028111 100644
@@ -160,7 +160,7 @@ int fec_initialize(struct bd_info *bis)
                struct mii_dev *mdiodev = mdio_alloc();
                if (!mdiodev)
                        return -ENOMEM;
-               strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+               strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
                mdiodev->read = fec8xx_miiphy_read;
                mdiodev->write = fec8xx_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#27 lore raw

PATCH 14/25 net: dsa: felix: ensure mii_bus->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/mscc_eswitch/felix_switch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mscc_eswitch/felix_switch.c +2 -2
index 6aa79784460d..4c2e57755967 100644
@@ -258,7 +258,7 @@ static void felix_init(struct udevice *dev)
 	priv->imdio.read = felix_mdio_read;
 	priv->imdio.write = felix_mdio_write;
 	priv->imdio.priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
-	strncpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
+	strlcpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
 
 	/* set up CPU port */
 	out_le32(base + FELIX_QSYS_SYSTEM_EXT_CPU_CFG,
@@ -303,7 +303,7 @@ static int felix_probe(struct udevice *dev)
 		mii_bus->read = felix_mdio_read;
 		mii_bus->write = felix_mdio_write;
 		mii_bus->priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
-		strncpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
+		strlcpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
 		mdio_register(mii_bus);
 	}
 
Signature · 1 line
2.25.1
Reviewed-by on v1 14/25
#28 lore raw

Re: [PATCH 14/25] net: dsa: felix: ensure mii_bus->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 43 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/mscc_eswitch/felix_switch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mscc_eswitch/felix_switch.c +2 -3
index 6aa79784460d..4c2e57755967 100644
@@ -258,7 +258,7 @@ static void felix_init(struct udevice *dev)
        priv->imdio.read = felix_mdio_read;
        priv->imdio.write = felix_mdio_write;
        priv->imdio.priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
-       strncpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
+       strlcpy(priv->imdio.name, dev->name, MDIO_NAME_LEN);
 
        /* set up CPU port */
        out_le32(base + FELIX_QSYS_SYSTEM_EXT_CPU_CFG,
@@ -303,7 +303,7 @@ static int felix_probe(struct udevice *dev)
                mii_bus->read = felix_mdio_read;
                mii_bus->write = felix_mdio_write;
                mii_bus->priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
-               strncpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
+               strlcpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
                mdio_register(mii_bus);
        }
 
--
Quoted 2 lines

2.25.1

#29 lore raw

PATCH 15/25 net: mvgbe: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/mvgbe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvgbe.c +1 -1
index ce5b8eed64b4..954bf86121a4 100644
@@ -883,7 +883,7 @@ int mvgbe_initialize(struct bd_info *bis)
 		struct mii_dev *mdiodev = mdio_alloc();
 		if (!mdiodev)
 			return -ENOMEM;
-		strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+		strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 		mdiodev->read = smi_reg_read;
 		mdiodev->write = smi_reg_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 15/25
#30 lore raw

Re: [PATCH 15/25] net: mvgbe: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/mvgbe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvgbe.c +1 -2
index ce5b8eed64b4..954bf86121a4 100644
@@ -883,7 +883,7 @@ int mvgbe_initialize(struct bd_info *bis)
                struct mii_dev *mdiodev = mdio_alloc();
                if (!mdiodev)
                        return -ENOMEM;
-               strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+               strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
                mdiodev->read = smi_reg_read;
                mdiodev->write = smi_reg_write;
 
--
Quoted 2 lines

2.25.1

#31 lore raw

PATCH 16/25 net: sh_eth: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/sh_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/sh_eth.c +1 -1
index 3143a5813a6d..4055f07b2feb 100644
@@ -657,7 +657,7 @@ int sh_eth_initialize(struct bd_info *bd)
 	mdiodev = mdio_alloc();
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = bb_miiphy_read;
 	mdiodev->write = bb_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 16/25
#32 lore raw

Re: [PATCH 16/25] net: sh_eth: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/sh_eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/sh_eth.c +1 -2
index 3143a5813a6d..4055f07b2feb 100644
@@ -657,7 +657,7 @@ int sh_eth_initialize(struct bd_info *bd)
        mdiodev = mdio_alloc();
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = bb_miiphy_read;
        mdiodev->write = bb_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#33 lore raw

PATCH 17/25 net: smc911x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/smc911x.c +1 -1
index 8f420261fa8d..5d9a73f23d75 100644
@@ -425,7 +425,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv)
 	if (!mdiodev)
 		return -ENOMEM;
 
-	strncpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN);
 	mdiodev->read = smc911x_miiphy_read;
 	mdiodev->write = smc911x_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 17/25
#34 lore raw

Re: [PATCH 17/25] net: smc911x: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/smc911x.c +1 -2
index 8f420261fa8d..5d9a73f23d75 100644
@@ -425,7 +425,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv)
        if (!mdiodev)
                return -ENOMEM;
 
-       strncpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN);
        mdiodev->read = smc911x_miiphy_read;
        mdiodev->write = smc911x_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#35 lore raw

PATCH 18/25 net: davinci_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/ti/davinci_emac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ti/davinci_emac.c +1 -1
index bfe1b84cd566..2dfadbd82d5b 100644
@@ -816,7 +816,7 @@ static int davinci_emac_probe(struct udevice *dev)
 		struct mii_dev *mdiodev = mdio_alloc();
 		if (!mdiodev)
 			return -ENOMEM;
-		strncpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN);
+		strlcpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN);
 		mdiodev->read = davinci_mii_phy_read;
 		mdiodev->write = davinci_mii_phy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 18/25
#36 lore raw

Re: [PATCH 18/25] net: davinci_emac: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/net/ti/davinci_emac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ti/davinci_emac.c +1 -2
index bfe1b84cd566..2dfadbd82d5b 100644
@@ -816,7 +816,7 @@ static int davinci_emac_probe(struct udevice *dev)
                struct mii_dev *mdiodev = mdio_alloc();
                if (!mdiodev)
                        return -ENOMEM;
-               strncpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN);
+               strlcpy(mdiodev->name, phy[i].name, MDIO_NAME_LEN);
                mdiodev->read = davinci_mii_phy_read;
                mdiodev->write = davinci_mii_phy_write;
 
--
Quoted 2 lines

2.25.1

#37 lore raw

PATCH 19/25 net: qe: uec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/qe/uec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/qe/uec.c +1 -1
index 5da971ddc0af..c4bd5c4a147f 100644
@@ -1407,7 +1407,7 @@ int uec_initialize(struct bd_info *bis, struct uec_inf *uec_info)
 
 	if (!mdiodev)
 		return -ENOMEM;
-	strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+	strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
 	mdiodev->read = uec_miiphy_read;
 	mdiodev->write = uec_miiphy_write;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 19/25
#38 lore raw

Re: [PATCH 19/25] net: qe: uec: ensure mdiodev->name is NULL terminated after MDIO_NAME_LEN truncation

Quoted 34 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 drivers/qe/uec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/qe/uec.c +1 -2
index 5da971ddc0af..c4bd5c4a147f 100644
@@ -1407,7 +1407,7 @@ int uec_initialize(struct bd_info *bis, struct uec_inf *uec_info)
 
        if (!mdiodev)
                return -ENOMEM;
-       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
        mdiodev->read = uec_miiphy_read;
        mdiodev->write = uec_miiphy_write;
 
--
Quoted 2 lines

2.25.1

#39 lore raw

PATCH 20/25 net: mdio-uclass: rewrite dm_mdio_post_probe using strlcpy

In reply to Vladimir Oltean

dm_mdio_post_probe used to be vulnerable after truncation, but has been patched by commit 398e7512d8d7 ("net: Fix Covarity Defect 244093"). Nonetheless, we can use strlcpy like the rest of the code base now, which yields the same result.

---
 net/mdio-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mdio-uclass.c +1 -1
index 1b687765b8ca..e74e34f78f9c 100644
@@ -101,7 +101,7 @@ static int dm_mdio_post_probe(struct udevice *dev)
 	pdata->mii_bus->write = mdio_write;
 	pdata->mii_bus->reset = mdio_reset;
 	pdata->mii_bus->priv = dev;
-	strncpy(pdata->mii_bus->name, dev->name, MDIO_NAME_LEN - 1);
+	strlcpy(pdata->mii_bus->name, dev->name, MDIO_NAME_LEN);
 
 	return mdio_register(pdata->mii_bus);
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 20/25
#40 lore raw

Re: [PATCH 20/25] net: mdio-uclass: rewrite dm_mdio_post_probe using strlcpy

Quoted 25 lines · Vladimir Oltean

dm_mdio_post_probe used to be vulnerable after truncation, but has been patched by commit 398e7512d8d7 ("net: Fix Covarity Defect 244093"). Nonetheless, we can use strlcpy like the rest of the code base now, which yields the same result.

---
 net/mdio-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mdio-uclass.c +1 -2
index 1b687765b8ca..e74e34f78f9c 100644
@@ -101,7 +101,7 @@ static int dm_mdio_post_probe(struct udevice *dev)
        pdata->mii_bus->write = mdio_write;
        pdata->mii_bus->reset = mdio_reset;
        pdata->mii_bus->priv = dev;
-       strncpy(pdata->mii_bus->name, dev->name, MDIO_NAME_LEN - 1);
+       strlcpy(pdata->mii_bus->name, dev->name, MDIO_NAME_LEN);
 
        return mdio_register(pdata->mii_bus);
 }
--
Quoted 2 lines

2.25.1

#41 lore raw

PATCH 21/25 scripts: ensure the cocci script for miiphy_register does not leave NULL-unterminated strings

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass MDIO_NAME_LEN - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 scripts/coccinelle/net/mdio_register.cocci | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/net/mdio_register.cocci +1 -1
index 100f10293610..31a40360f99e 100644
@@ -16,7 +16,7 @@ identifier readfunc, writefunc;
 - miiphy_register(devname, readfunc, writefunc);
 + struct mii_dev *mdiodev = mdio_alloc();
 + if (!mdiodev) return -ENOMEM;
-+ strncpy(mdiodev->name, devname, MDIO_NAME_LEN);
++ strlcpy(mdiodev->name, devname, MDIO_NAME_LEN);
 + mdiodev->read = readfunc;
 + mdiodev->write = writefunc;
 + 
Signature · 1 line
2.25.1
#42 lore raw

PATCH 22/25 net: dsa: felix: check return code of mdio_alloc and mdio_register

In reply to Vladimir Oltean

These functions can return errors, it's best to catch them and trigger the driver unwind code path.

---
 drivers/net/mscc_eswitch/felix_switch.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/mscc_eswitch/felix_switch.c +9 -1
index 4c2e57755967..98ae39e81d65 100644
@@ -276,6 +276,7 @@ static void felix_init(struct udevice *dev)
 static int felix_probe(struct udevice *dev)
 {
 	struct felix_priv *priv = dev_get_priv(dev);
+	int err;
 
 	if (ofnode_valid(dev_ofnode(dev)) &&
 	    !ofnode_is_available(dev_ofnode(dev))) {
@@ -300,11 +301,18 @@ static int felix_probe(struct udevice *dev)
 		struct mii_dev *mii_bus;
 
 		mii_bus = mdio_alloc();
+		if (!mii_bus)
+			return -ENOMEM;
+
 		mii_bus->read = felix_mdio_read;
 		mii_bus->write = felix_mdio_write;
 		mii_bus->priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
 		strlcpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
-		mdio_register(mii_bus);
+		err = mdio_register(mii_bus);
+		if (err) {
+			mdio_free(mii_bus);
+			return err;
+		}
 	}
 
 	dm_pci_clrset_config16(dev, PCI_COMMAND, 0, PCI_COMMAND_MEMORY);
Signature · 1 line
2.25.1
Reviewed-by on v1 22/25
#43 lore raw

Re: [PATCH 22/25] net: dsa: felix: check return code of mdio_alloc and mdio_register

Quoted 42 lines · Vladimir Oltean

These functions can return errors, it's best to catch them and trigger the driver unwind code path.

---
 drivers/net/mscc_eswitch/felix_switch.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/mscc_eswitch/felix_switch.c +9 -2
index 4c2e57755967..98ae39e81d65 100644
@@ -276,6 +276,7 @@ static void felix_init(struct udevice *dev)
 static int felix_probe(struct udevice *dev)
 {
        struct felix_priv *priv = dev_get_priv(dev);
+       int err;
 
        if (ofnode_valid(dev_ofnode(dev)) &&
            !ofnode_is_available(dev_ofnode(dev))) {
@@ -300,11 +301,18 @@ static int felix_probe(struct udevice *dev)
                struct mii_dev *mii_bus;
 
                mii_bus = mdio_alloc();
+               if (!mii_bus)
+                       return -ENOMEM;
+
                mii_bus->read = felix_mdio_read;
                mii_bus->write = felix_mdio_write;
                mii_bus->priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
                strlcpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
-               mdio_register(mii_bus);
+               err = mdio_register(mii_bus);
+               if (err) {
+                       mdio_free(mii_bus);
+                       return err;
+               }
        }
 
        dm_pci_clrset_config16(dev, PCI_COMMAND, 0, PCI_COMMAND_MEMORY);
--
Quoted 2 lines

2.25.1

#44 lore raw

PATCH 23/25 net: dsa: ensure port names are NULL-terminated after DSA_PORT_NAME_LENGTH truncation

In reply to Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass DSA_PORT_NAME_LENGTH - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 net/dsa-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/dsa-uclass.c +2 -2
index 9b8ae1e82b92..8db0de686e2a 100644
@@ -221,7 +221,7 @@ static int dsa_port_of_to_pdata(struct udevice *pdev)
 
 	label = ofnode_read_string(dev_ofnode(pdev), "label");
 	if (label)
-		strncpy(port_pdata->name, label, DSA_PORT_NAME_LENGTH);
+		strlcpy(port_pdata->name, label, DSA_PORT_NAME_LENGTH);
 
 	eth_pdata = dev_get_plat(pdev);
 	eth_pdata->priv_pdata = port_pdata;
@@ -433,7 +433,7 @@ static int dsa_post_bind(struct udevice *dev)
 			struct dsa_port_pdata *port_pdata;
 
 			port_pdata = dev_get_parent_plat(pdev);
-			strncpy(port_pdata->name, name, DSA_PORT_NAME_LENGTH);
+			strlcpy(port_pdata->name, name, DSA_PORT_NAME_LENGTH);
 			pdev->name = port_pdata->name;
 		}
 
Signature · 1 line
2.25.1
Reviewed-by on v1 23/25
#45 lore raw

Re: [PATCH 23/25] net: dsa: ensure port names are NULL-terminated after DSA_PORT_NAME_LENGTH truncation

Quoted 43 lines · Vladimir Oltean

strncpy() simply bails out when copying a source string whose size exceeds the destination string size, potentially leaving the destination string unterminated.

One possible way to address is to pass DSA_PORT_NAME_LENGTH - 1 and a previously zero-initialized destination string, but this is more difficult to maintain.

The chosen alternative is to use strlcpy(), which properly limits the copy len in the (srclen >= size) case to "size - 1", and which is also more efficient than the strncpy() byte-by-byte implementation by using memcpy. The destination string returned by strlcpy() is always NULL terminated.

---
 net/dsa-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/dsa-uclass.c +2 -3
index 9b8ae1e82b92..8db0de686e2a 100644
@@ -221,7 +221,7 @@ static int dsa_port_of_to_pdata(struct udevice *pdev)
 
        label = ofnode_read_string(dev_ofnode(pdev), "label");
        if (label)
-               strncpy(port_pdata->name, label, DSA_PORT_NAME_LENGTH);
+               strlcpy(port_pdata->name, label, DSA_PORT_NAME_LENGTH);
 
        eth_pdata = dev_get_plat(pdev);
        eth_pdata->priv_pdata = port_pdata;
@@ -433,7 +433,7 @@ static int dsa_post_bind(struct udevice *dev)
                        struct dsa_port_pdata *port_pdata;
 
                        port_pdata = dev_get_parent_plat(pdev);
-                       strncpy(port_pdata->name, name, DSA_PORT_NAME_LENGTH);
+                       strlcpy(port_pdata->name, name, DSA_PORT_NAME_LENGTH);
                        pdev->name = port_pdata->name;
                }
 
--
Quoted 2 lines

2.25.1

#46 lore raw

PATCH 24/25 arch: powerpc: mpc85xx: free MDIO bus if mdio_register fails

In reply to Vladimir Oltean

If mdio_register fails, it is nice to not leave behind dangling allocated memory.

---
 arch/powerpc/cpu/mpc85xx/ether_fcc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/ether_fcc.c +3 -1
index 1f6f55707321..5cf0a3fb227a 100644
@@ -449,8 +449,10 @@ int fec_initialize(struct bd_info *bis)
 		mdiodev->write = bb_miiphy_write;
 
 		retval = mdio_register(mdiodev);
-		if (retval < 0)
+		if (retval < 0) {
+			mdio_free(mdiodev);
 			return retval;
+		}
 #endif
 	}
 
Signature · 1 line
2.25.1
Reviewed-by on v1 24/25
#47 lore raw

Re: [PATCH 24/25] arch: powerpc: mpc85xx: free MDIO bus if mdio_register fails

Quoted 26 lines · Vladimir Oltean

If mdio_register fails, it is nice to not leave behind dangling allocated memory.

---
 arch/powerpc/cpu/mpc85xx/ether_fcc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/cpu/mpc85xx/ether_fcc.c +3 -2
index 1f6f55707321..5cf0a3fb227a 100644
@@ -449,8 +449,10 @@ int fec_initialize(struct bd_info *bis)
                mdiodev->write = bb_miiphy_write;
 
                retval = mdio_register(mdiodev);
-               if (retval < 0)
+               if (retval < 0) {
+                       mdio_free(mdiodev);
                        return retval;
+               }
 #endif
        }
 
--
Quoted 2 lines

2.25.1

#48 lore raw

PATCH 25/25 scripts: ensure the cocci script for miiphy_register does not leak the MDIO bus

In reply to Vladimir Oltean

When mdio_register fails, mdio_free should be called on the mdiodev that was previously allocated with mdio_alloc.

---
 scripts/coccinelle/net/mdio_register.cocci | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/net/mdio_register.cocci +1 -1
index 31a40360f99e..7d11281f4678 100644
@@ -21,7 +21,7 @@ identifier readfunc, writefunc;
 + mdiodev->write = writefunc;
 + 
 + retval = mdio_register(mdiodev);
-+ if (retval < 0) return retval;
++ if (retval < 0) { mdio_free(mdiodev); return retval; }
 
 @ update_read_sig @
 identifier mii_reg.readfunc;
Signature · 1 line
2.25.1