From c8d54cd53b43c514fbd8d36abf0f2f00f719dd54 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Wed, 16 Dec 2015 11:44:32 -0200 Subject: [media] media: Add an API to manage entity enumerations This is useful in e.g. knowing whether certain operations have already been performed for an entity. The users include the framework itself (for graph walking) and a number of drivers. Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-entity.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'drivers/media/media-entity.c') diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index 13c8ca11f169..5e3f32f63187 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -70,6 +70,46 @@ static inline const char *intf_type(struct media_interface *intf) } }; +/** + * __media_entity_enum_init - Initialise an entity enumeration + * + * @ent_enum: Entity enumeration to be initialised + * @idx_max: Maximum number of entities in the enumeration + * + * Returns zero on success or a negative error code. + */ +__must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum, + int idx_max) +{ + if (idx_max > MEDIA_ENTITY_ENUM_MAX_ID) { + ent_enum->bmap = kcalloc(DIV_ROUND_UP(idx_max, BITS_PER_LONG), + sizeof(long), GFP_KERNEL); + if (!ent_enum->bmap) + return -ENOMEM; + } else { + ent_enum->bmap = ent_enum->prealloc_bmap; + } + + bitmap_zero(ent_enum->bmap, idx_max); + ent_enum->idx_max = idx_max; + + return 0; +} +EXPORT_SYMBOL_GPL(__media_entity_enum_init); + +/** + * media_entity_enum_cleanup - Release resources of an entity enumeration + * + * @e: Entity enumeration to be released + */ +void media_entity_enum_cleanup(struct media_entity_enum *ent_enum) +{ + if (ent_enum->bmap != ent_enum->prealloc_bmap) + kfree(ent_enum->bmap); + ent_enum->bmap = NULL; +} +EXPORT_SYMBOL_GPL(media_entity_enum_cleanup); + /** * dev_dbg_obj - Prints in debug mode a change on some object * -- cgit v1.2.3