summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorSander Vanheule <sander@svanheule.net>2021-06-09 15:10:04 +0200
committerMark Brown <broonie@kernel.org>2021-06-14 16:00:29 +0200
commit0df0240946b1ffbe852fa302c04c0d322229c9ce (patch)
tree1519d877e958cc96e928fc74b34d429568b4302c /drivers/base
parentregmap: mdio: Fix regmap_bus pointer constness (diff)
downloadlinux-0df0240946b1ffbe852fa302c04c0d322229c9ce.tar.xz
linux-0df0240946b1ffbe852fa302c04c0d322229c9ce.zip
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: Sander Vanheule <sander@svanheule.net> Link: https://lore.kernel.org/r/047007e0e9fb596480829f11f8c7e6281d235c70.1623244066.git.sander@svanheule.net Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/regmap/regmap-mdio.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/drivers/base/regmap/regmap-mdio.c b/drivers/base/regmap/regmap-mdio.c
index b772b42809e2..6a20201299f5 100644
--- a/drivers/base/regmap/regmap-mdio.c
+++ b/drivers/base/regmap/regmap-mdio.c
@@ -31,14 +31,20 @@ static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *v
{
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)
{
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 = {
@@ -50,14 +56,20 @@ static int regmap_mdio_c45_read(void *context, unsigned int reg, unsigned int *v
{
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)
{
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 = {