]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
regmap: mdio: Clean up invalid clause-22 addresses
authorSander Vanheule <sander@svanheule.net>
Thu, 3 Jun 2021 18:25:09 +0000 (20:25 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 8 Jun 2021 12:37:42 +0000 (13:37 +0100)
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 masking the
provided register address.

Signed-off-by: Sander Vanheule <sander@svanheule.net>
Link: https://lore.kernel.org/r/f7013f67e6d6ff56ec98660f18320f6ffcc1a777.1622743333.git.sander@svanheule.net
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regmap-mdio.c

index 5ec208279913fdae088081875c07f8bcf7c3e746..aee34bf2400e5173caf42e65b4ea719abd54736e 100644 (file)
@@ -5,16 +5,19 @@
 #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);
+       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 +25,7 @@ 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);
+       return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg & REGNUM_C22_MASK, val);
 }
 
 static const struct regmap_bus regmap_mdio_bus = {