All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: unlisted-recipients:; (no To-header on input)@casper.infradead.org
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Nicholas Mc Guire <hofrat@osadl.org>,
	Julia Lawall <Julia.Lawall@lip6.fr>,
	Takeshi Yoshimura <yos@sslab.ics.keio.ac.jp>
Subject: [PATCH 2/6] [media] ddcore: avoid endless loop if readl() fails
Date: Sun,  6 Mar 2016 10:39:18 -0300	[thread overview]
Message-ID: <821b14b0c9c6afc57548c66c6944b101883c345e.1457271549.git.mchehab@osg.samsung.com> (raw)
In-Reply-To: <076989c7736719982a1bc9557d7db072910d8efe.1457271549.git.mchehab@osg.samsung.com>
In-Reply-To: <076989c7736719982a1bc9557d7db072910d8efe.1457271549.git.mchehab@osg.samsung.com>

As warned by smatch:
	drivers/media/pci/ddbridge/ddbridge-core.c:1351 flashio() warn: this loop depends on readl() succeeding
	drivers/media/pci/ddbridge/ddbridge-core.c:1371 flashio() warn: this loop depends on readl() succeeding

Let the loop be interrupted too if something really bad happens
and readl() fails.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
index 6e995ef8c37e..4b85dd0cac3f 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1339,6 +1339,7 @@ static irqreturn_t irq_handler(int irq, void *dev_id)
 static int flashio(struct ddb *dev, u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
 {
 	u32 data, shift;
+	int val;
 
 	if (wlen > 4)
 		ddbwritel(1, SPI_CONTROL);
@@ -1348,8 +1349,9 @@ static int flashio(struct ddb *dev, u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
 		wbuf += 4;
 		wlen -= 4;
 		ddbwritel(data, SPI_DATA);
-		while (ddbreadl(SPI_CONTROL) & 0x0004)
-			;
+		do {
+			val = ddbreadl(SPI_CONTROL);
+		} while (val >= 0 && val & 0x0004);
 	}
 
 	if (rlen)
@@ -1368,8 +1370,9 @@ static int flashio(struct ddb *dev, u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
 	if (shift)
 		data <<= shift;
 	ddbwritel(data, SPI_DATA);
-	while (ddbreadl(SPI_CONTROL) & 0x0004)
-		;
+	do {
+		val = ddbreadl(SPI_CONTROL);
+	} while (val >= 0 && val & 0x0004);
 
 	if (!rlen) {
 		ddbwritel(0, SPI_CONTROL);
@@ -1380,8 +1383,9 @@ static int flashio(struct ddb *dev, u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
 
 	while (rlen > 4) {
 		ddbwritel(0xffffffff, SPI_DATA);
-		while (ddbreadl(SPI_CONTROL) & 0x0004)
-			;
+		do {
+			val = ddbreadl(SPI_CONTROL);
+		} while (val >= 0 && val & 0x0004);
 		data = ddbreadl(SPI_DATA);
 		*(u32 *) rbuf = swab32(data);
 		rbuf += 4;
@@ -1389,8 +1393,9 @@ static int flashio(struct ddb *dev, u8 *wbuf, u32 wlen, u8 *rbuf, u32 rlen)
 	}
 	ddbwritel(0x0003 | ((rlen << (8 + 3)) & 0x1F00), SPI_CONTROL);
 	ddbwritel(0xffffffff, SPI_DATA);
-	while (ddbreadl(SPI_CONTROL) & 0x0004)
-		;
+	do {
+		val = ddbreadl(SPI_CONTROL);
+	} while (val >= 0 && val & 0x0004);
 
 	data = ddbreadl(SPI_DATA);
 	ddbwritel(0, SPI_CONTROL);
-- 
2.5.0


  reply	other threads:[~2016-03-06 13:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Mauro Carvalho Chehab [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=821b14b0c9c6afc57548c66c6944b101883c345e.1457271549.git.mchehab@osg.samsung.com \
    --to=mchehab@osg.samsung.com \
    --cc=Julia.Lawall@lip6.fr \
    --cc=hans.verkuil@cisco.com \
    --cc=hofrat@osadl.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=yos@sslab.ics.keio.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.