All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-arm] [PATCH] char: cadence: check divider against baud rate
@ 2016-10-18  9:47 ` P J P
  0 siblings, 0 replies; 24+ messages in thread
From: P J P @ 2016-10-18  9:47 UTC (permalink / raw)
  To: Qemu Developers; +Cc: qemu-arm, Huawei PSIRT, Prasad J Pandit, Alistair Francis

From: Prasad J Pandit <pjp@fedoraproject.org>

The Cadence UART device emulator calculates speed by dividing the
baud rate by a divider. If this divider was to be zero or if baud
rate was to be lesser than the divider, it could lead to a divide
by zero error. Add check to avoid it.

Reported-by: Huawei PSIRT <psirt@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/char/cadence_uart.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index e3bc52f..b18dd7f 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -170,6 +170,10 @@ static void uart_parameters_setup(CadenceUARTState *s)
     baud_rate = (s->r[R_MR] & UART_MR_CLKS) ?
             UART_INPUT_CLK / 8 : UART_INPUT_CLK;
 
+    if (!s->r[R_BRGR] || !(s->r[R_BDIV] + 1)
+        || baud_rate < (s->r[R_BRGR] * (s->r[R_BDIV] + 1))) {
+        return;
+    }
     ssp.speed = baud_rate / (s->r[R_BRGR] * (s->r[R_BDIV] + 1));
     packet_size = 1;
 
-- 
2.7.4


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

end of thread, other threads:[~2016-10-25  0:29 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18  9:47 [Qemu-arm] [PATCH] char: cadence: check divider against baud rate P J P
2016-10-18  9:47 ` [Qemu-devel] " P J P
2016-10-18  9:50 ` [Qemu-arm] " Peter Maydell
2016-10-18  9:50   ` [Qemu-devel] " Peter Maydell
2016-10-18 18:46   ` P J P
2016-10-18 18:46     ` [Qemu-devel] " P J P
2016-10-19  9:49     ` [Qemu-arm] [Qemu-devel] " Alistair Francis
2016-10-19  9:49       ` [Qemu-devel] [Qemu-arm] " Alistair Francis
2016-10-19 10:11       ` [Qemu-arm] [Qemu-devel] " P J P
2016-10-19 10:11         ` [Qemu-devel] [Qemu-arm] " P J P
2016-10-19 13:42         ` [Qemu-arm] [Qemu-devel] " Alistair Francis
2016-10-19 13:42           ` [Qemu-devel] [Qemu-arm] " Alistair Francis
2016-10-20  5:55           ` [Qemu-arm] [Qemu-devel] " P J P
2016-10-20  5:55             ` [Qemu-devel] [Qemu-arm] " P J P
2016-10-20 17:21             ` [Qemu-arm] [Qemu-devel] " Edgar E. Iglesias
2016-10-20 17:21               ` [Qemu-devel] [Qemu-arm] " Edgar E. Iglesias
2016-10-21  7:47               ` [Qemu-arm] [Qemu-devel] " P J P
2016-10-21  7:47                 ` [Qemu-devel] [Qemu-arm] " P J P
2016-10-24  7:46                 ` [Qemu-arm] [Qemu-devel] " Alistair Francis
2016-10-24  7:46                   ` [Qemu-devel] [Qemu-arm] " Alistair Francis
2016-10-24 13:25                   ` [Qemu-arm] [Qemu-devel] " P J P
2016-10-24 13:25                     ` [Qemu-devel] [Qemu-arm] " P J P
2016-10-25  0:28                     ` [Qemu-arm] [Qemu-devel] " Alistair Francis
2016-10-25  0:28                       ` [Qemu-devel] [Qemu-arm] " Alistair Francis

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.