Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1237994 > unrolled thread
| Started by | Tomeu Vizoso <tomeu.vizoso@collabora.com> |
|---|---|
| First post | 2015-10-02 09:20 +0200 |
| Last post | 2015-10-02 15:20 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v8 1/4] device core: add device_is_bound() Tomeu Vizoso <tomeu.vizoso@collabora.com> - 2015-10-02 09:20 +0200
Re: [PATCH v8 1/4] device core: add device_is_bound() "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2015-10-02 15:20 +0200
| From | Tomeu Vizoso <tomeu.vizoso@collabora.com> |
|---|---|
| Date | 2015-10-02 09:20 +0200 |
| Subject | [PATCH v8 1/4] device core: add device_is_bound() |
| Message-ID | <qf2Nj-4OQ-9@gated-at.bofh.it> |
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>
---
Changes in v8:
- Add device_is_bound()
drivers/base/dd.c | 9 +++++++--
include/linux/device.h | 2 ++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index be0eb4639128..f2007fa7316f 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -192,9 +192,14 @@ static int deferred_probe_initcall(void)
}
late_initcall(deferred_probe_initcall);
+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;
@@ -545,7 +550,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 5d7bc6349930..9b41c05fb479 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1035,6 +1035,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.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rjw@rjwysocki.net> |
|---|---|
| Date | 2015-10-02 15:20 +0200 |
| Message-ID | <qf8pI-4pZ-21@gated-at.bofh.it> |
| In reply to | #1237994 |
On Friday, October 02, 2015 09:14:28 AM Tomeu Vizoso wrote:
> 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>
> ---
>
> Changes in v8:
> - Add device_is_bound()
>
> drivers/base/dd.c | 9 +++++++--
> include/linux/device.h | 2 ++
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index be0eb4639128..f2007fa7316f 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -192,9 +192,14 @@ static int deferred_probe_initcall(void)
> }
> late_initcall(deferred_probe_initcall);
>
> +bool device_is_bound(struct device *dev)
> +{
> + return klist_node_attached(&dev->p->knode_driver);
> +}
It would be useful here to add a comment explaining what locks need to be held
around this for it to be non-racy IMO.
> +
> 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;
> @@ -545,7 +550,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 5d7bc6349930..9b41c05fb479 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -1035,6 +1035,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
> */
>
Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web