summaryrefslogtreecommitdiff
path: root/drivers/bus/fsl-mc/fsl-mc-allocator.c
diff options
context:
space:
mode:
authorIoana Ciornei <ioana.ciornei@nxp.com>2018-12-10 16:50:19 +0000
committerLi Yang <leoyang.li@nxp.com>2019-01-11 15:06:54 -0600
commitafb77422819ff60612e9b7d36461b9b2bc8e038e (patch)
treea9976bca434fae99f9064cb9b745990f117d2365 /drivers/bus/fsl-mc/fsl-mc-allocator.c
parent47441f7f73b7cf0c2d6e7d6372f026ea81193fd6 (diff)
bus: fsl-mc: automatically add a device_link on fsl_mc_[portal,object]_allocate
Allocatable devices can be acquired by drivers on the fsl-mc bus using the fsl_mc_portal_allocate or fsl_mc_object_allocate functions. Add a device link between the consumer device and the supplier device so that proper resource management is achieved. Also, adding a link between these devices ensures that a proper unbind order is respected (ie before the supplier device is unbound from its respective driver all consumer devices will be notified and unbound first). Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com> Reviewed-by: Laurentiu Tudor <laurentiu.tudor@nxp.com> Signed-off-by: Li Yang <leoyang.li@nxp.com>
Diffstat (limited to 'drivers/bus/fsl-mc/fsl-mc-allocator.c')
-rw-r--r--drivers/bus/fsl-mc/fsl-mc-allocator.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index e906ecfe23dd..8ad77246f322 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -295,6 +295,14 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
if (!mc_adev)
goto error;
+ mc_adev->consumer_link = device_link_add(&mc_dev->dev,
+ &mc_adev->dev,
+ DL_FLAG_AUTOREMOVE_CONSUMER);
+ if (!mc_adev->consumer_link) {
+ error = -EINVAL;
+ goto error;
+ }
+
*new_mc_adev = mc_adev;
return 0;
error:
@@ -321,6 +329,9 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
return;
fsl_mc_resource_free(resource);
+
+ device_link_del(mc_adev->consumer_link);
+ mc_adev->consumer_link = NULL;
}
EXPORT_SYMBOL_GPL(fsl_mc_object_free);