Linux Media Controller development
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] media: vsp1: vsp1_dl: Add usage counter
Date: Mon, 16 Jun 2025 16:20:49 +0300	[thread overview]
Message-ID: <20250616132049.GA10542@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20250529-vsp1_dl_list_count-v1-1-40c6d0e20592@ideasonboard.com>

Hi Jacopo,

Thank you for the patch.

On Thu, May 29, 2025 at 06:36:30PM +0200, Jacopo Mondi wrote:
> 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@ideasonboard.com>
> ---
>  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;

If you have no objection, I'd like to include "count" in the name. This
could be usage_count, ref_count or refcount.

>  };
>  
>  /**
> @@ -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++;

The usage count will never go above 1, as there's not real reference
counting for display lists. Better than including "count" in the field
name, we could replace

	int usage;

with

	bool allocated;

(right after has_chain to avoid increasing the structure size).

>  	}
>  
>  	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. */

s/decrement/Decrement/

> +	if (WARN_ON_ONCE(--dl->usage < 0))
> +		dl->usage = 0;
> +
>  	list_add_tail(&dl->list, &dl->dlm->free);
>  }
>  

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2025-06-16 13:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-29 16:36 [PATCH 0/2] media: vsp1: Detect display list wrong usage patterns Jacopo Mondi
2025-05-29 16:36 ` [PATCH 1/2] media: vsp1: vsp1_dl: Add usage counter Jacopo Mondi
2025-06-16 13:20   ` Laurent Pinchart [this message]
2025-05-29 16:36 ` [PATCH 2/2] media: vsp1: vsp1_dl: Count display lists Jacopo Mondi
2025-06-16 13:31   ` Laurent Pinchart
2025-06-16 14:35     ` Jacopo Mondi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250616132049.GA10542@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=jacopo.mondi+renesas@ideasonboard.com \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox