[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <7e1fc137134699fd2daca0937c2223225afd9c3d.1623238313.git.sander@svanheule.net>
Date: Wed, 9 Jun 2021 13:46:06 +0200
From: Sander Vanheule <sander@...nheule.net>
To: Mark Brown <broonie@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
linux-kernel@...r.kernel.org
Cc: Andy Shevchenko <andy.shevchenko@...il.com>,
Adrew Lunn <andrew@...n.ch>,
Sander Vanheule <sander@...nheule.net>
Subject: [PATCH 2/2] regmap: mdio: Reject invalid clause-22 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@...nheule.net>
---
drivers/base/regmap/regmap-mdio.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/base/regmap/regmap-mdio.c b/drivers/base/regmap/regmap-mdio.c
index aee34bf2400e..9adfb82be8f1 100644
--- a/drivers/base/regmap/regmap-mdio.c
+++ b/drivers/base/regmap/regmap-mdio.c
@@ -13,7 +13,10 @@ static int regmap_mdio_read(void *context, unsigned int reg, unsigned int *val)
struct mdio_device *mdio_dev = context;
int ret;
- ret = mdiobus_read(mdio_dev->bus, mdio_dev->addr, reg & REGNUM_C22_MASK);
+ if (unlikely(reg & ~REGNUM_C22_MASK))
+ return -ENXIO;
+
+ ret = mdiobus_read(mdio_dev->bus, mdio_dev->addr, reg);
if (ret < 0)
return ret;
@@ -25,7 +28,10 @@ static int regmap_mdio_write(void *context, unsigned int reg, unsigned int val)
{
struct mdio_device *mdio_dev = context;
- return mdiobus_write(mdio_dev->bus, mdio_dev->addr, 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_bus = {
--
2.31.1
Powered by blists - more mailing lists