w1: fixup search to support abort from netlink
Before63706172f3
"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.9d1817cab2
"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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
6b355b33a6
commit
4210569876
@@ -960,8 +960,7 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb
|
|||||||
tmp64 = (triplet_ret >> 2);
|
tmp64 = (triplet_ret >> 2);
|
||||||
rn |= (tmp64 << i);
|
rn |= (tmp64 << i);
|
||||||
|
|
||||||
/* ensure we're called from kthread and not by netlink callback */
|
if (test_bit(W1_ABORT_SEARCH, &dev->flags)) {
|
||||||
if (!dev->priv && kthread_should_stop()) {
|
|
||||||
mutex_unlock(&dev->bus_mutex);
|
mutex_unlock(&dev->bus_mutex);
|
||||||
dev_dbg(&dev->dev, "Abort w1_search\n");
|
dev_dbg(&dev->dev, "Abort w1_search\n");
|
||||||
return;
|
return;
|
||||||
|
@@ -155,6 +155,14 @@ struct w1_bus_master
|
|||||||
u8, w1_slave_found_callback);
|
u8, w1_slave_found_callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enum w1_master_flags - bitfields used in w1_master.flags
|
||||||
|
* @W1_ABORT_SEARCH: abort searching early on shutdown
|
||||||
|
*/
|
||||||
|
enum w1_master_flags {
|
||||||
|
W1_ABORT_SEARCH = 0,
|
||||||
|
};
|
||||||
|
|
||||||
struct w1_master
|
struct w1_master
|
||||||
{
|
{
|
||||||
struct list_head w1_master_entry;
|
struct list_head w1_master_entry;
|
||||||
@@ -178,6 +186,8 @@ struct w1_master
|
|||||||
/** 5V strong pullup duration in milliseconds, zero disabled. */
|
/** 5V strong pullup duration in milliseconds, zero disabled. */
|
||||||
int pullup_duration;
|
int pullup_duration;
|
||||||
|
|
||||||
|
long flags;
|
||||||
|
|
||||||
struct task_struct *thread;
|
struct task_struct *thread;
|
||||||
struct mutex mutex;
|
struct mutex mutex;
|
||||||
struct mutex bus_mutex;
|
struct mutex bus_mutex;
|
||||||
|
@@ -172,6 +172,7 @@ int w1_add_master_device(struct w1_bus_master *master)
|
|||||||
|
|
||||||
#if 0 /* Thread cleanup code, not required currently. */
|
#if 0 /* Thread cleanup code, not required currently. */
|
||||||
err_out_kill_thread:
|
err_out_kill_thread:
|
||||||
|
set_bit(W1_ABORT_SEARCH, &dev->flags);
|
||||||
kthread_stop(dev->thread);
|
kthread_stop(dev->thread);
|
||||||
#endif
|
#endif
|
||||||
err_out_rm_attr:
|
err_out_rm_attr:
|
||||||
@@ -187,6 +188,7 @@ void __w1_remove_master_device(struct w1_master *dev)
|
|||||||
struct w1_netlink_msg msg;
|
struct w1_netlink_msg msg;
|
||||||
struct w1_slave *sl, *sln;
|
struct w1_slave *sl, *sln;
|
||||||
|
|
||||||
|
set_bit(W1_ABORT_SEARCH, &dev->flags);
|
||||||
kthread_stop(dev->thread);
|
kthread_stop(dev->thread);
|
||||||
|
|
||||||
mutex_lock(&w1_mlock);
|
mutex_lock(&w1_mlock);
|
||||||
|
Reference in New Issue
Block a user