From patchwork Thu Aug 8 13:25:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 1144029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4648Jd1Fdgz9sDB for ; Thu, 8 Aug 2019 23:25:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbfHHNZw (ORCPT ); Thu, 8 Aug 2019 09:25:52 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:58686 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389561AbfHHNZw (ORCPT ); Thu, 8 Aug 2019 09:25:52 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id D7266A177B; Thu, 8 Aug 2019 15:25:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id XI5cvFhH_S4H; Thu, 8 Aug 2019 15:25:44 +0200 (CEST) From: Stefan Roese To: linux-serial@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andy Shevchenko , Geert Uytterhoeven , Pavel Machek , Linus Walleij , Greg Kroah-Hartman Subject: [PATCH 1/2] gpiolib: Add for_each_gpio_suffix() helper Date: Thu, 8 Aug 2019 15:25:42 +0200 Message-Id: <20190808132543.26274-1-sr@denx.de> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it. Signed-off-by: Stefan Roese Suggested-by: Andy Shevchenko Cc: Andy Shevchenko Cc: Geert Uytterhoeven Cc: Pavel Machek Cc: Linus Walleij Cc: Greg Kroah-Hartman --- drivers/gpio/gpiolib.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 7c52c2442173..a3add73f99d6 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -92,6 +92,12 @@ struct acpi_gpio_info { /* gpio suffixes used for ACPI and device tree lookup */ static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; +#define for_each_gpio_suffix(idx, suffix) \ + for (idx = 0; \ + idx < ARRAY_SIZE(gpio_suffixes) && \ + (suffix = gpio_suffixes[idx]) != NULL; \ + idx++) + #ifdef CONFIG_OF_GPIO struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, From patchwork Thu Aug 8 13:25:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 1144030 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4648Jk6Blxz9sDB for ; Thu, 8 Aug 2019 23:25:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732865AbfHHNZ6 (ORCPT ); Thu, 8 Aug 2019 09:25:58 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:59202 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732643AbfHHNZ6 (ORCPT ); Thu, 8 Aug 2019 09:25:58 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id DCFF0A1749; Thu, 8 Aug 2019 15:25:56 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id UthFW26DoSIi; Thu, 8 Aug 2019 15:25:45 +0200 (CEST) From: Stefan Roese To: linux-serial@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andy Shevchenko , Geert Uytterhoeven , Pavel Machek , Linus Walleij , Greg Kroah-Hartman Subject: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio) Date: Thu, 8 Aug 2019 15:25:43 +0200 Message-Id: <20190808132543.26274-2-sr@denx.de> In-Reply-To: <20190808132543.26274-1-sr@denx.de> References: <20190808132543.26274-1-sr@denx.de> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 Cc: Andy Shevchenko Cc: Geert Uytterhoeven Cc: Pavel Machek Cc: Linus Walleij Cc: Greg Kroah-Hartman --- 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 #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;