[PATCH 1/2] media: vsp1: vsp1_dl: Add usage counter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux