@@ -82,9 +82,79 @@ void
media_entity_cleanup(struct media_entity *entity)
{
kfree(entity->links);
+ entity->links = NULL;
}
EXPORT_SYMBOL_GPL(media_entity_cleanup);
+static void devm_media_entity_release(struct device *dev, void *res)
+{
+ struct media_entity **entity = res;
+
+ media_entity_cleanup(*entity);
+}
+
+/**
+ * devm_media_entity_init - managed media entity initialization
+ *
+ * @dev: Device for which @entity belongs to.
+ * @entity: Entity to be initialized.
+ * @num_pads: Total number of sink and source pads.
+ * @pads: Array of 'num_pads' pads.
+ * @extra_links: Initial estimate of the number of extra links.
+ *
+ * This is a managed version of media_entity_init. Entity initialized with
+ * this function will be automatically cleaned up on driver detach.
+ *
+ * If an entity initialized with this function needs to be cleaned up
+ * separately, devm_media_entity_cleanup() must be used.
+ */
+int
+devm_media_entity_init(struct device *dev, struct media_entity *entity,
+ u16 num_pads, struct media_pad *pads, u16 extra_links)
+{
+ struct media_entity **dr;
+ int rc;
+
+ dr = devres_alloc(devm_media_entity_release, sizeof(*dr), GFP_KERNEL);
+ if (!dr)
+ return -ENOMEM;
+
+ rc = media_entity_init(entity, num_pads, pads, extra_links);
+ if (rc) {
+ devres_free(dr);
+ return rc;
+ }
+
+ *dr = entity;
+ devres_add(dev, dr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_media_entity_init);
+
+static int devm_media_entity_match(struct device *dev, void *res, void *data)
+{
+ struct media_entity **this = res, **entity = data;
+
+ return *this == *entity;
+}
+
+/**
+ * devm_media_entity_cleanup - managed media entity cleanup
+ *
+ * @dev: Device for which @entity belongs to.
+ * @entity: Entity to be cleaned up.
+ *
+ * This function should be used to manual cleanup of an media entity
+ * initialized with devm_media_entity_init().
+ */
+void devm_media_entity_cleanup(struct device *dev, struct media_entity *entity)
+{
+ WARN_ON(devres_release(dev, devm_media_entity_release,
+ devm_media_entity_match, &entity));
+}
+EXPORT_SYMBOL_GPL(devm_media_entity_cleanup);
+
/* -----------------------------------------------------------------------------
* Graph traversal
*/
@@ -26,6 +26,8 @@
#include <linux/list.h>
#include <linux/media.h>
+struct device;
+
struct media_pipeline {
};
@@ -126,6 +128,10 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
struct media_pad *pads, u16 extra_links);
void media_entity_cleanup(struct media_entity *entity);
+int devm_media_entity_init(struct device *dev, struct media_entity *entity,
+ u16 num_pads, struct media_pad *pads, u16 extra_links);
+void devm_media_entity_cleanup(struct device *dev, struct media_entity *entity);
+
int media_entity_create_link(struct media_entity *source, u16 source_pad,
struct media_entity *sink, u16 sink_pad, u32 flags);
int __media_entity_setup_link(struct media_link *link, u32 flags);