]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pinctrl: cy8c95x0: Avoid accessing reserved registers
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 3 Feb 2025 13:10:28 +0000 (15:10 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Feb 2025 13:01:14 +0000 (14:01 +0100)
[ Upstream commit 3fbe3fe28764455e4fc3578afb9765f46f9ce93d ]

The checks for vrtual registers in the cy8c95x0_readable_register()
and cy8c95x0_writeable_register() are not aligned and broken.

Fix that by explicitly avoiding reserved registers to be accessed.

Fixes: 71e4001a0455 ("pinctrl: pinctrl-cy8c95x0: Fix regcache")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/20250203131506.3318201-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pinctrl/pinctrl-cy8c95x0.c

index 5096ccdd459ea40c0a7ec9e1a2af7969dc31f970..05224808d92bee113331626a03e5d54949aaf090 100644 (file)
@@ -330,14 +330,14 @@ static int cypress_get_pin_mask(struct cy8c95x0_pinctrl *chip, unsigned int pin)
 static bool cy8c95x0_readable_register(struct device *dev, unsigned int reg)
 {
        /*
-        * Only 12 registers are present per port (see Table 6 in the
-        * datasheet).
+        * Only 12 registers are present per port (see Table 6 in the datasheet).
         */
-       if (reg >= CY8C95X0_VIRTUAL && (reg % MUXED_STRIDE) < 12)
-               return true;
+       if (reg >= CY8C95X0_VIRTUAL && (reg % MUXED_STRIDE) >= 12)
+               return false;
 
        switch (reg) {
        case 0x24 ... 0x27:
+       case 0x31 ... 0x3f:
                return false;
        default:
                return true;
@@ -346,8 +346,11 @@ static bool cy8c95x0_readable_register(struct device *dev, unsigned int reg)
 
 static bool cy8c95x0_writeable_register(struct device *dev, unsigned int reg)
 {
-       if (reg >= CY8C95X0_VIRTUAL)
-               return true;
+       /*
+        * Only 12 registers are present per port (see Table 6 in the datasheet).
+        */
+       if (reg >= CY8C95X0_VIRTUAL && (reg % MUXED_STRIDE) >= 12)
+               return false;
 
        switch (reg) {
        case CY8C95X0_INPUT_(0) ... CY8C95X0_INPUT_(7):
@@ -355,6 +358,7 @@ static bool cy8c95x0_writeable_register(struct device *dev, unsigned int reg)
        case CY8C95X0_DEVID:
                return false;
        case 0x24 ... 0x27:
+       case 0x31 ... 0x3f:
                return false;
        default:
                return true;