linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] char: pcmcia: cm4000_cs: Replace mdelay with usleep_range in set_protocol
@ 2018-03-18 14:49 Jia-Ju Bai
  2018-03-18 15:12 ` Harald Welte
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2018-03-18 14:49 UTC (permalink / raw)
  To: laforge; +Cc: linux-kernel, Jia-Ju Bai

set_protocol() is never called in atomic context.

The call chains ending up at set_protocol() are:
[1] set_protocol() <- monitor_card()
[2] set_protocol() <- cmm_ioctl()
monitor_card() is only set in setup_timer(), and cmm_ioctl() is only 
set as ".unlocked_ioctl" in file_operations structure "cm4000_fops".

Despite never getting called from atomic context, set_protocol() calls
mdelay(10), i.e. busy wait for 10ms.
That is not necessary and can be replaced with usleep_range to 
avoid busy waiting.

This is found by a static analysis tool named DCNS written by myself.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/char/pcmcia/cm4000_cs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index cd53771..56fc671 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -530,7 +530,7 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
 			DEBUGP(5, dev, "NumRecBytes is valid\n");
 			break;
 		}
-		mdelay(10);
+		usleep_range(10000, 11000);
 	}
 	if (i == 100) {
 		DEBUGP(5, dev, "Timeout waiting for NumRecBytes getting "
@@ -546,7 +546,7 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
 			DEBUGP(2, dev, "NumRecBytes = %i\n", num_bytes_read);
 			break;
 		}
-		mdelay(10);
+		usleep_range(10000, 11000);
 	}
 
 	/* check whether it is a short PTS reply? */
-- 
1.9.1

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

* Re: [PATCH] char: pcmcia: cm4000_cs: Replace mdelay with usleep_range in set_protocol
  2018-03-18 14:49 [PATCH] char: pcmcia: cm4000_cs: Replace mdelay with usleep_range in set_protocol Jia-Ju Bai
@ 2018-03-18 15:12 ` Harald Welte
  2018-10-01  9:32   ` Dominik Brodowski
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Welte @ 2018-03-18 15:12 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: linux-kernel

Hi Jia-Ju Bai,

On Sun, Mar 18, 2018 at 10:49:57PM +0800, Jia-Ju Bai wrote:
> This is found by a static analysis tool named DCNS written by myself.

nice catch!

> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Acked-by: Harald Welte <laforge@gnumonks.org>

-- 
- Harald Welte <laforge@gnumonks.org>           http://laforge.gnumonks.org/
============================================================================
"Privacy in residential applications is a desirable marketing option."
                                                  (ETSI EN 300 175-7 Ch. A6)

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

* Re: [PATCH] char: pcmcia: cm4000_cs: Replace mdelay with usleep_range in set_protocol
  2018-03-18 15:12 ` Harald Welte
@ 2018-10-01  9:32   ` Dominik Brodowski
  0 siblings, 0 replies; 3+ messages in thread
From: Dominik Brodowski @ 2018-10-01  9:32 UTC (permalink / raw)
  To: Harald Welte; +Cc: Jia-Ju Bai, linux-kernel

On Sun, Mar 18, 2018 at 04:12:10PM +0100, Harald Welte wrote:
> Hi Jia-Ju Bai,
> 
> On Sun, Mar 18, 2018 at 10:49:57PM +0800, Jia-Ju Bai wrote:
> > This is found by a static analysis tool named DCNS written by myself.
> 
> nice catch!
> 
> > Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> 
> Acked-by: Harald Welte <laforge@gnumonks.org>

Applied to pcmcia-next.

Thanks,
	Dominik

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

end of thread, other threads:[~2018-10-01 11:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18 14:49 [PATCH] char: pcmcia: cm4000_cs: Replace mdelay with usleep_range in set_protocol Jia-Ju Bai
2018-03-18 15:12 ` Harald Welte
2018-10-01  9:32   ` Dominik Brodowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).