Skip to content

Commit 5216103

Browse files
prabhakarladgeertu
authored andcommitted
pinctrl: renesas: rzg2l: Validate pins before setting mux function
Ensure only valid pins are configured by validating pin mappings before setting the mux function. Rename rzg2l_validate_gpio_pin() to rzg2l_validate_pin() to reflect its broader purpose validating both GPIO pins and muxed pins. This helps avoid invalid configurations. Signed-off-by: Lad Prabhakar <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent d2fb026 commit 5216103

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

drivers/pinctrl/renesas/pinctrl-rzg2l.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,23 @@ static void rzv2h_pmc_writeb(struct rzg2l_pinctrl *pctrl, u8 val, u16 offset)
493493
writeb(pwpr & ~PWPR_REGWE_A, pctrl->base + regs->pwpr);
494494
}
495495

496+
static int rzg2l_validate_pin(struct rzg2l_pinctrl *pctrl,
497+
u64 cfg, u32 port, u8 bit)
498+
{
499+
u8 pinmap = FIELD_GET(PIN_CFG_PIN_MAP_MASK, cfg);
500+
u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg);
501+
u64 data;
502+
503+
if (!(pinmap & BIT(bit)) || port >= pctrl->data->n_port_pins)
504+
return -EINVAL;
505+
506+
data = pctrl->data->port_pin_configs[port];
507+
if (off != RZG2L_PIN_CFG_TO_PORT_OFFSET(data))
508+
return -EINVAL;
509+
510+
return 0;
511+
}
512+
496513
static void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl,
497514
u8 pin, u8 off, u8 func)
498515
{
@@ -536,6 +553,7 @@ static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
536553
unsigned int i, *psel_val;
537554
struct group_desc *group;
538555
const unsigned int *pins;
556+
int ret;
539557

540558
func = pinmux_generic_get_function(pctldev, func_selector);
541559
if (!func)
@@ -552,6 +570,10 @@ static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
552570
u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data);
553571
u32 pin = RZG2L_PIN_ID_TO_PIN(pins[i]);
554572

573+
ret = rzg2l_validate_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(pins[i]), pin);
574+
if (ret)
575+
return ret;
576+
555577
dev_dbg(pctrl->dev, "port:%u pin: %u off:%x PSEL:%u\n",
556578
RZG2L_PIN_ID_TO_PORT(pins[i]), pin, off, psel_val[i] - hwcfg->func_base);
557579

@@ -806,23 +828,6 @@ static int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev,
806828
return ret;
807829
}
808830

809-
static int rzg2l_validate_gpio_pin(struct rzg2l_pinctrl *pctrl,
810-
u64 cfg, u32 port, u8 bit)
811-
{
812-
u8 pinmap = FIELD_GET(PIN_CFG_PIN_MAP_MASK, cfg);
813-
u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(cfg);
814-
u64 data;
815-
816-
if (!(pinmap & BIT(bit)) || port >= pctrl->data->n_port_pins)
817-
return -EINVAL;
818-
819-
data = pctrl->data->port_pin_configs[port];
820-
if (off != RZG2L_PIN_CFG_TO_PORT_OFFSET(data))
821-
return -EINVAL;
822-
823-
return 0;
824-
}
825-
826831
static u32 rzg2l_read_pin_config(struct rzg2l_pinctrl *pctrl, u32 offset,
827832
u8 bit, u32 mask)
828833
{
@@ -1287,7 +1292,7 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
12871292
} else {
12881293
bit = RZG2L_PIN_ID_TO_PIN(_pin);
12891294

1290-
if (rzg2l_validate_gpio_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit))
1295+
if (rzg2l_validate_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit))
12911296
return -EINVAL;
12921297
}
12931298

@@ -1447,7 +1452,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
14471452
} else {
14481453
bit = RZG2L_PIN_ID_TO_PIN(_pin);
14491454

1450-
if (rzg2l_validate_gpio_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit))
1455+
if (rzg2l_validate_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit))
14511456
return -EINVAL;
14521457
}
14531458

@@ -1687,7 +1692,7 @@ static int rzg2l_gpio_request(struct gpio_chip *chip, unsigned int offset)
16871692
u8 reg8;
16881693
int ret;
16891694

1690-
ret = rzg2l_validate_gpio_pin(pctrl, *pin_data, port, bit);
1695+
ret = rzg2l_validate_pin(pctrl, *pin_data, port, bit);
16911696
if (ret)
16921697
return ret;
16931698

0 commit comments

Comments
 (0)