* [PATCH 00/11] Drop unnecessary static
@ 2017-07-15 20:07 Julia Lawall
2017-07-15 20:07 ` [PATCH 07/11] mfd: " Julia Lawall
2017-07-15 20:37 ` [PATCH 00/11] " Joe Perches
0 siblings, 2 replies; 9+ messages in thread
From: Julia Lawall @ 2017-07-15 20:07 UTC (permalink / raw)
To: linux-arm-kernel
Cc: linux-fbdev, Lars-Peter Clausen, keescook, linux-iio, linux-input,
kernel-janitors, linux-kernel, linux-ide, linux-mtd,
Peter Meerwald-Stadler, Hartmut Knaack, linux-omap, linux-clk
These patches fix cases where there is a static on a local variable, but
the variable is initialized before any possible use. Thus, the static has
no benefit.
---
drivers/ata/sata_gemini.c | 2 +-
drivers/clk/clk-moxart.c | 4 ++--
drivers/clk/mmp/clk.c | 2 +-
drivers/iio/orientation/hid-sensor-rotation.c | 2 +-
drivers/irqchip/irq-digicolor.c | 2 +-
drivers/irqchip/irq-gic-realview.c | 2 +-
drivers/irqchip/irq-mips-cpu.c | 2 +-
drivers/mfd/max8925-i2c.c | 2 +-
drivers/mfd/twl4030-irq.c | 2 +-
drivers/mtd/maps/physmap_of_versatile.c | 2 +-
drivers/video/fbdev/da8xx-fb.c | 2 +-
11 files changed, 12 insertions(+), 12 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 07/11] mfd: Drop unnecessary static
2017-07-15 20:07 [PATCH 00/11] Drop unnecessary static Julia Lawall
@ 2017-07-15 20:07 ` Julia Lawall
2017-07-15 20:49 ` Mark D Rustad
2017-07-25 8:00 ` Lee Jones
2017-07-15 20:37 ` [PATCH 00/11] " Joe Perches
1 sibling, 2 replies; 9+ messages in thread
From: Julia Lawall @ 2017-07-15 20:07 UTC (permalink / raw)
To: Tony Lindgren
Cc: keescook, kernel-janitors, Lee Jones, linux-omap, linux-kernel
Drop static on a local variable, when the variable is initialized before
any possible use. Thus, the static has no benefit.
The semantic patch that fixes this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@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;
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
---
These patches are all independent of each other.
drivers/mfd/twl4030-irq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff -u -p a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -685,7 +685,7 @@ int twl4030_sih_setup(struct device *dev
int twl4030_init_irq(struct device *dev, int irq_num)
{
- static struct irq_chip twl4030_irq_chip;
+ struct irq_chip twl4030_irq_chip;
int status, i;
int irq_base, irq_end, nr_irqs;
struct device_node *node = dev->of_node;
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 07/11] mfd: Drop unnecessary static
2017-07-15 20:07 ` [PATCH 07/11] mfd: " Julia Lawall
@ 2017-07-15 20:49 ` Mark D Rustad
2017-07-15 20:56 ` Julia Lawall
2017-07-25 8:00 ` Lee Jones
1 sibling, 1 reply; 9+ messages in thread
From: Mark D Rustad @ 2017-07-15 20:49 UTC (permalink / raw)
To: Julia Lawall
Cc: Tony Lindgren, keescook, kernel-janitors, Lee Jones, linux-omap,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]
> On Jul 15, 2017, at 1:07 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>
> Drop static on a local variable, when the variable is initialized before
> any possible use. Thus, the static has no benefit.
I think in this case the use relies on the structure continuing to exist, so a stack object is not an acceptable substitute. Just because it is initialized doesn't mean that it doesn't need a persistent lifetime.
> The semantic patch that fixes this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @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;
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
> These patches are all independent of each other.
>
> drivers/mfd/twl4030-irq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
> --- a/drivers/mfd/twl4030-irq.c
> +++ b/drivers/mfd/twl4030-irq.c
> @@ -685,7 +685,7 @@ int twl4030_sih_setup(struct device *dev
>
> int twl4030_init_irq(struct device *dev, int irq_num)
> {
> - static struct irq_chip twl4030_irq_chip;
> + struct irq_chip twl4030_irq_chip;
> int status, i;
> int irq_base, irq_end, nr_irqs;
> struct device_node *node = dev->of_node;
--
Mark Rustad, MRustad@gmail.com
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 841 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 07/11] mfd: Drop unnecessary static
2017-07-15 20:49 ` Mark D Rustad
@ 2017-07-15 20:56 ` Julia Lawall
2017-07-24 19:20 ` Pavel Machek
0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2017-07-15 20:56 UTC (permalink / raw)
To: Mark D Rustad
Cc: Tony Lindgren, keescook, kernel-janitors, Lee Jones, linux-omap,
linux-kernel
On Sat, 15 Jul 2017, Mark D Rustad wrote:
> > On Jul 15, 2017, at 1:07 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> >
> > Drop static on a local variable, when the variable is initialized before
> > any possible use. Thus, the static has no benefit.
>
> I think in this case the use relies on the structure continuing to exist, so a stack object is not an acceptable substitute. Just because it is initialized doesn't mean that it doesn't need a persistent lifetime.
OK, I see. Thanks for the feedback. I'll extend the rule to ensure that
the address of the variable is not taken. Ignore this patch in any case.
julia
>
> > The semantic patch that fixes this problem is as follows:
> > (http://coccinelle.lip6.fr/)
> >
> > // <smpl>
> > @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;
> > // </smpl>
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> >
> > ---
> > These patches are all independent of each other.
> >
> > drivers/mfd/twl4030-irq.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff -u -p a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
> > --- a/drivers/mfd/twl4030-irq.c
> > +++ b/drivers/mfd/twl4030-irq.c
> > @@ -685,7 +685,7 @@ int twl4030_sih_setup(struct device *dev
> >
> > int twl4030_init_irq(struct device *dev, int irq_num)
> > {
> > - static struct irq_chip twl4030_irq_chip;
> > + struct irq_chip twl4030_irq_chip;
> > int status, i;
> > int irq_base, irq_end, nr_irqs;
> > struct device_node *node = dev->of_node;
>
> --
> Mark Rustad, MRustad@gmail.com
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 07/11] mfd: Drop unnecessary static
2017-07-15 20:56 ` Julia Lawall
@ 2017-07-24 19:20 ` Pavel Machek
2017-07-24 22:27 ` Kees Cook
0 siblings, 1 reply; 9+ messages in thread
From: Pavel Machek @ 2017-07-24 19:20 UTC (permalink / raw)
To: Julia Lawall
Cc: Mark D Rustad, Tony Lindgren, keescook, kernel-janitors,
Lee Jones, linux-omap, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
Hi!
> > > Drop static on a local variable, when the variable is initialized before
> > > any possible use. Thus, the static has no benefit.
Actually... it has possible other benefit -- saving stack space. I've
used static for that purpose before. So ... careful with the
automation.
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 07/11] mfd: Drop unnecessary static
2017-07-24 19:20 ` Pavel Machek
@ 2017-07-24 22:27 ` Kees Cook
0 siblings, 0 replies; 9+ messages in thread
From: Kees Cook @ 2017-07-24 22:27 UTC (permalink / raw)
To: Pavel Machek
Cc: Julia Lawall, Mark D Rustad, Tony Lindgren, kernel-janitors,
Lee Jones, linux-omap, LKML
On Mon, Jul 24, 2017 at 12:20 PM, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
>> > > Drop static on a local variable, when the variable is initialized before
>> > > any possible use. Thus, the static has no benefit.
>
> Actually... it has possible other benefit -- saving stack space. I've
> used static for that purpose before. So ... careful with the
> automation.
This means any functions like this must not be thread safe, though...
-Kees
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 07/11] mfd: Drop unnecessary static
2017-07-15 20:07 ` [PATCH 07/11] mfd: " Julia Lawall
2017-07-15 20:49 ` Mark D Rustad
@ 2017-07-25 8:00 ` Lee Jones
1 sibling, 0 replies; 9+ messages in thread
From: Lee Jones @ 2017-07-25 8:00 UTC (permalink / raw)
To: Julia Lawall
Cc: Tony Lindgren, keescook, kernel-janitors, linux-omap,
linux-kernel
On Sat, 15 Jul 2017, Julia Lawall wrote:
> Drop static on a local variable, when the variable is initialized before
> any possible use. Thus, the static has no benefit.
>
> The semantic patch that fixes this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @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;
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
> These patches are all independent of each other.
>
> drivers/mfd/twl4030-irq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Looks like I didn't reply to this patch.
Just to let you know, it has been applied.
> diff -u -p a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
> --- a/drivers/mfd/twl4030-irq.c
> +++ b/drivers/mfd/twl4030-irq.c
> @@ -685,7 +685,7 @@ int twl4030_sih_setup(struct device *dev
>
> int twl4030_init_irq(struct device *dev, int irq_num)
> {
> - static struct irq_chip twl4030_irq_chip;
> + struct irq_chip twl4030_irq_chip;
> int status, i;
> int irq_base, irq_end, nr_irqs;
> struct device_node *node = dev->of_node;
>
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 00/11] Drop unnecessary static
2017-07-15 20:07 [PATCH 00/11] Drop unnecessary static Julia Lawall
2017-07-15 20:07 ` [PATCH 07/11] mfd: " Julia Lawall
@ 2017-07-15 20:37 ` Joe Perches
2017-07-15 21:00 ` Julia Lawall
1 sibling, 1 reply; 9+ messages in thread
From: Joe Perches @ 2017-07-15 20:37 UTC (permalink / raw)
To: Julia Lawall, linux-arm-kernel
Cc: keescook, kernel-janitors, linux-ide, linux-mtd, linux-kernel,
linux-clk, linux-fbdev, linux-omap, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, linux-input,
linux-iio
On Sat, 2017-07-15 at 22:07 +0200, Julia Lawall wrote:
> These patches fix cases where there is a static on a local variable, but
> the variable is initialized before any possible use. Thus, the static has
> no benefit.
Nice one.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 00/11] Drop unnecessary static
2017-07-15 20:37 ` [PATCH 00/11] " Joe Perches
@ 2017-07-15 21:00 ` Julia Lawall
0 siblings, 0 replies; 9+ messages in thread
From: Julia Lawall @ 2017-07-15 21:00 UTC (permalink / raw)
To: Joe Perches
Cc: Julia Lawall, linux-arm-kernel, keescook, kernel-janitors,
linux-ide, linux-mtd, linux-kernel, linux-clk, linux-fbdev,
linux-omap, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-input, linux-iio
On Sat, 15 Jul 2017, Joe Perches wrote:
> On Sat, 2017-07-15 at 22:07 +0200, Julia Lawall wrote:
> > These patches fix cases where there is a static on a local variable, but
> > the variable is initialized before any possible use. Thus, the static has
> > no benefit.
>
> Nice one.
Thanks. It was suggested by Kees Cook a while ago. There seem to be many
opportunities.
julia
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-07-25 8:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-15 20:07 [PATCH 00/11] Drop unnecessary static Julia Lawall
2017-07-15 20:07 ` [PATCH 07/11] mfd: " Julia Lawall
2017-07-15 20:49 ` Mark D Rustad
2017-07-15 20:56 ` Julia Lawall
2017-07-24 19:20 ` Pavel Machek
2017-07-24 22:27 ` Kees Cook
2017-07-25 8:00 ` Lee Jones
2017-07-15 20:37 ` [PATCH 00/11] " Joe Perches
2017-07-15 21:00 ` Julia Lawall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox