[PATCH 4/35] W1: w1_process, allow wakeup in sleep

From: David Fries
Date: Fri Mar 28 2008 - 08:53:35 EST


w1.c 1.7 1.8
msleep_interruptible only wakes for signals, but we don't use them.
We want kthread_stop to wake it up, so call schedule_timeout
ourselves. This is prep-work for blocking when there isn't anything to do, instead of sleeping in a loop, as something has to be able to
wake it up.
Added a check for termination after the bus search, otherwise it would
sleep for the full time value if kthread_stop was called while
w1_process was in the bus search. This would cause a deadlock when it
is blocking instead of sleeping with a timeout.

Signed-off-by: David Fries <david@xxxxxxxxx>
---
drivers/w1/w1.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 9a09f3a..ad89d85 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -810,6 +810,10 @@ void w1_search_process(struct w1_master *dev, u8 search_type)
int w1_process(void *data)
{
struct w1_master *dev = (struct w1_master *) data;
+ /* As long as w1_timeout is only set by a module parameter the sleep
+ * time can be calculated in jiffies once.
+ */
+ const unsigned long jtime=msecs_to_jiffies(w1_timeout * 1000);

while (!kthread_should_stop() && !test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
if(dev->search_count) {
@@ -819,7 +823,12 @@ int w1_process(void *data)
}

try_to_freeze();
- msleep_interruptible(w1_timeout * 1000);
+ __set_current_state(TASK_INTERRUPTIBLE);
+
+ if(kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
+ break;
+
+ schedule_timeout(jtime);
}

atomic_dec(&dev->refcnt);
--
1.4.4.4

Attachment: pgp00000.pgp
Description: PGP signature