mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tomeu Vizoso <tomeu.vizoso@collabora.com>
To: linux-pm@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	martyn.welch@collabora.co.uk,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Daniel Kurtz <djkurtz@chromium.org>
Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v12 1/4] device core: add device_is_bound()
Date: Thu,  7 Jan 2016 16:46:12 +0100	[thread overview]
Message-ID: <1452181575-9206-2-git-send-email-tomeu.vizoso@collabora.com> (raw)
In-Reply-To: <1452181575-9206-1-git-send-email-tomeu.vizoso@collabora.com>

Adds a function that tells whether a device is already bound to a
driver.

This is needed to warn when there is an attempt to change the PM domain
of a device that has finished probing already. The reason why we want to
enforce that is because in the general case that can cause problems and
also that we can simplify code quite a bit if we can always assume that.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---

Changes in v9:
- Add docs noting the need for the device lock to be held before calling
  device_is_bound()

Changes in v8:
- Add device_is_bound()

 drivers/base/dd.c      | 18 ++++++++++++++++--
 include/linux/device.h |  2 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7399be790b5d..13a0d66e5782 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -223,9 +223,23 @@ static int deferred_probe_initcall(void)
 }
 late_initcall(deferred_probe_initcall);
 
+/**
+ * device_is_bound() - Check if device is bound to a driver
+ * @dev: device to check
+ *
+ * Returns true if passed device has already finished probing successfully
+ * against a driver.
+ *
+ * This function must be called with the device lock held.
+ */
+bool device_is_bound(struct device *dev)
+{
+	return klist_node_attached(&dev->p->knode_driver);
+}
+
 static void driver_bound(struct device *dev)
 {
-	if (klist_node_attached(&dev->p->knode_driver)) {
+	if (device_is_bound(dev)) {
 		printk(KERN_WARNING "%s: device %s already bound\n",
 			__func__, kobject_name(&dev->kobj));
 		return;
@@ -601,7 +615,7 @@ static int __device_attach(struct device *dev, bool allow_async)
 
 	device_lock(dev);
 	if (dev->driver) {
-		if (klist_node_attached(&dev->p->knode_driver)) {
+		if (device_is_bound(dev)) {
 			ret = 1;
 			goto out_unlock;
 		}
diff --git a/include/linux/device.h b/include/linux/device.h
index f627ba20a46c..6d6f1fec092f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1044,6 +1044,8 @@ extern int __must_check driver_attach(struct device_driver *drv);
 extern void device_initial_probe(struct device *dev);
 extern int __must_check device_reprobe(struct device *dev);
 
+extern bool device_is_bound(struct device *dev);
+
 /*
  * Easy functions for dynamically creating devices on the fly
  */
-- 
2.5.0


  reply	other threads:[~2016-01-07 15:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07 15:46 [PATCH v12 0/4] Allow USB devices to remain runtime-suspended when sleeping Tomeu Vizoso
2016-01-07 15:46 ` Tomeu Vizoso [this message]
2016-01-07 15:46 ` [PATCH v12 2/4] PM / Domains: add setter for dev.pm_domain Tomeu Vizoso
2016-01-29 15:38   ` Andy Shevchenko
2016-01-29 15:51     ` Andy Shevchenko
2016-01-29 16:35       ` Andy Shevchenko
2016-01-29 21:35         ` Rafael J. Wysocki
2016-02-08 21:44           ` Valdis.Kletnieks
2016-02-08 21:50             ` Rafael J. Wysocki
2016-02-09 20:14               ` Valdis.Kletnieks
2016-01-07 15:46 ` [PATCH v12 3/4] PM / sleep: Go direct_complete if driver has no callbacks Tomeu Vizoso
2016-01-07 15:46 ` [PATCH v12 4/4] USB / PM: Allow USB devices to remain runtime-suspended when sleeping Tomeu Vizoso
2016-01-08 23:33 ` [PATCH v12 0/4] " Rafael J. Wysocki

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=1452181575-9206-2-git-send-email-tomeu.vizoso@collabora.com \
    --to=tomeu.vizoso@collabora.com \
    --cc=djkurtz@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=martyn.welch@collabora.co.uk \
    --cc=rjw@rjwysocki.net \
    --cc=stern@rowland.harvard.edu \
    --cc=ulf.hansson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®