summaryrefslogtreecommitdiff
path: root/drivers/media/media-device.c
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2015-12-16 11:32:17 -0200
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2016-01-11 12:19:17 -0200
commit665faa971d087e8b968ef75d04079a7a462ddfca (patch)
tree86bf4c0dd50debbe5a8353208a1e4b818d22d51d /drivers/media/media-device.c
parent1630b832355399dd0dc4fcc2cadbcad47153a748 (diff)
[media] media: Introduce internal index for media entities
The internal index can be used internally by the framework in order to keep track of entities for a purpose or another. The internal index is constant while it's registered to a media device, but the same index may be re-used once the entity having that index is unregistered. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/media-device.c')
-rw-r--r--drivers/media/media-device.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 30e3354d7481..ce97f8f196f3 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -22,6 +22,7 @@
#include <linux/compat.h>
#include <linux/export.h>
+#include <linux/idr.h>
#include <linux/ioctl.h>
#include <linux/media.h>
#include <linux/slab.h>
@@ -551,6 +552,17 @@ int __must_check media_device_register_entity(struct media_device *mdev,
entity->num_backlinks = 0;
spin_lock(&mdev->lock);
+
+ entity->internal_idx = ida_simple_get(&mdev->entity_internal_idx, 1, 0,
+ GFP_KERNEL);
+ if (entity->internal_idx < 0) {
+ spin_unlock(&mdev->lock);
+ return entity->internal_idx;
+ }
+
+ mdev->entity_internal_idx_max =
+ max(mdev->entity_internal_idx_max, entity->internal_idx);
+
/* Initialize media_gobj embedded at the entity */
media_gobj_create(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
@@ -579,6 +591,8 @@ static void __media_device_unregister_entity(struct media_entity *entity)
struct media_interface *intf;
unsigned int i;
+ ida_simple_remove(&mdev->entity_internal_idx, entity->internal_idx);
+
/* Remove all interface links pointing to this entity */
list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
list_for_each_entry_safe(link, tmp, &intf->links, list) {
@@ -632,6 +646,7 @@ void media_device_init(struct media_device *mdev)
INIT_LIST_HEAD(&mdev->links);
spin_lock_init(&mdev->lock);
mutex_init(&mdev->graph_mutex);
+ ida_init(&mdev->entity_internal_idx);
dev_dbg(mdev->dev, "Media device initialized\n");
}
@@ -644,6 +659,8 @@ EXPORT_SYMBOL_GPL(media_device_init);
*/
void media_device_cleanup(struct media_device *mdev)
{
+ ida_destroy(&mdev->entity_internal_idx);
+ mdev->entity_internal_idx_max = 0;
mutex_destroy(&mdev->graph_mutex);
}
EXPORT_SYMBOL_GPL(media_device_cleanup);