All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Gilles Muller <Gilles.Muller@inria.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Michal Marek <michal.lkml@markovi.net>,
	cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts: coccinelle: allow list_entry_is_head() to use pos
Date: Fri, 30 Jul 2021 12:58:40 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2107301257470.52326@hadrien> (raw)
In-Reply-To: <20210730095856.2038286-1-daniel.thompson@linaro.org>



On Fri, 30 Jul 2021, Daniel Thompson wrote:

> Currently use_after_iter.cocci generates false positives for code of the
> following form:
> ~~~
> 	list_for_each_entry(d, &ddata->irq_list, node) {
> 		if (irq == d->irq)
> 			break;
> 	}
>
> 	if (list_entry_is_head(d, &ddata->irq_list, node))
> 		return IRQ_NONE;
> ~~~
> [This specific example comes from drivers/power/supply/cpcap-battery.c]
>
> Most list macros use list_entry_is_head() as loop exit condition meaning it
> is not unsafe to reuse pos (a.k.a. d) in the code above.
>
> Let's avoid reporting these cases.
>
> Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
> ---
>
> Notes:
>     I'm pretty much a complete beginner w.r.t. SmPL. This is written
>     entirely by finding previous fixes and emulating them!
>
>     However I did test it by running the checker across the current kernel
>     tree. The changes reduced the error count by four... which was small
>     enough for me to eyeball each one and check they match the pattern I
>     was targetting.

This looks fine.  Thanks for the proposal.

julia

>
>  scripts/coccinelle/iterators/use_after_iter.cocci | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci
> index 9be48b520879..676edd562eef 100644
> --- a/scripts/coccinelle/iterators/use_after_iter.cocci
> +++ b/scripts/coccinelle/iterators/use_after_iter.cocci
> @@ -123,6 +123,8 @@ hlist_for_each_entry_safe(c,...) S
>  |
>  list_remove_head(x,c,...)
>  |
> +list_entry_is_head(c,...)
> +|
>  sizeof(<+...c...+>)
>  |
>   &c->member
>
> base-commit: 2734d6c1b1a089fb593ef6a23d4b70903526fe0c
> --
> 2.30.2
>
>

WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia.lawall@inria.fr>
To: Daniel Thompson <daniel.thompson@linaro.org>
Cc: Michal Marek <michal.lkml@markovi.net>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org
Subject: Re: [Cocci] [PATCH] scripts: coccinelle: allow list_entry_is_head() to use pos
Date: Fri, 30 Jul 2021 12:58:40 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2107301257470.52326@hadrien> (raw)
In-Reply-To: <20210730095856.2038286-1-daniel.thompson@linaro.org>



On Fri, 30 Jul 2021, Daniel Thompson wrote:

> Currently use_after_iter.cocci generates false positives for code of the
> following form:
> ~~~
> 	list_for_each_entry(d, &ddata->irq_list, node) {
> 		if (irq == d->irq)
> 			break;
> 	}
>
> 	if (list_entry_is_head(d, &ddata->irq_list, node))
> 		return IRQ_NONE;
> ~~~
> [This specific example comes from drivers/power/supply/cpcap-battery.c]
>
> Most list macros use list_entry_is_head() as loop exit condition meaning it
> is not unsafe to reuse pos (a.k.a. d) in the code above.
>
> Let's avoid reporting these cases.
>
> Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
> ---
>
> Notes:
>     I'm pretty much a complete beginner w.r.t. SmPL. This is written
>     entirely by finding previous fixes and emulating them!
>
>     However I did test it by running the checker across the current kernel
>     tree. The changes reduced the error count by four... which was small
>     enough for me to eyeball each one and check they match the pattern I
>     was targetting.

This looks fine.  Thanks for the proposal.

julia

>
>  scripts/coccinelle/iterators/use_after_iter.cocci | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci
> index 9be48b520879..676edd562eef 100644
> --- a/scripts/coccinelle/iterators/use_after_iter.cocci
> +++ b/scripts/coccinelle/iterators/use_after_iter.cocci
> @@ -123,6 +123,8 @@ hlist_for_each_entry_safe(c,...) S
>  |
>  list_remove_head(x,c,...)
>  |
> +list_entry_is_head(c,...)
> +|
>  sizeof(<+...c...+>)
>  |
>   &c->member
>
> base-commit: 2734d6c1b1a089fb593ef6a23d4b70903526fe0c
> --
> 2.30.2
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2021-07-30 10:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30  9:58 [PATCH] scripts: coccinelle: allow list_entry_is_head() to use pos Daniel Thompson
2021-07-30  9:58 ` [Cocci] " Daniel Thompson
2021-07-30 10:58 ` Julia Lawall [this message]
2021-07-30 10:58   ` Julia Lawall
2021-08-08 20:02 ` Julia Lawall

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=alpine.DEB.2.22.394.2107301257470.52326@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=Gilles.Muller@inria.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=daniel.thompson@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=nicolas.palix@imag.fr \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.