From b64cf2cf576d109e77b77d893be7cd9c8a163f8f Mon Sep 17 00:00:00 2001 From: Edgardo Handal Date: Mon, 19 Sep 2016 11:48:18 -0500 Subject: gpio: tegra: don't access nonexistent pins Store how many pins exist per port in a table and limit accesses based on that table. This will prevent reading nonexistent registers Change-Id: I94c8393565970849fd4d731721824245e50258d5 Signed-off-by: Edgardo Handal Reviewed-on: http://git-master/r/1223135 GVS: Gerrit_Virtual_Submit Reviewed-by: Laxman Dewangan --- drivers/gpio/gpio-tegra186.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c index 3ed3e00ac..4c5d718b6 100644 --- a/drivers/gpio/gpio-tegra186.c +++ b/drivers/gpio/gpio-tegra186.c @@ -123,6 +123,11 @@ static int tegra186_gpio_map[MAX_GPIO_CONTROLLERS][MAX_GPIO_PORTS] = { {31, 18, 20, 30, 21, 22, 26, 25},/* AON gpio cntrlr */ }; +static u32 tegra186_gpio_port_pin_count[MAX_PORTS] = { + 7, 7, 7, 6, 8, 6, 6, 7, 8, 8, 1, 8, 6, 7, 4, 7, + 6, 6, 5, 4, 6, 8, 8, 8, 7, 4, 8, 2, 4, 0, 3, 5, +}; + static u32 address_map[32][2]; static u32 tegra_gpio_bank_count; static struct tegra_gpio_controller @@ -199,6 +204,9 @@ static inline bool is_gpio_accessible(u32 offset) if (controller == -1) return false; + if (pin >= tegra186_gpio_port_pin_count[port]) + return false; + for (i = 0; i < MAX_GPIO_CONTROLLERS; i++) { for (j = 0; j < MAX_GPIO_PORTS; j++) { if (tegra186_gpio_map[i][j] == port) { -- cgit v1.2.2