mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mdio_bus: add NULL check to mdiobus_read/mdiobus_write
@ 2024-10-14  8:55 Ahmad Fatoum
  2024-10-14  9:24 ` Stefan Kerkmann
  2024-10-14 11:13 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-10-14  8:55 UTC (permalink / raw)
  To: barebox; +Cc: rcz, ske, Ahmad Fatoum

These functions shouldn't be called with a NULL pointer as argument in
the first place, but this happened at least twice so far[1][2], because
drivers weren't tested in fixed-link setups without PHYs.

To improve user experience, let's return -EIO instead of crashing
outright. The proper fix is still to adapt these drivers, so they
do not try to access non-existent PHYs.

[1]: commit 6269556397 ("net: eqos: let phy_resume handle fixed link phys")
[2]: https://lore.barebox.org/barebox/20241010-fix-designware-fixed-link-v1-1-de2df5485a25@pengutronix.de/T/#u

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 30d5aeacff0d..68652e92a830 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -441,6 +441,9 @@ int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
 {
 	int ret;
 
+	if (!bus)
+		return -EIO;
+
 	slice_acquire(&bus->slice);
 
 	ret = bus->read(bus, addr, regnum);
@@ -461,6 +464,9 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
 {
 	int ret;
 
+	if (!bus)
+		return -EIO;
+
 	slice_acquire(&bus->slice);
 
 	ret = bus->write(bus, addr, regnum, val);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mdio_bus: add NULL check to mdiobus_read/mdiobus_write
  2024-10-14  8:55 [PATCH] mdio_bus: add NULL check to mdiobus_read/mdiobus_write Ahmad Fatoum
@ 2024-10-14  9:24 ` Stefan Kerkmann
  2024-10-14 11:13 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Kerkmann @ 2024-10-14  9:24 UTC (permalink / raw)
  To: Ahmad Fatoum, barebox; +Cc: rcz, ske

Reviewed-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>

On 14.10.24 10:55, Ahmad Fatoum wrote:
> These functions shouldn't be called with a NULL pointer as argument in
> the first place, but this happened at least twice so far[1][2], because
> drivers weren't tested in fixed-link setups without PHYs.
> 
> To improve user experience, let's return -EIO instead of crashing
> outright. The proper fix is still to adapt these drivers, so they
> do not try to access non-existent PHYs.
> 
> [1]: commit 6269556397 ("net: eqos: let phy_resume handle fixed link phys")
> [2]: https://lore.barebox.org/barebox/20241010-fix-designware-fixed-link-v1-1-de2df5485a25@pengutronix.de/T/#u
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/net/phy/mdio_bus.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 30d5aeacff0d..68652e92a830 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -441,6 +441,9 @@ int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
>  {
>  	int ret;
>  
> +	if (!bus)
> +		return -EIO;
> +
>  	slice_acquire(&bus->slice);
>  
>  	ret = bus->read(bus, addr, regnum);
> @@ -461,6 +464,9 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
>  {
>  	int ret;
>  
> +	if (!bus)
> +		return -EIO;
> +
>  	slice_acquire(&bus->slice);
>  
>  	ret = bus->write(bus, addr, regnum, val);

-- 
Pengutronix e.K.                       | Stefan Kerkmann             |
Steuerwalder Str. 21                   | https://www.pengutronix.de/ |
31137 Hildesheim, Germany              | Phone: +49-5121-206917-128  |
Amtsgericht Hildesheim, HRA 2686       | Fax:   +49-5121-206917-9    |




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mdio_bus: add NULL check to mdiobus_read/mdiobus_write
  2024-10-14  8:55 [PATCH] mdio_bus: add NULL check to mdiobus_read/mdiobus_write Ahmad Fatoum
  2024-10-14  9:24 ` Stefan Kerkmann
@ 2024-10-14 11:13 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-10-14 11:13 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: rcz, ske


On Mon, 14 Oct 2024 10:55:06 +0200, Ahmad Fatoum wrote:
> These functions shouldn't be called with a NULL pointer as argument in
> the first place, but this happened at least twice so far[1][2], because
> drivers weren't tested in fixed-link setups without PHYs.
> 
> To improve user experience, let's return -EIO instead of crashing
> outright. The proper fix is still to adapt these drivers, so they
> do not try to access non-existent PHYs.
> 
> [...]

Applied, thanks!

[1/1] mdio_bus: add NULL check to mdiobus_read/mdiobus_write
      https://git.pengutronix.de/cgit/barebox/commit/?id=36d1dd4afe57 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-14 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-14  8:55 [PATCH] mdio_bus: add NULL check to mdiobus_read/mdiobus_write Ahmad Fatoum
2024-10-14  9:24 ` Stefan Kerkmann
2024-10-14 11:13 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox