Skip to content

Commit afb7742

Browse files
IoanaCiorneiLi Yang
authored andcommitted
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 <[email protected]> Reviewed-by: Laurentiu Tudor <[email protected]> Signed-off-by: Li Yang <[email protected]>
1 parent 47441f7 commit afb7742

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

drivers/bus/fsl-mc/fsl-mc-allocator.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
295295
if (!mc_adev)
296296
goto error;
297297

298+
mc_adev->consumer_link = device_link_add(&mc_dev->dev,
299+
&mc_adev->dev,
300+
DL_FLAG_AUTOREMOVE_CONSUMER);
301+
if (!mc_adev->consumer_link) {
302+
error = -EINVAL;
303+
goto error;
304+
}
305+
298306
*new_mc_adev = mc_adev;
299307
return 0;
300308
error:
@@ -321,6 +329,9 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
321329
return;
322330

323331
fsl_mc_resource_free(resource);
332+
333+
device_link_del(mc_adev->consumer_link);
334+
mc_adev->consumer_link = NULL;
324335
}
325336
EXPORT_SYMBOL_GPL(fsl_mc_object_free);
326337

drivers/bus/fsl-mc/mc-io.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,19 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
209209
if (error < 0)
210210
goto error_cleanup_resource;
211211

212+
dpmcp_dev->consumer_link = device_link_add(&mc_dev->dev,
213+
&dpmcp_dev->dev,
214+
DL_FLAG_AUTOREMOVE_CONSUMER);
215+
if (!dpmcp_dev->consumer_link) {
216+
error = -EINVAL;
217+
goto error_cleanup_mc_io;
218+
}
219+
212220
*new_mc_io = mc_io;
213221
return 0;
214222

223+
error_cleanup_mc_io:
224+
fsl_destroy_mc_io(mc_io);
215225
error_cleanup_resource:
216226
fsl_mc_resource_free(resource);
217227
return error;
@@ -244,6 +254,9 @@ void fsl_mc_portal_free(struct fsl_mc_io *mc_io)
244254

245255
fsl_destroy_mc_io(mc_io);
246256
fsl_mc_resource_free(resource);
257+
258+
device_link_del(dpmcp_dev->consumer_link);
259+
dpmcp_dev->consumer_link = NULL;
247260
}
248261
EXPORT_SYMBOL_GPL(fsl_mc_portal_free);
249262

include/linux/fsl/mc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ struct fsl_mc_device {
193193
struct resource *regions;
194194
struct fsl_mc_device_irq **irqs;
195195
struct fsl_mc_resource *resource;
196+
struct device_link *consumer_link;
196197
};
197198

198199
#define to_fsl_mc_device(_dev) \

0 commit comments

Comments
 (0)