mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-20 20:04:46 +00:00
pinctrl: tegra20: detect unknown/invalid pin/func configurations
Tegra20 driver doesn't know about some pin configurations and even about some pins. In case when pin configuration is unknown the pin would be muxed to whatever is under function 0, in case when pin itself is unknown, it could cause out-of-bounds array access in pinmux_set_func and pinmux_set_pullupdown. Signed-off-by: Artur Kowalski <arturkow2000@gmail.com> Reviewed-by: Svyatoslav Ryhel <clamor95@gmail.com> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
This commit is contained in:
parent
645350ed4b
commit
a35bf832d7
1 changed files with 16 additions and 2 deletions
|
@ -37,6 +37,11 @@ static void tegra_pinctrl_set_pin(struct udevice *config)
|
||||||
if (!strcmp(pins[i], tegra_pinctrl_to_pingrp[pin_id]))
|
if (!strcmp(pins[i], tegra_pinctrl_to_pingrp[pin_id]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (pin_id == PMUX_PINGRP_COUNT) {
|
||||||
|
log_debug("%s: %s(%d) is not valid\n", __func__, pins[i], pin_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (pull >= 0)
|
if (pull >= 0)
|
||||||
pinmux_set_pullupdown(pin_id, pull);
|
pinmux_set_pullupdown(pin_id, pull);
|
||||||
|
|
||||||
|
@ -58,13 +63,16 @@ static void tegra_pinctrl_set_func(struct udevice *config)
|
||||||
const char **pins;
|
const char **pins;
|
||||||
|
|
||||||
function = dev_read_string(config, "nvidia,function");
|
function = dev_read_string(config, "nvidia,function");
|
||||||
if (function)
|
if (function) {
|
||||||
for (i = 0; i < PMUX_FUNC_COUNT; i++)
|
for (i = 0; i < PMUX_FUNC_COUNT; i++)
|
||||||
if (tegra_pinctrl_to_func[i])
|
if (tegra_pinctrl_to_func[i])
|
||||||
if (!strcmp(function, tegra_pinctrl_to_func[i]))
|
if (!strcmp(function, tegra_pinctrl_to_func[i]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
func_id = i;
|
func_id = i;
|
||||||
|
} else {
|
||||||
|
func_id = PMUX_FUNC_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
count = dev_read_string_list(config, "nvidia,pins", &pins);
|
count = dev_read_string_list(config, "nvidia,pins", &pins);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
|
@ -78,6 +86,12 @@ static void tegra_pinctrl_set_func(struct udevice *config)
|
||||||
if (!strcmp(pins[i], tegra_pinctrl_to_pingrp[pin_id]))
|
if (!strcmp(pins[i], tegra_pinctrl_to_pingrp[pin_id]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (func_id == PMUX_FUNC_COUNT || pin_id == PMUX_PINGRP_COUNT) {
|
||||||
|
log_debug("%s: pin %s(%d) or function %s(%d) is not valid\n",
|
||||||
|
__func__, pins[i], pin_id, function, func_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
debug("%s(%d) muxed to %s(%d)\n", pins[i], pin_id, function, func_id);
|
debug("%s(%d) muxed to %s(%d)\n", pins[i], pin_id, function, func_id);
|
||||||
|
|
||||||
pinmux_set_func(pin_id, func_id);
|
pinmux_set_func(pin_id, func_id);
|
||||||
|
|
Loading…
Add table
Reference in a new issue