linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer
@ 2019-10-06 16:33 Adam Ford
  2019-10-06 16:33 ` [PATCH V2 2/2] serial: 8250_omap: Fix gpio check for auto RTS/CTS Adam Ford
  2019-10-06 18:11 ` [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer Yegor Yefremov
  0 siblings, 2 replies; 4+ messages in thread
From: Adam Ford @ 2019-10-06 16:33 UTC (permalink / raw)
  To: linux-serial
  Cc: Adam Ford, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Vignesh R, Mika Westerberg, Douglas Anderson, Tony Lindgren,
	Yegor Yefremov, linux-kernel

When using mctrl_gpio_to_gpiod, it dereferences gpios into a single
requested GPIO.  This dereferencing can break if gpios is NULL,
so this patch adds a NULL check before dereferencing it.  If
gpios is NULL, this function will also return NULL.

Signed-off-by: Adam Ford <aford173@gmail.com>
---
V2:  This patch is new to the V2 of this series, so patch 2/2 can 
     work without risking a NULL dereference
diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
index d9074303c88e..fb4781292d40 100644
--- a/drivers/tty/serial/serial_mctrl_gpio.c
+++ b/drivers/tty/serial/serial_mctrl_gpio.c
@@ -66,6 +66,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);
 struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
 				      enum mctrl_gpio_idx gidx)
 {
+	if (gpios == NULL)
+		return NULL;
+
 	return gpios->gpio[gidx];
 }
 EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
-- 
2.17.1


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

* [PATCH V2 2/2] serial: 8250_omap: Fix gpio check for auto RTS/CTS
  2019-10-06 16:33 [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer Adam Ford
@ 2019-10-06 16:33 ` Adam Ford
  2019-10-06 18:11   ` Yegor Yefremov
  2019-10-06 18:11 ` [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer Yegor Yefremov
  1 sibling, 1 reply; 4+ messages in thread
From: Adam Ford @ 2019-10-06 16:33 UTC (permalink / raw)
  To: linux-serial
  Cc: Adam Ford, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Vignesh R, Mika Westerberg, Douglas Anderson, Tony Lindgren,
	Yegor Yefremov, linux-kernel

There are two checks to see if the manual gpio is configured, but
these the check is seeing if the structure is NULL instead it
should check to see if there are CTS and/or RTS pins defined.

This patch uses checks for those individual pins instead of
checking for the structure itself to restore auto RTS/CTS.

Signed-off-by: Adam Ford <aford173@gmail.com>
---
V2:  Made the NULL dererence check from patch 1/2 come before this.

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c68e2b3a1634..836e736ae188 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
 
 	serial8250_do_set_mctrl(port, mctrl);
 
-	if (!up->gpios) {
+	if (!mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS)) {
 		/*
 		 * Turn off autoRTS if RTS is lowered and restore autoRTS
 		 * setting if RTS is raised
@@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port,
 	up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF);
 
 	if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW &&
-	    !up->gpios) {
+	    !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS) &&
+	    !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_CTS)) {
 		/* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */
 		up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS;
 		priv->efr |= UART_EFR_CTS;
-- 
2.17.1


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

* Re: [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer
  2019-10-06 16:33 [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer Adam Ford
  2019-10-06 16:33 ` [PATCH V2 2/2] serial: 8250_omap: Fix gpio check for auto RTS/CTS Adam Ford
@ 2019-10-06 18:11 ` Yegor Yefremov
  1 sibling, 0 replies; 4+ messages in thread
From: Yegor Yefremov @ 2019-10-06 18:11 UTC (permalink / raw)
  To: Adam Ford
  Cc: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Vignesh R, Mika Westerberg, Douglas Anderson, Tony Lindgren,
	kernel list

On Sun, Oct 6, 2019 at 6:33 PM Adam Ford <aford173@gmail.com> wrote:
>
> When using mctrl_gpio_to_gpiod, it dereferences gpios into a single
> requested GPIO.  This dereferencing can break if gpios is NULL,
> so this patch adds a NULL check before dereferencing it.  If
> gpios is NULL, this function will also return NULL.
>
> Signed-off-by: Adam Ford <aford173@gmail.com>

Reviewed-by: Yegor Yefremov <yegorslists@googlemail.com>

> ---
> V2:  This patch is new to the V2 of this series, so patch 2/2 can
>      work without risking a NULL dereference
> diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
> index d9074303c88e..fb4781292d40 100644
> --- a/drivers/tty/serial/serial_mctrl_gpio.c
> +++ b/drivers/tty/serial/serial_mctrl_gpio.c
> @@ -66,6 +66,9 @@ EXPORT_SYMBOL_GPL(mctrl_gpio_set);
>  struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios,
>                                       enum mctrl_gpio_idx gidx)
>  {
> +       if (gpios == NULL)
> +               return NULL;
> +
>         return gpios->gpio[gidx];
>  }
>  EXPORT_SYMBOL_GPL(mctrl_gpio_to_gpiod);
> --
> 2.17.1
>

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

* Re: [PATCH V2 2/2] serial: 8250_omap: Fix gpio check for auto RTS/CTS
  2019-10-06 16:33 ` [PATCH V2 2/2] serial: 8250_omap: Fix gpio check for auto RTS/CTS Adam Ford
@ 2019-10-06 18:11   ` Yegor Yefremov
  0 siblings, 0 replies; 4+ messages in thread
From: Yegor Yefremov @ 2019-10-06 18:11 UTC (permalink / raw)
  To: Adam Ford
  Cc: linux-serial, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Vignesh R, Mika Westerberg, Douglas Anderson, Tony Lindgren,
	kernel list

On Sun, Oct 6, 2019 at 6:33 PM Adam Ford <aford173@gmail.com> wrote:
>
> There are two checks to see if the manual gpio is configured, but
> these the check is seeing if the structure is NULL instead it
> should check to see if there are CTS and/or RTS pins defined.
>
> This patch uses checks for those individual pins instead of
> checking for the structure itself to restore auto RTS/CTS.
>
> Signed-off-by: Adam Ford <aford173@gmail.com>

Reviewed-by: Yegor Yefremov <yegorslists@googlemail.com>

> ---
> V2:  Made the NULL dererence check from patch 1/2 come before this.
>
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index c68e2b3a1634..836e736ae188 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -141,7 +141,7 @@ static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
>
>         serial8250_do_set_mctrl(port, mctrl);
>
> -       if (!up->gpios) {
> +       if (!mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS)) {
>                 /*
>                  * Turn off autoRTS if RTS is lowered and restore autoRTS
>                  * setting if RTS is raised
> @@ -456,7 +456,8 @@ static void omap_8250_set_termios(struct uart_port *port,
>         up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF);
>
>         if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW &&
> -           !up->gpios) {
> +           !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS) &&
> +           !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_CTS)) {
>                 /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */
>                 up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS;
>                 priv->efr |= UART_EFR_CTS;
> --
> 2.17.1
>

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

end of thread, other threads:[~2019-10-06 18:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-06 16:33 [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer Adam Ford
2019-10-06 16:33 ` [PATCH V2 2/2] serial: 8250_omap: Fix gpio check for auto RTS/CTS Adam Ford
2019-10-06 18:11   ` Yegor Yefremov
2019-10-06 18:11 ` [PATCH V2 1/2] serial: mctrl_gpio: Check for NULL pointer Yegor Yefremov

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).