Skip to content

Commit

Permalink
FROMLIST: device core: add device_is_bound()
Browse files Browse the repository at this point in the history
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.

BUG=chrome-os-partner:46491
TEST=boot glados

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
(am from https://patchwork.kernel.org/patch/7328221/)
Signed-off-by: Derek Basehore <dbasehore@chromium.org>

Change-Id: I02b842a5ce3beca1d3228243bed64ad9b9a7d7d3
Reviewed-on: https://chromium-review.googlesource.com/305813
Commit-Ready: Derek Basehore <dbasehore@chromium.org>
Tested-by: Derek Basehore <dbasehore@chromium.org>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
  • Loading branch information
Tomeu Vizoso authored and chrome-bot committed Oct 23, 2015
1 parent cc6714b commit 123b0e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,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;
Expand Down Expand Up @@ -496,7 +510,7 @@ 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;
}
Expand Down
2 changes: 2 additions & 0 deletions include/linux/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,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
*/
Expand Down

0 comments on commit 123b0e7

Please sign in to comment.