mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 22:59:29 +02:00
pinctrl: spacemit: validate pins in pinconf callbacks
Pin 0 is a valid pin ID, but spacemit_pinconf_get() rejects it by
testing the numeric ID rather than the result of the descriptor lookup.
It also fails to reject nonzero IDs absent from the SoC pin table before
computing their register addresses. Check the descriptor and use its pin
ID for the register lookup.
spacemit_pinconf_group_set() validates only the first group member when
generating the configuration. If a later member is invalid,
spacemit_pin_set_config() returns -EINVAL, but the callback ignores it
and reports success after partially updating the group.
Validate every group member before writing any registers so malformed
groups fail without being partially applied.
Fixes: a83c29e1d1 ("pinctrl: spacemit: add support for SpacemiT K1 SoC")
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Reviewed-by: Yixun Lan <dlan@kernel.org>
Signed-off-by: Linus Walleij <linusw@kernel.org>
This commit is contained in:
committed by
Linus Walleij
parent
17007cd700
commit
41c59b2237
@@ -503,13 +503,14 @@ static int spacemit_pinconf_get(struct pinctrl_dev *pctldev,
|
||||
unsigned int pin, unsigned long *config)
|
||||
{
|
||||
struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
|
||||
const struct spacemit_pin *spin = spacemit_get_pin(pctrl, pin);
|
||||
int param = pinconf_to_config_param(*config);
|
||||
u32 value, arg = 0;
|
||||
|
||||
if (!pin)
|
||||
if (!spin)
|
||||
return -EINVAL;
|
||||
|
||||
value = readl(spacemit_pin_to_reg(pctrl, pin));
|
||||
value = readl(spacemit_pin_to_reg(pctrl, spin->pin));
|
||||
|
||||
switch (param) {
|
||||
case PIN_CONFIG_SLEW_RATE:
|
||||
@@ -689,6 +690,11 @@ static int spacemit_pinconf_group_set(struct pinctrl_dev *pctldev,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < group->grp.npins; i++) {
|
||||
if (!spacemit_get_pin(pctrl, group->grp.pins[i]))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < group->grp.npins; i++)
|
||||
spacemit_pin_set_config(pctrl, group->grp.pins[i], value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user