#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/gfp.h>
+#include <linux/refcount.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
struct list_head list;
struct list_head free;
+ refcount_t refcnt;
+
struct vsp1_dl_body_pool *pool;
struct vsp1_device *vsp1;
if (!list_empty(&pool->free)) {
dlb = list_first_entry(&pool->free, struct vsp1_dl_body, free);
list_del(&dlb->free);
+ refcount_set(&dlb->refcnt, 1);
}
spin_unlock_irqrestore(&pool->lock, flags);
if (!dlb)
return;
+ if (!refcount_dec_and_test(&dlb->refcnt))
+ return;
+
dlb->num_entries = 0;
spin_lock_irqsave(&dlb->pool->lock, flags);
* which bodies are added.
*
* Adding a body to a display list passes ownership of the body to the list. The
- * caller must not touch the body after this call, and must not release it
- * explicitly with vsp1_dl_body_put().
+ * caller retains its reference to the fragment when adding it to the display
+ * list, but is not allowed to add new entries to the body.
+ *
+ * The reference must be explicitly released by a call to vsp1_dl_body_put()
+ * when the body isn't needed anymore.
*
* Additional bodies are only usable for display lists in header mode.
* Attempting to add a body to a header-less display list will return an error.
if (dl->dlm->mode != VSP1_DL_MODE_HEADER)
return -EINVAL;
+ refcount_inc(&dlb->refcnt);
+
list_add_tail(&dlb->list, &dl->bodies);
return 0;