[1/6,media] mantis: check for errors on readl inside loop
diff mbox

Message ID 076989c7736719982a1bc9557d7db072910d8efe.1457271549.git.mchehab@osg.samsung.com
State New
Headers show

Commit Message

Mauro Carvalho Chehab March 6, 2016, 1:39 p.m. UTC
As warned by smatch:
	drivers/media/pci/mantis/mantis_uart.c:105 mantis_uart_work() warn: this loop depends on readl() succeeding

If readl() fails, this could lead into an endless loop. Avoid that.
We might instead add some timeout logic, but it readl() is
failing, then something really wrong is happening.

While here, remove two defines that are only used once.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/pci/mantis/mantis_common.h | 7 ++-----
 drivers/media/pci/mantis/mantis_uart.c   | 4 ++--
 2 files changed, 4 insertions(+), 7 deletions(-)

Patch
diff mbox

diff --git a/drivers/media/pci/mantis/mantis_common.h b/drivers/media/pci/mantis/mantis_common.h
index d48778a366a9..8348c5de3d18 100644
--- a/drivers/media/pci/mantis/mantis_common.h
+++ b/drivers/media/pci/mantis/mantis_common.h
@@ -54,11 +54,8 @@ 
 	}												\
 } while(0)
 
-#define mwrite(dat, addr)	writel((dat), addr)
-#define mread(addr)		readl(addr)
-
-#define mmwrite(dat, addr)	mwrite((dat), (mantis->mmio + (addr)))
-#define mmread(addr)		mread(mantis->mmio + (addr))
+#define mmwrite(dat, addr)	writel((dat), (mantis->mmio + (addr)))
+#define mmread(addr)		readl(mantis->mmio + (addr))
 
 #define MANTIS_TS_188		0
 #define MANTIS_TS_204		1
diff --git a/drivers/media/pci/mantis/mantis_uart.c b/drivers/media/pci/mantis/mantis_uart.c
index f1c96aec8c7b..95ccc34be9fd 100644
--- a/drivers/media/pci/mantis/mantis_uart.c
+++ b/drivers/media/pci/mantis/mantis_uart.c
@@ -91,7 +91,7 @@  static void mantis_uart_read(struct mantis_pci *mantis)
 static void mantis_uart_work(struct work_struct *work)
 {
 	struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work);
-	u32 stat;
+	int stat;
 
 	stat = mmread(MANTIS_UART_STAT);
 
@@ -102,7 +102,7 @@  static void mantis_uart_work(struct work_struct *work)
 	 * MANTIS_UART_RXFIFO_DATA is only set if at least
 	 * config->bytes + 1 bytes are in the FIFO.
 	 */
-	while (stat & MANTIS_UART_RXFIFO_DATA) {
+	while ((stat >= 0) && (stat & MANTIS_UART_RXFIFO_DATA)) {
 		mantis_uart_read(mantis);
 		stat = mmread(MANTIS_UART_STAT);
 	}