Linux EDAC development
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Borislav Petkov <bp@alien8.de>
Cc: "Gustavo A. R. Silva" <garsilva@embeddedor.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	cocci@systeme.lip6.fr
Subject: EDAC: remove unnecessary static in edac_fake_inject_write()
Date: Fri, 21 Jul 2017 22:08:12 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1707212205410.2232@hadrien> (raw)

On Mon, 17 Jul 2017, Borislav Petkov wrote:

> On Tue, Jul 04, 2017 at 04:44:40PM -0500, Gustavo A. R. Silva wrote:
> > Remove unnecessary static on local variable _type_.
> > Such variable is initialized before being used,
> > on every execution path throughout the function.
> > The static has no benefit and, removing it reduces
> > the code size.
> >
> > This issue was detected using Coccinelle and the following semantic patch:
> >
> > @bad exists@
> > position p;
> > identifier x;
> > type T;
> > @@
> >
> > static T x@p;
> > ...
> > x = <+...x...+>
> >
> > @@
> > identifier x;
> > expression e;
> > type T;
> > position p != bad.p;
> > @@
> >
> > -static
> >  T x@p;
> >  ... when != x
> >      when strict
> > ?x = e;
>
> So the fix is ok but I don't understand Coccinelle to be able to judge
> whether the above patch is fine or not. If it is, it probably should be
> put somewhere in scripts/coccinelle/ so that others can use it too so
> that they can catch such useless uses of static too.

Someone pointed out that the rule is probably not OK when the address of
the static variable is taken, because then it is likely being used as
permanent storage.  An improved rule is:

@bad exists@
position p;
identifier x;
expression e;
type T;
@@

static T x@p;
... when != x = e
x = <+...x...+>

@worse exists@
position p;
identifier x;
type T;
@@

static T x@p;
...
 &x

@@
identifier x;
expression e;
type T;
position p != {bad.p,worse.p};
@@

-static
 T x@p;
 ... when != x
     when strict
?x = e;

julia

>
> Lemme add the Coccinelle ML to CC.
>
> (Leaving in the rest for reference.)
>
> > In the following log you can see the difference in the code size and,
> > also a significant difference in bss segment. This log is the output
> > of the size command, before and after the code change:
> >
> > before:
> >    text    data     bss     dec     hex filename
> >    2966     920     128    4014     fae drivers/edac/debugfs.o
> >
> > after:
> >    text     data     bss    dec     hex filename
> >    2961     832      64    3857     f11 drivers/edac/debugfs.o
> >
> > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> > ---
> >  drivers/edac/debugfs.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/edac/debugfs.c b/drivers/edac/debugfs.c
> > index 92dbb7e..ba0af49 100644
> > --- a/drivers/edac/debugfs.c
> > +++ b/drivers/edac/debugfs.c
> > @@ -8,7 +8,7 @@ static ssize_t edac_fake_inject_write(struct file *file,
> >  {
> >  	struct device *dev = file->private_data;
> >  	struct mem_ctl_info *mci = to_mci(dev);
> > -	static enum hw_event_mc_err_type type;
> > +	enum hw_event_mc_err_type type;
> >  	u16 errcount = mci->fake_inject_count;
> >
> >  	if (!errcount)
> > --
> > 2.5.0
> >
>
> --
> Regards/Gruss,
>     Boris.
>
> ECO tip #101: Trim your mails when you reply.
> --
>
---
To unsubscribe from this list: send the line "unsubscribe linux-edac" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2017-07-21 20:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 20:08 Julia Lawall [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-07-24 10:34 EDAC: remove unnecessary static in edac_fake_inject_write() Borislav Petkov
2017-07-23  6:25 Gustavo A. R. Silva
2017-07-23  5:53 Julia Lawall
2017-07-23  5:42 Gustavo A. R. Silva
2017-07-23  5:07 Julia Lawall
2017-07-23  2:31 Gustavo A. R. Silva
2017-07-22 16:22 Gustavo A. R. Silva
2017-07-22  6:39 Julia Lawall
2017-07-22  6:36 Borislav Petkov
2017-07-17  8:39 Borislav Petkov
2017-07-04 21:44 Gustavo A. R. Silva

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.20.1707212205410.2232@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=bp@alien8.de \
    --cc=cocci@systeme.lip6.fr \
    --cc=garsilva@embeddedor.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@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