# \[PATCH\] pinctrl: renesas: r8a7794: Add range checking to .pin\_to\_pocctrl()

- From: Geert Uytterhoeven \<geert+renesas@glider.be\>
- Date: 2021-12-23 14:28:26 
- List: linux-gpio
- Page: https://ratatoskr.run/linux-gpio/2021/12/8514026
- Thread: https://ratatoskr.run/linux-renesas-soc/2021/12/8514026/t.md

```text
The .pin_to_pocctrl() implementation for R-Car E2 does not perform a
full range check, unlike on all other SoCs.  Add the range check, so the
checker can validate better the consistency of the pin control tables.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
To be queued in renesas-pinctrl for v5.18.

 drivers/pinctrl/renesas/pfc-r8a7794.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pinctrl/renesas/pfc-r8a7794.c b/drivers/pinctrl/renesas/pfc-r8a7794.c
index fbb5b3b68f349ac6..08a4269565e2e54a 100644
--- a/drivers/pinctrl/renesas/pfc-r8a7794.c
+++ b/drivers/pinctrl/renesas/pfc-r8a7794.c
@@ -5623,6 +5623,9 @@ static const struct pinmux_cfg_reg pinmux_config_regs[] = {
 
 static int r8a7794_pin_to_pocctrl(struct sh_pfc *pfc, unsigned int pin, u32 *pocctrl)
 {
+	if (pin < RCAR_GP_PIN(6, 0) || pin > RCAR_GP_PIN(6, 23))
+		return -EINVAL;
+
 	*pocctrl = 0xe606006c;
 
 	switch (pin & 0x1f) {
-- 
2.25.1

```
