mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guru Das Srinagesh <linux@gurudas.dev>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: Nicolas Palix <nicolas.palix@imag.fr>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-kernel@vger.kernel.org, cocci@inria.fr,
	Brian Masney <bmasney@redhat.com>,
	linux-clk@vger.kernel.org
Subject: Re: [PATCH] coccinelle: Detect clk_register() anti-pattern
Date: Mon, 3 Aug 2026 23:14:55 -0700	[thread overview]
Message-ID: <anGDX4xWItkoXTo9@gurudas.dev> (raw)
In-Reply-To: <31eb2139-eb3c-912b-9f61-4aa77df7a5ee@inria.fr>

Hi Julia,

Thank you so much for the review.

On Sun, Aug 02, 2026 at 11:01:08AM +0200, Julia Lawall wrote:
> 
> 
> On Sun, 2 Aug 2026, Guru Das Srinagesh wrote:

--->8---

> > diff --git a/scripts/coccinelle/api/clk_register.cocci b/scripts/coccinelle/api/clk_register.cocci
> > new file mode 100644
> > index 000000000000..fe5bcd4b00d4
> > --- /dev/null
> > +++ b/scripts/coccinelle/api/clk_register.cocci
> > @@ -0,0 +1,125 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/// Remove error messages after clk registration failures, because
> > +/// clk_register(), clk_hw_register(), and their variants already log
> > +/// an error when they fail. See commit 12a0fd23e870 ("clk: Print an
> > +/// error when clk registration fails").
> > +//
> > +// Confidence: Medium
> > +// Options: --include-headers
> > +
> > +virtual patch
> > +virtual context
> > +virtual org
> > +virtual report
> > +
> > +@depends on context@
> > +expression clk;
> > +identifier reg =~ "^(devm_)?clk_register$";
> > +identifier voidfn =~ "^(dev_err|dev_warn|pr_err|pr_warn)$";
> > +@@
> > +
> > +clk = reg(...);
> 
> From a performance point of view, it would be desirable to put instead
> \(devm_clk_register\|clk_register\).  This will trigger some
> optimizations that won't be triggered by a regular expression.

Done.

> 
> 
> > +if ( \( IS_ERR(clk) \| IS_ERR(clk) == 1 \) )
> > +{
> > +...
> > +*voidfn(...);
> > +...
> > +}
> > +
> > +@depends on patch@
> > +expression clk;
> > +identifier reg =~ "^(devm_)?clk_register$";
> > +identifier voidfn =~ "^(dev_err|dev_warn|pr_err|pr_warn)$";
> > +@@
> > +
> > +clk = reg(...);
> > +if ( \( IS_ERR(clk) \| IS_ERR(clk) == 1 \) )
> > +{
> > +...
> > +-voidfn(...);
> > +...
> > +}
> > +
> > +@r1 depends on org || report@
> > +position p1;
> > +expression clk;
> > +identifier reg =~ "^(devm_)?clk_register$";
> > +identifier voidfn =~ "^(dev_err|dev_warn|pr_err|pr_warn)$";
> > +@@
> > +
> > +clk = reg(...);
> > +if ( \( IS_ERR(clk) \| IS_ERR(clk) == 1 \) )
> > +{
> > +...
> > +voidfn@p1(...);
> > +...
> > +}
> > +
> > +@depends on context@
> > +expression ret;
> > +identifier reg =~ "^(devm_)?(of_)?clk_hw_register$";
> > +identifier voidfn =~ "^(dev_err|dev_warn|pr_err|pr_warn)$";
> > +@@
> > +
> > +ret = reg(...);
> > +if ( \( ret \| ret != 0 \| ret < 0 \) )
> > +{
> > +...
> > +*voidfn(...);
> > +...
> > +}
> > +
> > +@depends on patch@
> > +expression ret;
> > +identifier reg =~ "^(devm_)?(of_)?clk_hw_register$";
> > +identifier voidfn =~ "^(dev_err|dev_warn|pr_err|pr_warn)$";
> > +@@
> > +
> > +ret = reg(...);
> > +if ( \( ret \| ret != 0 \| ret < 0 \) )
> > +{
> > +...
> > +-voidfn(...);
> > +...
> > +}
> 
> I think yourpatch rule should have an extra case for where there are
> currently only two statements in the if branch.  In that case the {}
> should be removed.
> 
> julia

Done.

> 
> > +
> > +@r2 depends on org || report@
> > +position p2;
> > +expression ret;

--->8---

Thank you.

Guru Das.

      reply	other threads:[~2026-08-04  6:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02  8:53 Guru Das Srinagesh
2026-08-02  9:01 ` Julia Lawall
2026-08-04  6:14   ` Guru Das Srinagesh [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=anGDX4xWItkoXTo9@gurudas.dev \
    --to=linux@gurudas.dev \
    --cc=bmasney@redhat.com \
    --cc=cocci@inria.fr \
    --cc=julia.lawall@inria.fr \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nicolas.palix@imag.fr \
    --cc=sboyd@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

all inboxes | Powered by JetHome®