pwm: stm32: Validate breakinput data from DT
Both index and level can only be either 0 or 1 and the filter value is limited to values between (and including) 0 and 15. Validate that the device tree node contains values that are within these ranges. Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
parent
27938fd8ba
commit
8dfa620e3d
@ -536,6 +536,7 @@ static int stm32_pwm_probe_breakinputs(struct stm32_pwm *priv,
|
|||||||
struct device_node *np)
|
struct device_node *np)
|
||||||
{
|
{
|
||||||
int nb, ret, array_size;
|
int nb, ret, array_size;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
nb = of_property_count_elems_of_size(np, "st,breakinput",
|
nb = of_property_count_elems_of_size(np, "st,breakinput",
|
||||||
sizeof(struct stm32_breakinput));
|
sizeof(struct stm32_breakinput));
|
||||||
@ -557,6 +558,13 @@ static int stm32_pwm_probe_breakinputs(struct stm32_pwm *priv,
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
for (i = 0; i < priv->num_breakinputs; i++) {
|
||||||
|
if (priv->breakinputs[i].index > 1 ||
|
||||||
|
priv->breakinputs[i].level > 1 ||
|
||||||
|
priv->breakinputs[i].filter > 15)
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return stm32_pwm_apply_breakinputs(priv);
|
return stm32_pwm_apply_breakinputs(priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user