All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Fries <David@Fries.net>
To: linux-kernel@vger.kernel.org
Cc: Evgeniy Polyakov <zbr@ioremap.net>,
	Marcin Jurkowski <marcin1j@gmail.com>,
	Josh Boyer <jwboyer@gmail.com>,
	Sven Geggus <lists@fuchsschwanzdomain.de>
Subject: [PATCH 02/14] w1: fixup search to support abort from netlink
Date: Sun, 29 Dec 2013 00:45:44 -0600	[thread overview]
Message-ID: <1388299556-12669-3-git-send-email-David@Fries.net> (raw)
In-Reply-To: <1388299556-12669-1-git-send-email-David@Fries.net>

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>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Marcin Jurkowski <marcin1j@gmail.com>
Cc: Josh Boyer <jwboyer@gmail.com>
Cc: Sven Geggus <lists@fuchsschwanzdomain.de>
---
 drivers/w1/w1.c     |    3 +--
 drivers/w1/w1.h     |   10 ++++++++++
 drivers/w1/w1_int.c |    2 ++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 66efa96..67b6d5f 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
 			tmp64 = (triplet_ret >> 2);
 			rn |= (tmp64 << i);
 
-			/* ensure we're called from kthread and not by netlink callback */
-			if (!dev->priv && kthread_should_stop()) {
+			if (test_bit(W1_ABORT_SEARCH, &dev->flags)) {
 				mutex_unlock(&dev->bus_mutex);
 				dev_dbg(&dev->dev, "Abort w1_search\n");
 				return;
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index ca8081a..bc329d2 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -155,6 +155,14 @@ struct w1_bus_master
 		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 list_head	w1_master_entry;
@@ -178,6 +186,8 @@ struct w1_master
 	/** 5V strong pullup duration in milliseconds, zero disabled. */
 	int			pullup_duration;
 
+	long			flags;
+
 	struct task_struct	*thread;
 	struct mutex		mutex;
 	struct mutex		bus_mutex;
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 590bd8a..423f3c2 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)
 
 #if 0 /* Thread cleanup code, not required currently. */
 err_out_kill_thread:
+	set_bit(W1_ABORT_SEARCH, &dev->flags);
 	kthread_stop(dev->thread);
 #endif
 err_out_rm_attr:
@@ -187,6 +188,7 @@ void __w1_remove_master_device(struct w1_master *dev)
 	struct w1_netlink_msg msg;
 	struct w1_slave *sl, *sln;
 
+	set_bit(W1_ABORT_SEARCH, &dev->flags);
 	kthread_stop(dev->thread);
 
 	mutex_lock(&w1_mlock);
-- 
1.7.10.4


  parent reply	other threads:[~2013-12-29  6:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-29  6:45 [PATCH 00/14] w1: async netlink, search, fixes, and improvements David Fries
2013-12-29  6:45 ` [PATCH 01/14] w1: fix w1_send_slave dropping a slave id David Fries
2013-12-29  6:45 ` David Fries [this message]
2013-12-29  6:45 ` [PATCH 03/14] w1: Only wake up the search process if it is going to be searching David Fries
2013-12-29  6:45 ` [PATCH 04/14] w1: increase w1_max_slave_count, allow write access David Fries
2013-12-29  6:45 ` [PATCH 05/14] w1: continue slave search where previous left off David Fries
2013-12-29  6:45 ` [PATCH 06/14] w1: new netlink commands, add/remove/list slaves David Fries
2013-12-29  6:45 ` [PATCH 07/14] w1: process w1 netlink commands in w1_process thread David Fries
2013-12-29  6:45 ` [PATCH 08/14] connector: add portid to unicast in addition to broadcasting David Fries
2013-12-29  6:45 ` [PATCH 09/14] w1: reply only to the requester portid David Fries
2013-12-29  6:45 ` [PATCH 10/14] w1: ds2490 reduce magic numbers David Fries
2013-12-29  6:45 ` [PATCH 11/14] w1: ds2490 USB setup fixes David Fries
2013-12-29  6:45 ` [PATCH 12/14] w1: ds2490 fix and enable hardware search David Fries
2013-12-29  6:45 ` [PATCH 13/14] w1: use family_data instead of rom in w1_slave David Fries
2013-12-29  6:45 ` [PATCH 14/14] w1: format for DocBook and fixes David Fries
2013-12-29 21:26 ` [PATCH 00/14] w1: async netlink, search, fixes, and improvements Evgeniy Polyakov
2014-01-15  4:52 ` [PATCH 16/16] hold bus_mutex in netlink and search David Fries
2014-01-15 20:58   ` Evgeniy Polyakov
2014-01-15 21:10     ` David Fries
2014-01-16  2:33       ` GregKH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388299556-12669-3-git-send-email-David@Fries.net \
    --to=david@fries.net \
    --cc=jwboyer@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lists@fuchsschwanzdomain.de \
    --cc=marcin1j@gmail.com \
    --cc=zbr@ioremap.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.