Skip to content

Commit 81556d6

Browse files
biglbenaescolar
authored andcommitted
drivers: ethernet: phy_mii: check if there is a mdio config
In fixed-link mode, mdio remains unconfigured. This results in a null pointer dereference, triggering a bus fault Signed-off-by: Benjamin Bigler <[email protected]>
1 parent 85c57c2 commit 81556d6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/ethernet/phy/phy_mii.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ static inline int reg_read(const struct device *dev, uint16_t reg_addr,
4949
{
5050
const struct phy_mii_dev_config *const cfg = dev->config;
5151

52+
/* if there is no mdio (fixed-link) it is not supported to read */
53+
if (cfg->mdio == NULL) {
54+
return -ENOTSUP;
55+
}
5256
return mdio_read(cfg->mdio, cfg->phy_addr, reg_addr, value);
5357
}
5458

@@ -57,6 +61,10 @@ static inline int reg_write(const struct device *dev, uint16_t reg_addr,
5761
{
5862
const struct phy_mii_dev_config *const cfg = dev->config;
5963

64+
/* if there is no mdio (fixed-link) it is not supported to write */
65+
if (cfg->mdio == NULL) {
66+
return -ENOTSUP;
67+
}
6068
return mdio_write(cfg->mdio, cfg->phy_addr, reg_addr, value);
6169
}
6270

0 commit comments

Comments
 (0)