linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] Drop unnecessary static
@ 2017-05-04 20:10 Julia Lawall
  2017-05-04 20:10 ` [PATCH 7/9] iio: hid-sensor-accel-3d: " Julia Lawall
  2017-06-27 23:47 ` [PATCH 0/9] " Kees Cook
  0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2017-05-04 20:10 UTC (permalink / raw)
  To: linux-pm
  Cc: keescook, kernel-janitors, linux-mtd, linux-kernel, drbd-dev,
	linux-omap, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-input, linux-iio

These patches fix cases where there is a static on a local variable, but
the variable is either first initialized or never used, on every possible
execution path through the function.  The static has no benefit, and
dropping it reduces the code size.

---

 drivers/block/drbd/drbd_nl.c            |    2 +-
 drivers/clocksource/timer-fttmr010.c    |    2 +-
 drivers/iio/accel/hid-sensor-accel-3d.c |    2 +-
 drivers/mfd/max8925-i2c.c               |    2 +-
 drivers/mfd/twl4030-irq.c               |    2 +-
 drivers/mtd/chips/cfi_cmdset_0020.c     |    2 +-
 drivers/mtd/maps/physmap_of_gemini.c    |    2 +-
 drivers/power/supply/axp20x_usb_power.c |    2 +-
 drivers/regulator/palmas-regulator.c    |    2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 7/9] iio: hid-sensor-accel-3d: Drop unnecessary static
  2017-05-04 20:10 [PATCH 0/9] Drop unnecessary static Julia Lawall
@ 2017-05-04 20:10 ` Julia Lawall
  2017-05-07 12:57   ` Jonathan Cameron
  2017-06-27 23:47 ` [PATCH 0/9] " Kees Cook
  1 sibling, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2017-05-04 20:10 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: keescook, kernel-janitors, Jonathan Cameron, Srinivas Pandruvada,
	Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-input, linux-iio, linux-kernel

Drop static on a local variable, when the variable is initialized before
use, on every possible execution path through the function.  The static has
no benefit, and dropping it reduces the code size.

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>

The change in code size is indicates by the following output from the size
command.

before:
   text    data     bss     dec     hex filename
   3879     512       8    4399    112f drivers/iio/accel/hid-sensor-accel-3d.o

after:
   text    data     bss     dec     hex filename
   3863     512       0    4375    1117 drivers/iio/accel/hid-sensor-accel-3d.o

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/iio/accel/hid-sensor-accel-3d.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 43a6cb0..2238a26 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -347,7 +347,7 @@ static int accel_3d_parse_report(struct platform_device *pdev,
 static int hid_accel_3d_probe(struct platform_device *pdev)
 {
 	int ret = 0;
-	static const char *name;
+	const char *name;
 	struct iio_dev *indio_dev;
 	struct accel_3d_state *accel_state;
 	const struct iio_chan_spec *channel_spec;


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 7/9] iio: hid-sensor-accel-3d: Drop unnecessary static
  2017-05-04 20:10 ` [PATCH 7/9] iio: hid-sensor-accel-3d: " Julia Lawall
@ 2017-05-07 12:57   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-05-07 12:57 UTC (permalink / raw)
  To: Julia Lawall, Jiri Kosina
  Cc: keescook, kernel-janitors, Srinivas Pandruvada, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, linux-input,
	linux-iio, linux-kernel

On 04/05/17 21:10, Julia Lawall wrote:
> Drop static on a local variable, when the variable is initialized before
> use, on every possible execution path through the function.  The static has
> no benefit, and dropping it reduces the code size.
> 
> 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>
> 
> The change in code size is indicates by the following output from the size
> command.
> 
> before:
>    text    data     bss     dec     hex filename
>    3879     512       8    4399    112f drivers/iio/accel/hid-sensor-accel-3d.o
> 
> after:
>    text    data     bss     dec     hex filename
>    3863     512       0    4375    1117 drivers/iio/accel/hid-sensor-accel-3d.o
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan
> 
> ---
>  drivers/iio/accel/hid-sensor-accel-3d.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index 43a6cb0..2238a26 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -347,7 +347,7 @@ static int accel_3d_parse_report(struct platform_device *pdev,
>  static int hid_accel_3d_probe(struct platform_device *pdev)
>  {
>  	int ret = 0;
> -	static const char *name;
> +	const char *name;
>  	struct iio_dev *indio_dev;
>  	struct accel_3d_state *accel_state;
>  	const struct iio_chan_spec *channel_spec;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/9] Drop unnecessary static
  2017-05-04 20:10 [PATCH 0/9] Drop unnecessary static Julia Lawall
  2017-05-04 20:10 ` [PATCH 7/9] iio: hid-sensor-accel-3d: " Julia Lawall
@ 2017-06-27 23:47 ` Kees Cook
  1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2017-06-27 23:47 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Linux PM list, kernel-janitors, Linux mtd, LKML, drbd-dev,
	linux-omap, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-input, linux-iio

On Thu, May 4, 2017 at 1:10 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> These patches fix cases where there is a static on a local variable, but
> the variable is either first initialized or never used, on every possible
> execution path through the function.  The static has no benefit, and
> dropping it reduces the code size.
>
> ---
>
>  drivers/block/drbd/drbd_nl.c            |    2 +-
>  drivers/clocksource/timer-fttmr010.c    |    2 +-
>  drivers/iio/accel/hid-sensor-accel-3d.c |    2 +-
>  drivers/mfd/max8925-i2c.c               |    2 +-
>  drivers/mfd/twl4030-irq.c               |    2 +-
>  drivers/mtd/chips/cfi_cmdset_0020.c     |    2 +-
>  drivers/mtd/maps/physmap_of_gemini.c    |    2 +-
>  drivers/power/supply/axp20x_usb_power.c |    2 +-
>  drivers/regulator/palmas-regulator.c    |    2 +-
>  9 files changed, 9 insertions(+), 9 deletions(-)

It looks like most of these were taken. I pinged the other three. Thanks!

-Kees

-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-27 23:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-04 20:10 [PATCH 0/9] Drop unnecessary static Julia Lawall
2017-05-04 20:10 ` [PATCH 7/9] iio: hid-sensor-accel-3d: " Julia Lawall
2017-05-07 12:57   ` Jonathan Cameron
2017-06-27 23:47 ` [PATCH 0/9] " Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).