aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Fries <David@Fries.net>2014-01-15 23:29:13 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-07 18:40:17 -0500
commit421056987620fecb43c22c558e127085c406b7ba (patch)
tree12b735281e22323f036b87f010d11ea8addb2af0
parent6b355b33a64fd6d8ead2b838ec16fb9b551f71e8 (diff)
w1: fixup search to support abort from netlink
Before 63706172f33 "rework kthread_stop()" kthread_should_stop() always returned false when called from a non-kthread task, after it would oops as a non-kthread didn't have that structure and netlink was calling search from a thread which wasn't a kthread. 9d1817cab2f030 "w1: fix oops when w1_search is called from netlink connector", modified the code to avoid calling kthread_stop from a netlink thread. Introduce a w1_master flag and bit W1_ABORT_SEARCH to identify abort to cleanly support both kthread and netlink search abort. A search can take seconds to run, so it is important to abort early if the hardware is removed in the middle of a search. Signed-off-by: David Fries <David@Fries.net> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Cc: Marcin Jurkowski <marcin1j@gmail.com> Cc: Josh Boyer <jwboyer@gmail.com> Cc: Sven Geggus <lists@fuchsschwanzdomain.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/w1/w1.c3
-rw-r--r--drivers/w1/w1.h10
-rw-r--r--drivers/w1/w1_int.c2
3 files changed, 13 insertions, 2 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 66efa96c4603..67b6d5fb25bc 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -960,8 +960,7 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb
960 tmp64 = (triplet_ret >> 2); 960 tmp64 = (triplet_ret >> 2);
961 rn |= (tmp64 << i); 961 rn |= (tmp64 << i);
962 962
963 /* ensure we're called from kthread and not by netlink callback */ 963 if (test_bit(W1_ABORT_SEARCH, &dev->flags)) {
964 if (!dev->priv && kthread_should_stop()) {
965 mutex_unlock(&dev->bus_mutex); 964 mutex_unlock(&dev->bus_mutex);
966 dev_dbg(&dev->dev, "Abort w1_search\n"); 965 dev_dbg(&dev->dev, "Abort w1_search\n");
967 return; 966 return;
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index ca8081a101d6..bc329d2bba28 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -155,6 +155,14 @@ struct w1_bus_master
155 u8, w1_slave_found_callback); 155 u8, w1_slave_found_callback);
156}; 156};
157 157
158/**
159 * enum w1_master_flags - bitfields used in w1_master.flags
160 * @W1_ABORT_SEARCH: abort searching early on shutdown
161 */
162enum w1_master_flags {
163 W1_ABORT_SEARCH = 0,
164};
165
158struct w1_master 166struct w1_master
159{ 167{
160 struct list_head w1_master_entry; 168 struct list_head w1_master_entry;
@@ -178,6 +186,8 @@ struct w1_master
178 /** 5V strong pullup duration in milliseconds, zero disabled. */ 186 /** 5V strong pullup duration in milliseconds, zero disabled. */
179 int pullup_duration; 187 int pullup_duration;
180 188
189 long flags;
190
181 struct task_struct *thread; 191 struct task_struct *thread;
182 struct mutex mutex; 192 struct mutex mutex;
183 struct mutex bus_mutex; 193 struct mutex bus_mutex;
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 590bd8a7cd1b..423f3c2b9e7d 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -172,6 +172,7 @@ int w1_add_master_device(struct w1_bus_master *master)
172 172
173#if 0 /* Thread cleanup code, not required currently. */ 173#if 0 /* Thread cleanup code, not required currently. */
174err_out_kill_thread: 174err_out_kill_thread:
175 set_bit(W1_ABORT_SEARCH, &dev->flags);
175 kthread_stop(dev->thread); 176 kthread_stop(dev->thread);
176#endif 177#endif
177err_out_rm_attr: 178err_out_rm_attr:
@@ -187,6 +188,7 @@ void __w1_remove_master_device(struct w1_master *dev)
187 struct w1_netlink_msg msg; 188 struct w1_netlink_msg msg;
188 struct w1_slave *sl, *sln; 189 struct w1_slave *sl, *sln;
189 190
191 set_bit(W1_ABORT_SEARCH, &dev->flags);
190 kthread_stop(dev->thread); 192 kthread_stop(dev->thread);
191 193
192 mutex_lock(&w1_mlock); 194 mutex_lock(&w1_mlock);