linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix a division by zero
@ 2014-09-23 19:54 Frans Klaver
  2014-09-23 19:54 ` [PATCH 1/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-23 19:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

Hi Greg,

Here's a couple of patches that fix a divison by zero in omap-serial.c. One's a
cleanup, the other the actual fix.

Thanks,
Frans

Frans Klaver (2):
  tty: omap-serial: pull out calculation from baud_is_mode16
  tty: omap-serial: fix a division by zero

 drivers/tty/serial/omap-serial.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

-- 
2.1.0


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

* [PATCH 1/2] tty: omap-serial: pull out calculation from baud_is_mode16
  2014-09-23 19:54 [PATCH 0/2] Fix a division by zero Frans Klaver
@ 2014-09-23 19:54 ` Frans Klaver
  2014-09-23 19:54 ` [PATCH 2/2] tty: omap-serial: fix a division by zero Frans Klaver
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-23 19:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

To determine the correct divisor, we need to know the difference between
the desired baud rate and the actual baud rate. The calculation for this
difference is implemented twice within omap_serial_baud_is_mode16().
Pull out the calculation for easier maintenance.

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
 drivers/tty/serial/omap-serial.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index d017cec..ae935ce 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -239,6 +239,22 @@ static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable)
 }
 
 /*
+ * Calculate the absolute difference between the desired and actual baud
+ * rate for the given mode.
+ */
+static inline int calculate_baud_abs_diff(struct uart_port *port,
+				unsigned int baud, unsigned int mode)
+{
+	unsigned int n = port->uartclk / (mode * baud);
+	int abs_diff = baud - (port->uartclk / (mode * n));
+
+	if (abs_diff < 0)
+		abs_diff = -abs_diff;
+
+	return abs_diff;
+}
+
+/*
  * serial_omap_baud_is_mode16 - check if baud rate is MODE16X
  * @port: uart port info
  * @baud: baudrate for which mode needs to be determined
@@ -252,14 +268,8 @@ static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable)
 static bool
 serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
 {
-	unsigned int n13 = port->uartclk / (13 * baud);
-	unsigned int n16 = port->uartclk / (16 * baud);
-	int baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
-	int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
-	if (baudAbsDiff13 < 0)
-		baudAbsDiff13 = -baudAbsDiff13;
-	if (baudAbsDiff16 < 0)
-		baudAbsDiff16 = -baudAbsDiff16;
+	int baudAbsDiff13 = calculate_baud_abs_diff(port, baud, 13);
+	int baudAbsDiff16 = calculate_baud_abs_diff(port, baud, 16);
 
 	return (baudAbsDiff13 >= baudAbsDiff16);
 }
-- 
2.1.0


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

* [PATCH 2/2] tty: omap-serial: fix a division by zero
  2014-09-23 19:54 [PATCH 0/2] Fix a division by zero Frans Klaver
  2014-09-23 19:54 ` [PATCH 1/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
@ 2014-09-23 19:54 ` Frans Klaver
  2014-09-23 21:58 ` [PATCH 0/2] Fix " Greg Kroah-Hartman
  2014-09-24  7:55 ` [PATCH v2 0/2] Frans Klaver
  3 siblings, 0 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-23 19:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
calculated n values in calculate_baud_abs_diff may become 0. This causes
a division by zero when calculating the difference between calculated
and desired baud rates. To prevent this, cap n on 1.

Division by zero in kernel.
[<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
[<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
[<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
[<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
[<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
[<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
[<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
[<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
[<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
[<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
[<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
[<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
[<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
 drivers/tty/serial/omap-serial.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index ae935ce..7d3f557 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -246,8 +246,12 @@ static inline int calculate_baud_abs_diff(struct uart_port *port,
 				unsigned int baud, unsigned int mode)
 {
 	unsigned int n = port->uartclk / (mode * baud);
-	int abs_diff = baud - (port->uartclk / (mode * n));
+	int abs_diff;
 
+	if (n == 0)
+		n = 1;
+
+	abs_diff = baud - (port->uartclk / (mode * n));
 	if (abs_diff < 0)
 		abs_diff = -abs_diff;
 
-- 
2.1.0


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

* Re: [PATCH 0/2] Fix a division by zero
  2014-09-23 19:54 [PATCH 0/2] Fix a division by zero Frans Klaver
  2014-09-23 19:54 ` [PATCH 1/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
  2014-09-23 19:54 ` [PATCH 2/2] tty: omap-serial: fix a division by zero Frans Klaver
@ 2014-09-23 21:58 ` Greg Kroah-Hartman
  2014-09-24  7:55 ` [PATCH v2 0/2] Frans Klaver
  3 siblings, 0 replies; 13+ messages in thread
From: Greg Kroah-Hartman @ 2014-09-23 21:58 UTC (permalink / raw)
  To: Frans Klaver; +Cc: Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Tue, Sep 23, 2014 at 09:54:38PM +0200, Frans Klaver wrote:
> Hi Greg,
> 
> Here's a couple of patches that fix a divison by zero in omap-serial.c. One's a
> cleanup, the other the actual fix.

So both would be needed to be backported to stable kernels?  Why not
just do the fix first, then the cleanup afterward, to make backporting
easier?

thanks,

greg k-h

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

* [PATCH v2 0/2]
  2014-09-23 19:54 [PATCH 0/2] Fix a division by zero Frans Klaver
                   ` (2 preceding siblings ...)
  2014-09-23 21:58 ` [PATCH 0/2] Fix " Greg Kroah-Hartman
@ 2014-09-24  7:55 ` Frans Klaver
  2014-09-24  7:55   ` [PATCH 1/2] tty: omap-serial: fix division by zero Frans Klaver
  2014-09-24  7:55   ` [PATCH 2/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
  3 siblings, 2 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-24  7:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Tue, Sep 23, 2014 at 11:58 PM, Greg Kroah-Hartman wrote:
> So both would be needed to be backported to stable kernels?  Why not
> just do the fix first, then the cleanup afterward, to make backporting
> easier?

Sure thing. I read something about cleaning up first, then actually changing
stuff, but it doesn't really make sense to move bugs around before fixing them,
unless fixing them requires moving them around.

Anyway, here's the respin.

v1..v2:
  - swapped fix and cleanup to ease backporting

Frans Klaver (2):
  tty: omap-serial: fix division by zero
  tty: omap-serial: pull out calculation from baud_is_mode16

 drivers/tty/serial/omap-serial.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

-- 
2.1.0


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

* [PATCH 1/2] tty: omap-serial: fix division by zero
  2014-09-24  7:55 ` [PATCH v2 0/2] Frans Klaver
@ 2014-09-24  7:55   ` Frans Klaver
  2014-09-24  8:08     ` Greg Kroah-Hartman
  2014-09-24  7:55   ` [PATCH 2/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
  1 sibling, 1 reply; 13+ messages in thread
From: Frans Klaver @ 2014-09-24  7:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
calculated n values in serial_omap_is_baud_mode16() may become 0. This
causes a division by zero when calculating the difference between
calculated and desired baud rates. To prevent this, cap the n13 and n16
values on 1.

Division by zero in kernel.
[<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
[<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
[<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
[<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
[<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
[<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
[<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
[<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
[<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
[<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
[<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
[<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
[<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
 drivers/tty/serial/omap-serial.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index d017cec..e454b7c 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -254,8 +254,16 @@ serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
 {
 	unsigned int n13 = port->uartclk / (13 * baud);
 	unsigned int n16 = port->uartclk / (16 * baud);
-	int baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
-	int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
+	int baudAbsDiff13;
+	int baudAbsDiff16;
+
+	if (n13 == 0)
+		n13 = 1;
+	if (n16 == 0)
+		n16 = 1;
+
+	baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
+	baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
 	if (baudAbsDiff13 < 0)
 		baudAbsDiff13 = -baudAbsDiff13;
 	if (baudAbsDiff16 < 0)
-- 
2.1.0


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

* [PATCH 2/2] tty: omap-serial: pull out calculation from baud_is_mode16
  2014-09-24  7:55 ` [PATCH v2 0/2] Frans Klaver
  2014-09-24  7:55   ` [PATCH 1/2] tty: omap-serial: fix division by zero Frans Klaver
@ 2014-09-24  7:55   ` Frans Klaver
  1 sibling, 0 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-24  7:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

To determine the correct divisor, we need to know the difference between
the desired baud rate and the actual baud rate. The calculation for this
difference is implemented twice within omap_serial_baud_is_mode16().
Pull out the calculation for easier maintenance.

While at it, remove the CamelCasing from the variable names.

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
 drivers/tty/serial/omap-serial.c | 42 +++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index e454b7c..18c30ca 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -239,6 +239,26 @@ static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable)
 }
 
 /*
+ * Calculate the absolute difference between the desired and actual baud
+ * rate for the given mode.
+ */
+static inline int calculate_baud_abs_diff(struct uart_port *port,
+				unsigned int baud, unsigned int mode)
+{
+	unsigned int n = port->uartclk / (mode * baud);
+	int abs_diff;
+
+	if (n == 0)
+		n = 1;
+
+	abs_diff = baud - (port->uartclk / (mode * n));
+	if (abs_diff < 0)
+		abs_diff = -abs_diff;
+
+	return abs_diff;
+}
+
+/*
  * serial_omap_baud_is_mode16 - check if baud rate is MODE16X
  * @port: uart port info
  * @baud: baudrate for which mode needs to be determined
@@ -252,24 +272,10 @@ static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable)
 static bool
 serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
 {
-	unsigned int n13 = port->uartclk / (13 * baud);
-	unsigned int n16 = port->uartclk / (16 * baud);
-	int baudAbsDiff13;
-	int baudAbsDiff16;
-
-	if (n13 == 0)
-		n13 = 1;
-	if (n16 == 0)
-		n16 = 1;
-
-	baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
-	baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
-	if (baudAbsDiff13 < 0)
-		baudAbsDiff13 = -baudAbsDiff13;
-	if (baudAbsDiff16 < 0)
-		baudAbsDiff16 = -baudAbsDiff16;
-
-	return (baudAbsDiff13 >= baudAbsDiff16);
+	int abs_diff_13 = calculate_baud_abs_diff(port, baud, 13);
+	int abs_diff_16 = calculate_baud_abs_diff(port, baud, 16);
+
+	return (abs_diff_13 >= abs_diff_16);
 }
 
 /*
-- 
2.1.0


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

* Re: [PATCH 1/2] tty: omap-serial: fix division by zero
  2014-09-24  7:55   ` [PATCH 1/2] tty: omap-serial: fix division by zero Frans Klaver
@ 2014-09-24  8:08     ` Greg Kroah-Hartman
  2014-09-24  8:41       ` Frans Klaver
  2014-09-25  9:19       ` [PATCH resend " Frans Klaver
  0 siblings, 2 replies; 13+ messages in thread
From: Greg Kroah-Hartman @ 2014-09-24  8:08 UTC (permalink / raw)
  To: Frans Klaver; +Cc: Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Wed, Sep 24, 2014 at 09:55:21AM +0200, Frans Klaver wrote:
> If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
> calculated n values in serial_omap_is_baud_mode16() may become 0. This
> causes a division by zero when calculating the difference between
> calculated and desired baud rates. To prevent this, cap the n13 and n16
> values on 1.
> 
> Division by zero in kernel.
> [<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
> [<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
> [<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
> [<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
> [<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
> [<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
> [<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
> [<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
> [<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
> [<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
> [<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
> [<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
> [<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)
> 
> Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> ---
>  drivers/tty/serial/omap-serial.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)

Should this go to the stable kernel trees as well?

thanks,

greg k-h

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

* Re: [PATCH 1/2] tty: omap-serial: fix division by zero
  2014-09-24  8:08     ` Greg Kroah-Hartman
@ 2014-09-24  8:41       ` Frans Klaver
  2014-09-24  9:09         ` Frans Klaver
  2014-09-25  9:19       ` [PATCH resend " Frans Klaver
  1 sibling, 1 reply; 13+ messages in thread
From: Frans Klaver @ 2014-09-24  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Wed, Sep 24, 2014 at 01:08:52AM -0700, Greg Kroah-Hartman wrote:
> On Wed, Sep 24, 2014 at 09:55:21AM +0200, Frans Klaver wrote:
> > If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
> > calculated n values in serial_omap_is_baud_mode16() may become 0. This
> > causes a division by zero when calculating the difference between
> > calculated and desired baud rates. To prevent this, cap the n13 and n16
> > values on 1.
> > 
> > Division by zero in kernel.
> > [<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
> > [<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
> > [<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
> > [<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
> > [<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
> > [<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
> > [<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
> > [<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
> > [<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
> > [<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
> > [<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
> > [<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
> > [<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)
> > 
> > Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> > ---
> >  drivers/tty/serial/omap-serial.c | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> Should this go to the stable kernel trees as well?

It's been there for a while. Introduced in 5fe2123647c1508 "OMAP/serial:
Support 1Mbaud and similar baudrates that require Mode16 instead of
Mode13" (v3.9). It's probably a good idea to do so. stable@... needs a
cc?

Frans

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

* Re: [PATCH 1/2] tty: omap-serial: fix division by zero
  2014-09-24  8:41       ` Frans Klaver
@ 2014-09-24  9:09         ` Frans Klaver
  0 siblings, 0 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-24  9:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Wed, Sep 24, 2014 at 10:41:11AM +0200, Frans Klaver wrote:
> On Wed, Sep 24, 2014 at 01:08:52AM -0700, Greg Kroah-Hartman wrote:
> > On Wed, Sep 24, 2014 at 09:55:21AM +0200, Frans Klaver wrote:
> > > If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
> > > calculated n values in serial_omap_is_baud_mode16() may become 0. This
> > > causes a division by zero when calculating the difference between
> > > calculated and desired baud rates. To prevent this, cap the n13 and n16
> > > values on 1.
> > > 
> > > Division by zero in kernel.
> > > [<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
> > > [<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
> > > [<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
> > > [<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
> > > [<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
> > > [<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
> > > [<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
> > > [<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
> > > [<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
> > > [<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
> > > [<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
> > > [<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
> > > [<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)
> > > 
> > > Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> > > ---
> > >  drivers/tty/serial/omap-serial.c | 12 ++++++++++--
> > >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > Should this go to the stable kernel trees as well?
> 
> It's been there for a while. Introduced in 5fe2123647c1508 "OMAP/serial:
> Support 1Mbaud and similar baudrates that require Mode16 instead of
> Mode13" (v3.9). It's probably a good idea to do so. stable@... needs a
> cc?

And would it be enough to just resend this particular patch in that
case?

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

* [PATCH resend 1/2] tty: omap-serial: fix division by zero
  2014-09-24  8:08     ` Greg Kroah-Hartman
  2014-09-24  8:41       ` Frans Klaver
@ 2014-09-25  9:19       ` Frans Klaver
  2014-09-25 10:16         ` Greg Kroah-Hartman
  1 sibling, 1 reply; 13+ messages in thread
From: Frans Klaver @ 2014-09-25  9:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: stable, Frans Klaver, Jiri Slaby, linux-serial, linux-kernel, linux-omap

If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
calculated n values in serial_omap_is_baud_mode16() may become 0. This
causes a division by zero when calculating the difference between
calculated and desired baud rates. To prevent this, cap the n13 and n16
values on 1.

Division by zero in kernel.
[<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
[<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
[<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
[<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
[<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
[<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
[<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
[<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
[<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
[<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
[<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
[<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
[<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
Resend to add stable@vger.kernel.org to CC. As far as I know, this applies to
v3.9 and up.

Thanks,
Frans

 drivers/tty/serial/omap-serial.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index d017cec..e454b7c 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -254,8 +254,16 @@ serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
 {
 	unsigned int n13 = port->uartclk / (13 * baud);
 	unsigned int n16 = port->uartclk / (16 * baud);
-	int baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
-	int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
+	int baudAbsDiff13;
+	int baudAbsDiff16;
+
+	if (n13 == 0)
+		n13 = 1;
+	if (n16 == 0)
+		n16 = 1;
+
+	baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
+	baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
 	if (baudAbsDiff13 < 0)
 		baudAbsDiff13 = -baudAbsDiff13;
 	if (baudAbsDiff16 < 0)
-- 
2.1.0


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

* Re: [PATCH resend 1/2] tty: omap-serial: fix division by zero
  2014-09-25  9:19       ` [PATCH resend " Frans Klaver
@ 2014-09-25 10:16         ` Greg Kroah-Hartman
  2014-09-25 10:24           ` Frans Klaver
  0 siblings, 1 reply; 13+ messages in thread
From: Greg Kroah-Hartman @ 2014-09-25 10:16 UTC (permalink / raw)
  To: Frans Klaver; +Cc: stable, Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Thu, Sep 25, 2014 at 11:19:51AM +0200, Frans Klaver wrote:
> If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
> calculated n values in serial_omap_is_baud_mode16() may become 0. This
> causes a division by zero when calculating the difference between
> calculated and desired baud rates. To prevent this, cap the n13 and n16
> values on 1.
> 
> Division by zero in kernel.
> [<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
> [<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
> [<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
> [<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
> [<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
> [<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
> [<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
> [<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
> [<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
> [<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
> [<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
> [<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
> [<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)
> 
> Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> ---
> Resend to add stable@vger.kernel.org to CC. As far as I know, this applies to
> v3.9 and up.

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
for how to do this properly.

</formletter>

I'll take care of this, but go read that file for your next time...

greg k-h

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

* Re: [PATCH resend 1/2] tty: omap-serial: fix division by zero
  2014-09-25 10:16         ` Greg Kroah-Hartman
@ 2014-09-25 10:24           ` Frans Klaver
  0 siblings, 0 replies; 13+ messages in thread
From: Frans Klaver @ 2014-09-25 10:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: stable, Jiri Slaby, linux-serial, linux-kernel, linux-omap

On Thu, Sep 25, 2014 at 12:16:28PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Sep 25, 2014 at 11:19:51AM +0200, Frans Klaver wrote:
> > If the chosen baud rate is large enough (e.g. 3.5 megabaud), the
> > calculated n values in serial_omap_is_baud_mode16() may become 0. This
> > causes a division by zero when calculating the difference between
> > calculated and desired baud rates. To prevent this, cap the n13 and n16
> > values on 1.
> > 
> > Division by zero in kernel.
> > [<c00132e0>] (unwind_backtrace) from [<c00112ec>] (show_stack+0x10/0x14)
> > [<c00112ec>] (show_stack) from [<c01ed7bc>] (Ldiv0+0x8/0x10)
> > [<c01ed7bc>] (Ldiv0) from [<c023805c>] (serial_omap_baud_is_mode16+0x4c/0x68)
> > [<c023805c>] (serial_omap_baud_is_mode16) from [<c02396b4>] (serial_omap_set_termios+0x90/0x8d8)
> > [<c02396b4>] (serial_omap_set_termios) from [<c0230a0c>] (uart_change_speed+0xa4/0xa8)
> > [<c0230a0c>] (uart_change_speed) from [<c0231798>] (uart_set_termios+0xa0/0x1fc)
> > [<c0231798>] (uart_set_termios) from [<c022bb44>] (tty_set_termios+0x248/0x2c0)
> > [<c022bb44>] (tty_set_termios) from [<c022c17c>] (set_termios+0x248/0x29c)
> > [<c022c17c>] (set_termios) from [<c022c3e4>] (tty_mode_ioctl+0x1c8/0x4e8)
> > [<c022c3e4>] (tty_mode_ioctl) from [<c0227e70>] (tty_ioctl+0xa94/0xb18)
> > [<c0227e70>] (tty_ioctl) from [<c00cf45c>] (do_vfs_ioctl+0x4a0/0x560)
> > [<c00cf45c>] (do_vfs_ioctl) from [<c00cf568>] (SyS_ioctl+0x4c/0x74)
> > [<c00cf568>] (SyS_ioctl) from [<c000e480>] (ret_fast_syscall+0x0/0x30)
> > 
> > Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> > ---
> > Resend to add stable@vger.kernel.org to CC. As far as I know, this applies to
> > v3.9 and up.
> 
> <formletter>
> 
> This is not the correct way to submit patches for inclusion in the
> stable kernel tree.  Please read Documentation/stable_kernel_rules.txt
> for how to do this properly.
> 
> </formletter>
> 
> I'll take care of this, but go read that file for your next time...

Ah, right. I'll heed that next time. Thanks for taking care of it.

Frans

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

end of thread, other threads:[~2014-09-25 10:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-23 19:54 [PATCH 0/2] Fix a division by zero Frans Klaver
2014-09-23 19:54 ` [PATCH 1/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
2014-09-23 19:54 ` [PATCH 2/2] tty: omap-serial: fix a division by zero Frans Klaver
2014-09-23 21:58 ` [PATCH 0/2] Fix " Greg Kroah-Hartman
2014-09-24  7:55 ` [PATCH v2 0/2] Frans Klaver
2014-09-24  7:55   ` [PATCH 1/2] tty: omap-serial: fix division by zero Frans Klaver
2014-09-24  8:08     ` Greg Kroah-Hartman
2014-09-24  8:41       ` Frans Klaver
2014-09-24  9:09         ` Frans Klaver
2014-09-25  9:19       ` [PATCH resend " Frans Klaver
2014-09-25 10:16         ` Greg Kroah-Hartman
2014-09-25 10:24           ` Frans Klaver
2014-09-24  7:55   ` [PATCH 2/2] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver

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