Commit 0df02409 authored by Sander Vanheule's avatar Sander Vanheule Committed by Mark Brown

regmap: mdio: Reject invalid addresses

When an invalid register offset is provided, the upper bits are silently
discarded. Change this to return -ENXIO instead, to help catch potential
bugs.
Signed-off-by: default avatarSander Vanheule <sander@svanheule.net>
Link: https://lore.kernel.org/r/047007e0e9fb596480829f11f8c7e6281d235c70.1623244066.git.sander@svanheule.netSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent ce62df22
...@@ -31,14 +31,20 @@ static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *v ...@@ -31,14 +31,20 @@ static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *v
{ {
struct mdio_device *mdio_dev = context; struct mdio_device *mdio_dev = context;
return regmap_mdio_read(mdio_dev, reg & REGNUM_C22_MASK, val); if (unlikely(reg & ~REGNUM_C22_MASK))
return -ENXIO;
return regmap_mdio_read(mdio_dev, reg, val);
} }
static int regmap_mdio_c22_write(void *context, unsigned int reg, unsigned int val) static int regmap_mdio_c22_write(void *context, unsigned int reg, unsigned int val)
{ {
struct mdio_device *mdio_dev = context; struct mdio_device *mdio_dev = context;
return regmap_mdio_write(mdio_dev, reg & REGNUM_C22_MASK, val); if (unlikely(reg & ~REGNUM_C22_MASK))
return -ENXIO;
return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg, val);
} }
static const struct regmap_bus regmap_mdio_c22_bus = { static const struct regmap_bus regmap_mdio_c22_bus = {
...@@ -50,14 +56,20 @@ static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *v ...@@ -50,14 +56,20 @@ static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *v
{ {
struct mdio_device *mdio_dev = context; struct mdio_device *mdio_dev = context;
return regmap_mdio_read(mdio_dev, MII_ADDR_C45 | (reg & REGNUM_C45_MASK), val); if (unlikely(reg & ~REGNUM_C45_MASK))
return -ENXIO;
return regmap_mdio_read(mdio_dev, MII_ADDR_C45 | reg, val);
} }
static int regmap_mdio_c45_write(void *context, unsigned int reg, unsigned int val) static int regmap_mdio_c45_write(void *context, unsigned int reg, unsigned int val)
{ {
struct mdio_device *mdio_dev = context; struct mdio_device *mdio_dev = context;
return regmap_mdio_write(mdio_dev, MII_ADDR_C45 | (reg & REGNUM_C45_MASK), val); if (unlikely(reg & ~REGNUM_C45_MASK))
return -ENXIO;
return regmap_mdio_write(mdio_dev, MII_ADDR_C45 | reg, val);
} }
static const struct regmap_bus regmap_mdio_c45_bus = { static const struct regmap_bus regmap_mdio_c45_bus = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment