Skip to contentSkip to conversation

staging: speakup: prefer usleep_range over udelay

PATCH In review Payal Kshirsagar 2 participants 3 messages Mar 18, 2019 – Mar 19, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: speakup: prefer usleep_range over udelay

Since usleep_range is built on top of hrtimers, the wakeup will be very precise (ish), thus a simple usleep function would likely introduce a large number of undesired interrupts.
Thus udelay replaced with usleep_range.

---
 drivers/staging/speakup/speakup_decpc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/speakup/speakup_decpc.c +7 -7
index 798c42d..10ca19b 100644
@@ -251,7 +251,7 @@ static int dt_waitbit(int bit)
 	while (--timeout > 0) {
 		if ((dt_getstatus() & bit) == bit)
 			return 1;
-		udelay(50);
+		usleep_range(50, 50 + 10);
 	}
 	return 0;
 }
@@ -265,7 +265,7 @@ static int dt_wait_dma(void)
 	while (--timeout > 0) {
 		if ((dt_getstatus() & STAT_dma_state) == state)
 			return 1;
-		udelay(50);
+		usleep_range(50, 50 + 10);
 	}
 	dma_state = dt_getstatus() & STAT_dma_state;
 	return 1;
@@ -283,7 +283,7 @@ static int dt_ctrl(u_int cmd)
 	dt_sendcmd(CMD_control | cmd);
 	outb_p(0, speakup_info.port_tts + 6);
 	while (dt_getstatus() & STAT_cmd_ready) {
-		udelay(20);
+		usleep_range(20, 20 + 10);
 		if (--timeout == 0)
 			break;
 	}
@@ -302,20 +302,20 @@ static void synth_flush(struct spk_synth *synth)
 	while (dt_ctrl(CTRL_flush)) {
 		if (--timeout == 0)
 			break;
-		udelay(50);
+		usleep_range(50, 50 + 10);
 	}
 	for (timeout = 0; timeout < 10; timeout++) {
 		if (dt_waitbit(STAT_dma_ready))
 			break;
-		udelay(50);
+		usleep_range(50, 50 + 10);
 	}
 	outb_p(DMA_sync, speakup_info.port_tts + 4);
 	outb_p(0, speakup_info.port_tts + 4);
-	udelay(100);
+	usleep_range(100, 100 + 10);
 	for (timeout = 0; timeout < 10; timeout++) {
 		if (!(dt_getstatus() & STAT_flushing))
 			break;
-		udelay(50);
+		usleep_range(50, 50 + 10);
 	}
 	dma_state = dt_getstatus() & STAT_dma_state;
 	dma_state ^= STAT_dma_state;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 16 lines · Payal Kshirsagar

Since usleep_range is built on top of hrtimers, the wakeup will be very precise (ish), thus a simple usleep function would likely introduce a large number of undesired interrupts.
Thus udelay replaced with usleep_range.

---
 drivers/staging/speakup/speakup_decpc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/speakup/speakup_decpc.c +0 -0
index 798c42d..10ca19b 100644

drivers/staging/speakup/speakup_decpc.c static int dt_waitbit(int bit) · line 254

Quoted 5 lines
drivers/staging/speakup/speakup_decpc.c +1 -1
@@ -251,7 +251,7 @@ static int dt_waitbit(int bit)
 	while (--timeout > 0) {
 		if ((dt_getstatus() & bit) == bit)
 			return 1;
-		udelay(50);
+		usleep_range(50, 50 + 10);

I've said this in the past, only do this type of change if you can actually test it, and know it will be ok. For some stuff like this, it _might_ be ok, but you just expanded the timeout range potentially a lot longer than before, and do we know that is ok?

I sure do not :)

So just leave these things alone unless you know the hardware will keep working properly.

thanks,

greg k-h

#2 lore raw
Quoted 29 lines · Greg KH
Quoted 6 lines · Payal Kshirsagar

Since usleep_range is built on top of hrtimers, the wakeup will be very precise (ish), thus a simple usleep function would likely introduce a large number of undesired interrupts.
Thus udelay replaced with usleep_range.

Review

Quoted 6 lines
---
 drivers/staging/speakup/speakup_decpc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/speakup/speakup_decpc.c

drivers/staging/speakup/speakup_decpc.c static int dt_waitbit(int bit) · line 254

Quoted 9 lines

index 798c42d..10ca19b 100644

drivers/staging/speakup/speakup_decpc.c +1 -1
@@ -251,7 +251,7 @@ static int dt_waitbit(int bit)
      while (--timeout > 0) {
              if ((dt_getstatus() & bit) == bit)
                      return 1;
-             udelay(50);
+             usleep_range(50, 50 + 10);

I've said this in the past, only do this type of change if you can actually test it, and know it will be ok. For some stuff like this, it _might_ be ok, but you just expanded the timeout range potentially a lot longer than before, and do we know that is ok?

Quoted 9 lines

I sure do not :)

So just leave these things alone unless you know the hardware will keep working properly.

thanks,

greg k-h

Okay I'll drop this patch .
Regards,
Payal

Quoted 1 line