linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails
@ 2015-02-12 14:24 Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 2/5] serial: clps711x: fail if " Uwe Kleine-König
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2015-02-12 14:24 UTC (permalink / raw)
  To: linux-arm-kernel

mctrl_gpio_init at present doesn't return NULL. (It might be used in the
future when no gpios are to be used indicating success.) Properly pass
error returned and also make driver probing fail on error.

Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
---
 drivers/tty/serial/atmel_serial.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 4d848a29e223..8a30342dfa7c 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2507,8 +2507,8 @@ static int atmel_init_gpios(struct atmel_uart_port *p, struct device *dev)
 	struct gpio_desc *gpiod;
 
 	p->gpios = mctrl_gpio_init(dev, 0);
-	if (IS_ERR_OR_NULL(p->gpios))
-		return -1;
+	if (IS_ERR(p->gpios))
+		return PTR_ERR(p->gpios);
 
 	for (i = 0; i < UART_GPIO_MAX; i++) {
 		gpiod = mctrl_gpio_to_gpiod(p->gpios, i);
@@ -2559,9 +2559,10 @@ static int atmel_serial_probe(struct platform_device *pdev)
 	port->uart.line = ret;
 
 	ret = atmel_init_gpios(port, &pdev->dev);
-	if (ret < 0)
-		dev_err(&pdev->dev, "%s",
-			"Failed to initialize GPIOs. The serial port may not work as expected");
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to initialize GPIOs.");
+		goto err;
+	}
 
 	ret = atmel_init_port(port, pdev);
 	if (ret)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] serial: clps711x: fail if mctrl_gpio_init fails
  2015-02-12 14:24 [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
@ 2015-02-12 14:24 ` Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 3/5] serial: mxs-auart: properly handle mctrl_gpio failing Uwe Kleine-König
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2015-02-12 14:24 UTC (permalink / raw)
  To: linux-arm-kernel

mctrl_gpio_init is fully aware of being optional. If it returns an error
code this indicates a real error that must not be ignored.

Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
---
 drivers/tty/serial/clps711x.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c
index 6e11c275f2ab..d5d2dd7c7917 100644
--- a/drivers/tty/serial/clps711x.c
+++ b/drivers/tty/serial/clps711x.c
@@ -501,6 +501,8 @@ static int uart_clps711x_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, s);
 
 	s->gpios = mctrl_gpio_init(&pdev->dev, 0);
+	if (IS_ERR(s->gpios))
+	    return PTR_ERR(s->gpios);
 
 	ret = uart_add_one_port(&clps711x_uart, &s->port);
 	if (ret)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] serial: mxs-auart: properly handle mctrl_gpio failing
  2015-02-12 14:24 [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 2/5] serial: clps711x: fail if " Uwe Kleine-König
@ 2015-02-12 14:24 ` Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 4/5] serial: mctrl-gpio: don't check for struct mctrl_gpios * to be invalid Uwe Kleine-König
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2015-02-12 14:24 UTC (permalink / raw)
  To: linux-arm-kernel

If mctrl_gpio_init returns an error code this value should be forwarded and
the driver must not simply ignore this failure.

Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
---
 drivers/tty/serial/mxs-auart.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index ec553f8eb218..14430394985d 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -1157,14 +1157,14 @@ static int serial_mxs_probe_dt(struct mxs_auart_port *s,
 	return 0;
 }
 
-static bool mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev)
+static int mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev)
 {
 	enum mctrl_gpio_idx i;
 	struct gpio_desc *gpiod;
 
 	s->gpios = mctrl_gpio_init(dev, 0);
-	if (IS_ERR_OR_NULL(s->gpios))
-		return false;
+	if (IS_ERR(s->gpios))
+		return PTR_ERR(s->gpios);
 
 	/* Block (enabled before) DMA option if RTS or CTS is GPIO line */
 	if (!RTS_AT_AUART() || !CTS_AT_AUART()) {
@@ -1182,7 +1182,7 @@ static bool mxs_auart_init_gpios(struct mxs_auart_port *s, struct device *dev)
 			s->gpio_irq[i] = -EINVAL;
 	}
 
-	return true;
+	return 0;
 }
 
 static void mxs_auart_free_gpio_irq(struct mxs_auart_port *s)
@@ -1279,9 +1279,11 @@ static int mxs_auart_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, s);
 
-	if (!mxs_auart_init_gpios(s, &pdev->dev))
-		dev_err(&pdev->dev,
-			"Failed to initialize GPIOs. The serial port may not work as expected\n");
+	ret = mxs_auart_init_gpios(s, &pdev->dev);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to initialize GPIOs.\n");
+		got out_free_irq;
+	}
 
 	/*
 	 * Get the GPIO lines IRQ
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] serial: mctrl-gpio: don't check for struct mctrl_gpios * to be invalid
  2015-02-12 14:24 [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 2/5] serial: clps711x: fail if " Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 3/5] serial: mxs-auart: properly handle mctrl_gpio failing Uwe Kleine-König
@ 2015-02-12 14:24 ` Uwe Kleine-König
  2015-02-12 14:24 ` [PATCH 5/5] serial: mctrl-gpio: simplify init routine Uwe Kleine-König
  2015-02-27 20:40 ` [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2015-02-12 14:24 UTC (permalink / raw)
  To: linux-arm-kernel

Drivers using mctrl-gpio must not pass invalid values for struct
mctrl_gpios *. All drivers were fixed in this regard and so some checks
can go away or be simplified.

Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
---
 drivers/tty/serial/serial_mctrl_gpio.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
index a38596c5194e..c0381a09f12d 100644
--- a/drivers/tty/serial/serial_mctrl_gpio.c
+++ b/drivers/tty/serial/serial_mctrl_gpio.c
@@ -48,9 +48,6 @@ void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl)
 	int value_array[UART_GPIO_MAX];
 	unsigned int count = 0;
 
-	if (IS_ERR_OR_NULL(gpios))
-		return;
-
 	for (i = 0; i < UART_GPIO_MAX; i++)
 		if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&
 		    mctrl_gpios_desc[i].dir_out) {
@@ -65,10 +62,7 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);
 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
 				      enum mctrl_gpio_idx gidx)
 {
-	if (!IS_ERR_OR_NULL(gpios) && !IS_ERR_OR_NULL(gpios->gpio[gidx]))
-		return gpios->gpio[gidx];
-	else
-		return NULL;
+	return gpios->gpio[gidx];
 }
 EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
 
@@ -76,15 +70,8 @@ unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl)
 {
 	enum mctrl_gpio_idx i;
 
-	/*
-	 * return it unchanged if the structure is not allocated
-	 */
-	if (IS_ERR_OR_NULL(gpios))
-		return *mctrl;
-
 	for (i = 0; i < UART_GPIO_MAX; i++) {
-		if (!IS_ERR_OR_NULL(gpios->gpio[i]) &&
-		    !mctrl_gpios_desc[i].dir_out) {
+		if (gpios->gpio[i] && !mctrl_gpios_desc[i].dir_out) {
 			if (gpiod_get_value(gpios->gpio[i]))
 				*mctrl |= mctrl_gpios_desc[i].mctrl;
 			else
@@ -138,9 +125,6 @@ void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios)
 {
 	enum mctrl_gpio_idx i;
 
-	if (IS_ERR_OR_NULL(gpios))
-		return;
-
 	for (i = 0; i < UART_GPIO_MAX; i++)
 		if (!IS_ERR_OR_NULL(gpios->gpio[i]))
 			devm_gpiod_put(dev, gpios->gpio[i]);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] serial: mctrl-gpio: simplify init routine
  2015-02-12 14:24 [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2015-02-12 14:24 ` [PATCH 4/5] serial: mctrl-gpio: don't check for struct mctrl_gpios * to be invalid Uwe Kleine-König
@ 2015-02-12 14:24 ` Uwe Kleine-König
  2015-02-27 20:40 ` [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
  4 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2015-02-12 14:24 UTC (permalink / raw)
  To: linux-arm-kernel

Instead of ignoring errors returned by devm_gpiod_get_index use
devm_gpiod_get_index_optional which results in slightly more strict
error handling which is good.

Also use the fourth parameter to devm_gpiod_get_index_optional to be
able to drop the explicit direction setting.

Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
---
 drivers/tty/serial/serial_mctrl_gpio.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
index c0381a09f12d..5027db7b5814 100644
--- a/drivers/tty/serial/serial_mctrl_gpio.c
+++ b/drivers/tty/serial/serial_mctrl_gpio.c
@@ -94,27 +94,20 @@ struct mctrl_gpios *mctrl_gpio_init(struct device *dev, unsigned int idx)
 		return ERR_PTR(-ENOMEM);
 
 	for (i = 0; i < UART_GPIO_MAX; i++) {
-		gpios->gpio[i] = devm_gpiod_get_index(dev,
-						      mctrl_gpios_desc[i].name,
-						      idx);
-
-		/*
-		 * The GPIOs are maybe not all filled,
-		 * this is not an error.
-		 */
-		if (IS_ERR_OR_NULL(gpios->gpio[i]))
-			continue;
+		enum gpiod_flags flags;
 
 		if (mctrl_gpios_desc[i].dir_out)
-			err = gpiod_direction_output(gpios->gpio[i], 0);
+			flags = GPIOD_OUT_LOW;
 		else
-			err = gpiod_direction_input(gpios->gpio[i]);
-		if (err) {
-			dev_dbg(dev, "Unable to set direction for %s GPIO",
-				mctrl_gpios_desc[i].name);
-			devm_gpiod_put(dev, gpios->gpio[i]);
-			gpios->gpio[i] = NULL;
-		}
+			flags = GPIOD_IN;
+
+		gpios->gpio[i] =
+			devm_gpiod_get_index_optional(dev,
+						      mctrl_gpios_desc[i].name,
+						      idx, flags);
+
+		if (IS_ERR(gpios->gpio[i]))
+			return PTR_ERR(gpios->gpio[i]);
 	}
 
 	return gpios;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails
  2015-02-12 14:24 [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
                   ` (3 preceding siblings ...)
  2015-02-12 14:24 ` [PATCH 5/5] serial: mctrl-gpio: simplify init routine Uwe Kleine-König
@ 2015-02-27 20:40 ` Uwe Kleine-König
  2015-02-27 20:49   ` Greg Kroah-Hartman
  4 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2015-02-27 20:40 UTC (permalink / raw)
  To: linux-arm-kernel

Hello Greg,

probably it's just me being impatient, but I wonder about not getting
any feedback for the several patches I sent for drivers/tty/serial.

Are you just not yet in patch-collecting mode for 4.1? Although the
patches in this series might even be post-merge-window material.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails
  2015-02-27 20:40 ` [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
@ 2015-02-27 20:49   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2015-02-27 20:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Feb 27, 2015 at 09:40:18PM +0100, Uwe Kleine-K?nig wrote:
> Hello Greg,
> 
> probably it's just me being impatient, but I wonder about not getting
> any feedback for the several patches I sent for drivers/tty/serial.
> 
> Are you just not yet in patch-collecting mode for 4.1? Although the
> patches in this series might even be post-merge-window material.

I'm not in a patch-collecting mode for tty/serial drivers for 4.1 just
yet, sorry, I hope to get to them next week.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-27 20:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-12 14:24 [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
2015-02-12 14:24 ` [PATCH 2/5] serial: clps711x: fail if " Uwe Kleine-König
2015-02-12 14:24 ` [PATCH 3/5] serial: mxs-auart: properly handle mctrl_gpio failing Uwe Kleine-König
2015-02-12 14:24 ` [PATCH 4/5] serial: mctrl-gpio: don't check for struct mctrl_gpios * to be invalid Uwe Kleine-König
2015-02-12 14:24 ` [PATCH 5/5] serial: mctrl-gpio: simplify init routine Uwe Kleine-König
2015-02-27 20:40 ` [PATCH 1/5] serial: atmel: fix error handling when mctrl_gpio_init fails Uwe Kleine-König
2015-02-27 20:49   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).