All of lore.kernel.org
 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

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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.