Patchwork [6/6] mtd/ps3vram: Use msleep in waits

login
register
mail settings
Submitter Geoff Levand
Date Jan. 6, 2009, 9:32 p.m.
Message ID <4963CDF4.1070403@am.sony.com>
Download mbox | patch
Permalink /patch/16874/
State New
Headers show

Comments

Geoff Levand - Jan. 6, 2009, 9:32 p.m.
Replace the use of udelay() with msleep() in the looping wait routines
ps3vram_notifier_wait() and ps3vram_wait_ring().

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
---
 drivers/mtd/devices/ps3vram.c |   36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)
Arnd Bergmann - Jan. 7, 2009, 7:25 p.m.
On Tuesday 06 January 2009, Geoff Levand wrote:
>         do {
> -               if (notify[3] == 0)
> +               if (!notify[3])
>                         return 0;
> -
> -               if (timeout_ms)
> -                       udelay(1);
> +               msleep(1);
>         } while (timeout_ms--);
>  

I guess it's not really important, but this function might wait substantially
longer than requested. If you have CONFIG_HZ=100, msleep(1) will sleep for
at least 10 miliseconds. The correct way to sleep for up to a given amount
of time is to calculate the end time in jiffies, and use time_before() in
the loop condition.

	Arnd <><

Patch

--- a/drivers/mtd/devices/ps3vram.c
+++ b/drivers/mtd/devices/ps3vram.c
@@ -109,22 +109,18 @@  static void ps3vram_notifier_reset(struc
 		notify[i] = 0xffffffff;
 }
 
-static int ps3vram_notifier_wait(struct mtd_info *mtd, int timeout_ms)
+static int ps3vram_notifier_wait(struct mtd_info *mtd, unsigned int timeout_ms)
 {
 	struct ps3vram_priv *priv = mtd->priv;
 	u32 *notify = ps3vram_get_notifier(priv->reports, NOTIFIER);
 
-	timeout_ms *= 1000;
-
 	do {
-		if (notify[3] == 0)
+		if (!notify[3])
 			return 0;
-
-		if (timeout_ms)
-			udelay(1);
+		msleep(1);
 	} while (timeout_ms--);
 
-	return -1;
+	return -ETIMEDOUT;
 }
 
 static void ps3vram_init_ring(struct mtd_info *mtd)
@@ -135,25 +131,21 @@  static void ps3vram_init_ring(struct mtd
 	priv->ctrl[CTRL_GET] = FIFO_BASE + FIFO_OFFSET;
 }
 
-static int ps3vram_wait_ring(struct mtd_info *mtd, int timeout)
+static int ps3vram_wait_ring(struct mtd_info *mtd, unsigned int timeout_ms)
 {
 	struct ps3vram_priv *priv = mtd->priv;
 
-	/* wait until setup commands are processed */
-	timeout *= 1000;
-	while (--timeout) {
+	do {
 		if (priv->ctrl[CTRL_PUT] == priv->ctrl[CTRL_GET])
-			break;
-		udelay(1);
-	}
-	if (timeout == 0) {
-		dev_dbg(priv->dev, "%s:%d: FIFO timeout (%08x/%08x/%08x)\n",
-			__func__, __LINE__, priv->ctrl[CTRL_PUT],
-			priv->ctrl[CTRL_GET], priv->ctrl[CTRL_TOP]);
-		return -ETIMEDOUT;
-	}
+			return 0;
+		msleep(1);
+	} while (timeout_ms--);
 
-	return 0;
+	dev_dbg(priv->dev, "%s:%d: FIFO timeout (%08x/%08x/%08x)\n", __func__,
+		__LINE__, priv->ctrl[CTRL_PUT], priv->ctrl[CTRL_GET],
+		priv->ctrl[CTRL_TOP]);
+
+	return -ETIMEDOUT;
 }
 
 static void ps3vram_out_ring(struct ps3vram_priv *priv, u32 data)