Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1693952

Re: [PATCH] EDAC: remove unnecessary static in edac_fake_inject_write()

From Julia Lawall <julia.lawall@lip6.fr>
Newsgroups linux.kernel
Subject Re: [PATCH] EDAC: remove unnecessary static in edac_fake_inject_write()
Date 2017-07-21 22:10 +0200
Message-ID <u5Mpj-Qz-3@gated-at.bofh.it> (permalink)
References <tZEb7-5V4-9@gated-at.bofh.it> <u49T4-2FF-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View 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.
> --
>

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() Julia Lawall <julia.lawall@lip6.fr> - 2017-07-21 22:10 +0200
  Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() Borislav Petkov <bp@alien8.de> - 2017-07-22 08:40 +0200
    Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() Julia Lawall <julia.lawall@lip6.fr> - 2017-07-22 08:40 +0200
    Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-22 18:30 +0200
      Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-07-23 04:40 +0200
        Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() Julia Lawall <julia.lawall@lip6.fr> - 2017-07-23 07:10 +0200
          Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() "Gustavo A. R. Silva" <gustavo@embeddedor.com> - 2017-07-23 07:50 +0200
            Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() Julia Lawall <julia.lawall@lip6.fr> - 2017-07-23 08:00 +0200
              Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() "Gustavo A. R. Silva" <gustavo@embeddedor.com> - 2017-07-23 08:30 +0200
                Re: [PATCH] EDAC: remove unnecessary static in  edac_fake_inject_write() Borislav Petkov <bp@alien8.de> - 2017-07-24 12:40 +0200

csiph-web