This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial: mctrl_gpio: Check if GPIO property exisits before requesting it"). This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper. Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure. Signed-off-by: Stefan Roese <sr@xxxxxxx> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Cc: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> Cc: Pavel Machek <pavel@xxxxxxx> Cc: Linus Walleij <linus.walleij@xxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/tty/serial/serial_mctrl_gpio.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c index 2b400189be91..d444fdaa280a 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -15,6 +15,7 @@ #include <linux/property.h> #include "serial_mctrl_gpio.h" +#include "../../gpio/gpiolib.h" struct mctrl_gpios { struct uart_port *port; @@ -117,17 +118,24 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) for (i = 0; i < UART_GPIO_MAX; i++) { enum gpiod_flags flags; - char *gpio_str; + const char *suffix; + char gpio_str[32]; /* 32 is max size of property name */ bool present; + int k; + + /* + * Check if GPIO property exists and continue if not. Iterate + * over all supported GPIO suffixes (foo-gpios vs. foo-gpio). + */ + for_each_gpio_suffix(k, suffix) { + snprintf(gpio_str, sizeof(gpio_str), "%s-%s", + mctrl_gpios_desc[i].name, suffix); + + present = device_property_present(dev, gpio_str); + if (present) + break; + } - /* Check if GPIO property exists and continue if not */ - gpio_str = kasprintf(GFP_KERNEL, "%s-gpios", - mctrl_gpios_desc[i].name); - if (!gpio_str) - continue; - - present = device_property_present(dev, gpio_str); - kfree(gpio_str); if (!present) continue; -- 2.22.0