[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210605083116.12786-1-sander@svanheule.net>
Date: Sat, 5 Jun 2021 10:31:18 +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>,
Sander Vanheule <sander@...nheule.net>,
Andrew Lunn <andrew@...n.ch>
Subject: [PATCH] regmap: mdio: Reject invalid clause-22 addresses
Currently a regmap configuration for regmap-mdio must have a register
address width of 5 bits (cf. clause-22 register access). This is not
enforced on the provided register addresses, which would enable
clause-45 MDIO bus access, if the right bit packing is used.
Prevent clause-45 access, and other invalid addresses, by verifying the
provided register address.
Cc: Andrew Lunn <andrew@...n.ch>
Signed-off-by: Sander Vanheule <sander@...nheule.net>
---
drivers/base/regmap/regmap-mdio.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/base/regmap/regmap-mdio.c b/drivers/base/regmap/regmap-mdio.c
index 5ec208279913..3b842cf1eef9 100644
--- a/drivers/base/regmap/regmap-mdio.c
+++ b/drivers/base/regmap/regmap-mdio.c
@@ -5,16 +5,22 @@
#include <linux/module.h>
#include <linux/regmap.h>
+#define REGVAL_MASK GENMASK(15, 0)
+#define REGNUM_C22_MASK GENMASK(4, 0)
+
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);
+ if (unlikely(reg & ~REGNUM_C22_MASK))
+ return -ENXIO;
+
+ ret = mdiobus_read(mdio_dev->bus, mdio_dev->addr, reg & REGNUM_C22_MASK);
if (ret < 0)
return ret;
- *val = ret & 0xffff;
+ *val = ret & REGVAL_MASK;
return 0;
}
@@ -22,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, val);
+ if (unlikely(reg & ~REGNUM_C22_MASK))
+ return -ENXIO;
+
+ return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg & REGNUM_C22_MASK, val);
}
static const struct regmap_bus regmap_mdio_bus = {
--
2.31.1
Powered by blists - more mailing lists