Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

driver core: Add fwnode_to_dev() to look up device from fwnode

It's often useful to look up a device that corresponds to a fwnode. So
add an API to do that irrespective of the bus on which the device has
been added to.

Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20190904211126.47518-2-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Saravana Kannan and committed by
Greg Kroah-Hartman
372a67c0 54ecb8f7

+9
+7
drivers/base/core.c
··· 2198 2198 BUS_NOTIFY_ADD_DEVICE, dev); 2199 2199 2200 2200 kobject_uevent(&dev->kobj, KOBJ_ADD); 2201 + 2202 + if (dev->fwnode && !dev->fwnode->dev) 2203 + dev->fwnode->dev = dev; 2204 + 2201 2205 bus_probe_device(dev); 2202 2206 if (parent) 2203 2207 klist_add_tail(&dev->p->knode_parent, ··· 2345 2341 device_lock(dev); 2346 2342 kill_device(dev); 2347 2343 device_unlock(dev); 2344 + 2345 + if (dev->fwnode && dev->fwnode->dev == dev) 2346 + dev->fwnode->dev = NULL; 2348 2347 2349 2348 /* Notify clients of device removal. This call must come 2350 2349 * before dpm_sysfs_remove().
+2
include/linux/fwnode.h
··· 17 17 struct fwnode_handle { 18 18 struct fwnode_handle *secondary; 19 19 const struct fwnode_operations *ops; 20 + struct device *dev; 20 21 }; 21 22 22 23 /** ··· 124 123 if (fwnode_has_op(fwnode, op)) \ 125 124 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ 126 125 } while (false) 126 + #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) 127 127 128 128 #endif