All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s5k5baf: remove unnecessary static in s5k5baf_get_selection()
@ 2017-07-05 18:07 ` Gustavo A. R. Silva
  2017-07-10 12:25   ` Andrzej Hajda
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-05 18:07 UTC (permalink / raw)
  To: Kyungmin Park, Andrzej Hajda, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Gustavo A. R. Silva

Remove unnecessary static on local variable rtype.
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;

In the following log you can see the difference in the code size. Also,
there is a significant difference in the bss segment. This log is the
output of the size command, before and after the code change:

before:
   text    data     bss     dec     hex filename
  27765    5656     320   33741    83cd drivers/media/i2c/s5k5baf.o

after:
   text    data     bss     dec     hex filename
  27733    5600     256   33589    8335 drivers/media/i2c/s5k5baf.o


Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/media/i2c/s5k5baf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 962051b..f01722d 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1374,7 +1374,7 @@ static int s5k5baf_get_selection(struct v4l2_subdev *sd,
 				 struct v4l2_subdev_pad_config *cfg,
 				 struct v4l2_subdev_selection *sel)
 {
-	static enum selection_rect rtype;
+	enum selection_rect rtype;
 	struct s5k5baf *state = to_s5k5baf(sd);
 
 	rtype = s5k5baf_get_sel_rect(sel->pad, sel->target);
-- 
2.5.0

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

* Re: [PATCH] s5k5baf: remove unnecessary static in s5k5baf_get_selection()
  2017-07-05 18:07 ` [PATCH] s5k5baf: remove unnecessary static in s5k5baf_get_selection() Gustavo A. R. Silva
@ 2017-07-10 12:25   ` Andrzej Hajda
  0 siblings, 0 replies; 2+ messages in thread
From: Andrzej Hajda @ 2017-07-10 12:25 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Kyungmin Park, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Sylwester Nawrocki

On 05.07.2017 20:07, Gustavo A. R. Silva wrote:
> Remove unnecessary static on local variable rtype.
> 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;
>
> In the following log you can see the difference in the code size. Also,
> there is a significant difference in the bss segment. This log is the
> output of the size command, before and after the code change:
>
> before:
>    text    data     bss     dec     hex filename
>   27765    5656     320   33741    83cd drivers/media/i2c/s5k5baf.o
>
> after:
>    text    data     bss     dec     hex filename
>   27733    5600     256   33589    8335 drivers/media/i2c/s5k5baf.o
>
>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

 --
Regards
Andrzej

> ---
>  drivers/media/i2c/s5k5baf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 962051b..f01722d 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -1374,7 +1374,7 @@ static int s5k5baf_get_selection(struct v4l2_subdev *sd,
>  				 struct v4l2_subdev_pad_config *cfg,
>  				 struct v4l2_subdev_selection *sel)
>  {
> -	static enum selection_rect rtype;
> +	enum selection_rect rtype;
>  	struct s5k5baf *state = to_s5k5baf(sd);
>  
>  	rtype = s5k5baf_get_sel_rect(sel->pad, sel->target);

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

end of thread, other threads:[~2017-07-10 12:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170705180734epcas5p3b658b32b6b0f5f0c77b7f068fb020d77@epcas5p3.samsung.com>
2017-07-05 18:07 ` [PATCH] s5k5baf: remove unnecessary static in s5k5baf_get_selection() Gustavo A. R. Silva
2017-07-10 12:25   ` Andrzej Hajda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.