In order to detect invalid usage pattern such as double list_put() calls, add a usage counter to each display list. Increment it whenever a list is get() and decrement it when the list is put(). Warn if the usage counter goes below 0. Signed-off-by: Jacopo Mondi <jacopo.mondi+renesas@xxxxxxxxxxxxxxxx> --- drivers/media/platform/renesas/vsp1/vsp1_dl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/media/platform/renesas/vsp1/vsp1_dl.c b/drivers/media/platform/renesas/vsp1/vsp1_dl.c index bb8228b19824..8a3c0274a163 100644 --- a/drivers/media/platform/renesas/vsp1/vsp1_dl.c +++ b/drivers/media/platform/renesas/vsp1/vsp1_dl.c @@ -179,6 +179,7 @@ struct vsp1_dl_cmd_pool { * @has_chain: if true, indicates that there's a partition chain * @chain: entry in the display list partition chain * @flags: display list flags, a combination of VSP1_DL_FRAME_END_* + * @usage: usage counter to detect double list free */ struct vsp1_dl_list { struct list_head list; @@ -198,6 +199,7 @@ struct vsp1_dl_list { struct list_head chain; unsigned int flags; + int usage; }; /** @@ -617,6 +619,7 @@ struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm) * display list can assert list_empty() if it is not in a chain. */ INIT_LIST_HEAD(&dl->chain); + dl->usage++; } spin_unlock_irqrestore(&dlm->lock, flags); @@ -657,6 +660,10 @@ static void __vsp1_dl_list_put(struct vsp1_dl_list *dl) */ dl->body0->num_entries = 0; + /* decrement usage count to detect invalid usage pattern. */ + if (WARN_ON_ONCE(--dl->usage < 0)) + dl->usage = 0; + list_add_tail(&dl->list, &dl->dlm->free); } -- 2.49.0