Skip to content

Commit b743296

Browse files
andy-shevgregkh
authored andcommitted
pinctrl: cy8c95x0: Avoid accessing reserved registers
[ Upstream commit 3fbe3fe ] 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: 71e4001 ("pinctrl: pinctrl-cy8c95x0: Fix regcache") Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent eea6d16 commit b743296

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/pinctrl/pinctrl-cy8c95x0.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,14 @@ static int cypress_get_pin_mask(struct cy8c95x0_pinctrl *chip, unsigned int pin)
330330
static bool cy8c95x0_readable_register(struct device *dev, unsigned int reg)
331331
{
332332
/*
333-
* Only 12 registers are present per port (see Table 6 in the
334-
* datasheet).
333+
* Only 12 registers are present per port (see Table 6 in the datasheet).
335334
*/
336-
if (reg >= CY8C95X0_VIRTUAL && (reg % MUXED_STRIDE) < 12)
337-
return true;
335+
if (reg >= CY8C95X0_VIRTUAL && (reg % MUXED_STRIDE) >= 12)
336+
return false;
338337

339338
switch (reg) {
340339
case 0x24 ... 0x27:
340+
case 0x31 ... 0x3f:
341341
return false;
342342
default:
343343
return true;
@@ -346,15 +346,19 @@ static bool cy8c95x0_readable_register(struct device *dev, unsigned int reg)
346346

347347
static bool cy8c95x0_writeable_register(struct device *dev, unsigned int reg)
348348
{
349-
if (reg >= CY8C95X0_VIRTUAL)
350-
return true;
349+
/*
350+
* Only 12 registers are present per port (see Table 6 in the datasheet).
351+
*/
352+
if (reg >= CY8C95X0_VIRTUAL && (reg % MUXED_STRIDE) >= 12)
353+
return false;
351354

352355
switch (reg) {
353356
case CY8C95X0_INPUT_(0) ... CY8C95X0_INPUT_(7):
354357
return false;
355358
case CY8C95X0_DEVID:
356359
return false;
357360
case 0x24 ... 0x27:
361+
case 0x31 ... 0x3f:
358362
return false;
359363
default:
360364
return true;

0 commit comments

Comments
 (0)