All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guru Das Srinagesh" <linux@gurudas.dev>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH v4] coccinelle: Detect clk_register() anti-pattern
Date: Mon, 19 Oct 2026 07:21:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-176742@kernel.org> (raw)
In-Reply-To: <20261018-cocci-clk-register-v4-1-ed611b1c0da6@gurudas.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] coccinelle: clk_register: missing when != n constraints in bind_loop
--

commit 5a7f966954ec0e1e638d5df96a25b50558993fc6
Author: Guru Das Srinagesh <linux@gurudas.dev>

coccinelle: Detect clk_register() anti-pattern

This commit adds a Coccinelle semantic patch to detect and remove redundant
error messages logged after clk_register(), clk_hw_register(), and their
devm_/of_ variants fail.

> diff --git a/scripts/coccinelle/api/clk_register.cocci b/scripts/coccinelle/api/clk_register.cocci
> new file mode 100644
> index 0000000000000..01d272e2d96f7
> --- /dev/null
> +++ b/scripts/coccinelle/api/clk_register.cocci
> @@ -0,0 +1,262 @@

[ ... ]

> +@bind_loop depends on patch@
> +expression x, E;
> +identifier voidfn, n;
> +constant char[] c;
> +type T;
> +statement S, S_else;
> +@@
> +
> +  for (...;...;...) {
> +  ... when != n
> +- T n;
> +  ...
> +- n = E;
> +  ...
> +  x = \(clk_register\|devm_clk_register\|clk_hw_register\|devm_clk_hw_register\|of_clk_hw_register\)(...);
> +  if ( \( IS_ERR(x) \| x \| x < 0 \) )
> +(
> +-{
> +-voidfn(...,c,...,n,...);
> +S
> +-}
> +|
> +{
> +...
> +-voidfn(...,c,...,n,...);
> +...
> +}
> +)
> +  else S_else
> +  ... when != n
> +  }

[Severity: Medium]
Can the bind_loop rule delete the declaration and assignment of n when n is
still referenced elsewhere in the loop?

In SmPL, when != n only constrains the specific ellipsis to which it is
attached. Here, when != n is only placed before T n; (before n is in scope)
and after else S_else. The intermediate ellipses around n = E; and
voidfn(...), the registration call arguments, and the statements S and
S_else are not constrained.

If a loop uses n between n = E; and the end of the if/else block (for
example, passing n to the registration call or using it in S or S_else),
won't running this script in patch mode still remove T n; and n = E;,
leaving behind an undeclared identifier?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261018-cocci-clk-register-v4-1-ed611b1c0da6@gurudas.dev?part=1

      reply	other threads:[~2026-10-19  7:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  6:56 [PATCH v4] coccinelle: Detect clk_register() anti-pattern Guru Das Srinagesh
2026-10-19  7:21 ` sashiko-bot [this message]

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=sashiko-outbox-176742@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux@gurudas.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.