Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: linux-serial@vger.kernel.org
Cc: linux-gpio@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Pavel Machek <pavel@denx.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH v2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)
Date: Thu, 15 Aug 2019 10:53:41 +0200	[thread overview]
Message-ID: <20190815085341.28088-1-sr@denx.de> (raw)

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 using gpiod_count() which iterates
over all supported GPIO suffixes (thanks to Linus for suggesting this).

With this change, the local string is not needed any more. This way
we can remove the allocation in the loop.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Pavel Machek <pavel@denx.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v2
- Use gpiod_count() to check if the GPIO exists (Linus)
- Remove the now unnecessary malloc in the loop (kasprintf)

 drivers/tty/serial/serial_mctrl_gpio.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
index 2b400189be91..ce73b142c66b 100644
--- a/drivers/tty/serial/serial_mctrl_gpio.c
+++ b/drivers/tty/serial/serial_mctrl_gpio.c
@@ -117,18 +117,11 @@ 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;
-		bool present;
+		int count;
 
 		/* 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)
+		count = gpiod_count(dev, mctrl_gpios_desc[i].name);
+		if (count <= 0)
 			continue;
 
 		if (mctrl_gpios_desc[i].dir_out)
-- 
2.22.1


             reply	other threads:[~2019-08-15  8:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-15  8:53 Stefan Roese [this message]
2019-08-15  9:44 ` [PATCH v2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio) Linus Walleij
2019-08-16  7:16 ` Geert Uytterhoeven
2019-08-21  8:26   ` Uwe Kleine-König
2019-08-21  8:08 ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190815085341.28088-1-sr@denx.de \
    --to=sr@denx.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=pavel@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox