diff --git a/drivers/base/core.c b/drivers/base/core.c index fcda6313e7de..3e7fb298ee26 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1981,6 +1981,10 @@ int device_add(struct device *dev) BUS_NOTIFY_ADD_DEVICE, dev); kobject_uevent(&dev->kobj, KOBJ_ADD); + + if (dev->fwnode && !dev->fwnode->dev) + dev->fwnode->dev = dev; + bus_probe_device(dev); if (parent) klist_add_tail(&dev->p->knode_parent, @@ -2123,6 +2127,9 @@ void device_del(struct device *dev) kill_device(dev); device_unlock(dev); + if (dev->fwnode && dev->fwnode->dev == dev) + dev->fwnode->dev = NULL; + /* Notify clients of device removal. This call must come * before dpm_sysfs_remove(). */ diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index faebf0ca0686..49be3d2d1c7f 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -20,6 +20,7 @@ struct device; struct fwnode_handle { struct fwnode_handle *secondary; const struct fwnode_operations *ops; + struct device *dev; }; /** @@ -125,5 +126,6 @@ struct fwnode_operations { if (fwnode_has_op(fwnode, op)) \ (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ } while (false) +#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) #endif