calypso/uart.c: Fix array bounds checking
[osmocom-bb.git] / src / target / firmware / calypso / uart.c
index a46fff9..bcb56bd 100644 (file)
@@ -33,7 +33,7 @@
 #include <comm/sercomm.h>
 
 #include <calypso/irq.h>
-#include <calypso/uart.h>
+#include <uart.h>
 
 #define BASE_ADDR_UART_MODEM   0xffff5000
 #define OFFSET_IRDA            0x800
@@ -43,7 +43,7 @@
 #define LCR7BIT                0x80
 #define LCRBFBIT       0x40
 #define MCR6BIT                0x20
-#define REG_OFFS(m)    ((m) &= ~(LCR7BIT|LCRBFBIT|MCR6BIT))
+#define REG_OFFS(m)    ((m) & ~(LCR7BIT|LCRBFBIT|MCR6BIT))
 /* read access LCR[7] = 0 */
 enum uart_reg {
        RHR     = 0,
@@ -127,12 +127,12 @@ static void uart_set_lcr7bit(int uart, int on)
 static uint8_t old_lcr;
 static void uart_set_lcr_bf(int uart, int on)
 {
-       old_lcr = readb(UART_REG(uart, LCR));
-
-       if (on)
+       if (on) {
+               old_lcr = readb(UART_REG(uart, LCR));
                writeb(0xBF, UART_REG(uart, LCR));
-       else
+       } else {
                writeb(old_lcr, UART_REG(uart, LCR));
+       }
 }
 
 /* Enable or disable the TCR_TLR latch bit in MCR[6] */
@@ -427,7 +427,7 @@ int uart_baudrate(uint8_t uart, enum uart_baudrate bdrt)
 {
        uint16_t div;
 
-       if (bdrt > ARRAY_SIZE(divider))
+       if (bdrt >= ARRAY_SIZE(divider))
                return -1;
 
        div = divider[bdrt];