All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] [media] mantis: check for errors on readl inside loop
@ 2016-03-06 13:39 Mauro Carvalho Chehab
  2016-03-06 13:39 ` [PATCH 2/6] [media] ddcore: avoid endless loop if readl() fails Mauro Carvalho Chehab
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Mauro Carvalho Chehab @ 2016-03-06 13:39 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab, Jan Klötzke

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

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);
 	}
-- 
2.5.0


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

end of thread, other threads:[~2016-03-07  8:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-06 13:39 [PATCH 1/6] [media] mantis: check for errors on readl inside loop Mauro Carvalho Chehab
2016-03-06 13:39 ` [PATCH 2/6] [media] ddcore: avoid endless loop if readl() fails Mauro Carvalho Chehab
2016-03-06 13:39 ` [PATCH 3/6] [media] mceusb: use %*ph for small buffer dumps Mauro Carvalho Chehab
2016-03-06 13:39 ` [PATCH 4/6] [media] st-rc: prevent a endless loop Mauro Carvalho Chehab
2016-03-06 13:39   ` Mauro Carvalho Chehab
2016-03-07  8:16   ` Patrice Chotard
2016-03-07  8:16     ` Patrice Chotard
2016-03-06 13:39 ` [PATCH 5/6] [media] touptek: don't DMA at the stack Mauro Carvalho Chehab
2016-03-06 13:39 ` [PATCH 6/6] [media] touptek: cast char types on %x printk Mauro Carvalho Chehab

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.