2017-07-05 04:04:18

by Gustavo A. R. Silva

[permalink] [raw]
Subject: [PATCH] cpufreq: speedstep: remove unnecessary static in speedstep_detect_chipset()

Remove unnecessary static on local variable hostbridge.
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
5084 3392 256 8732 221c drivers/cpufreq/speedstep-ich.o

after:
text data bss dec hex filename
5062 3304 192 8558 216e drivers/cpufreq/speedstep-ich.o

Signed-off-by: Gustavo A. R. Silva <[email protected]>
---
drivers/cpufreq/speedstep-ich.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
index b86953a..0412a24 100644
--- a/drivers/cpufreq/speedstep-ich.c
+++ b/drivers/cpufreq/speedstep-ich.c
@@ -207,7 +207,7 @@ static unsigned int speedstep_detect_chipset(void)
* 8100 which use a pretty old revision of the 82815
* host bridge. Abort on these systems.
*/
- static struct pci_dev *hostbridge;
+ struct pci_dev *hostbridge;

hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_INTEL_82815_MC,
--
2.5.0


2017-07-05 03:53:50

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: speedstep: remove unnecessary static in speedstep_detect_chipset()

+ Dominic,

On 04-07-17, 22:09, Gustavo A. R. Silva wrote:
> Remove unnecessary static on local variable hostbridge.
> 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
> 5084 3392 256 8732 221c drivers/cpufreq/speedstep-ich.o
>
> after:
> text data bss dec hex filename
> 5062 3304 192 8558 216e drivers/cpufreq/speedstep-ich.o
>
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
> drivers/cpufreq/speedstep-ich.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
> index b86953a..0412a24 100644
> --- a/drivers/cpufreq/speedstep-ich.c
> +++ b/drivers/cpufreq/speedstep-ich.c
> @@ -207,7 +207,7 @@ static unsigned int speedstep_detect_chipset(void)
> * 8100 which use a pretty old revision of the 82815
> * host bridge. Abort on these systems.
> */
> - static struct pci_dev *hostbridge;
> + struct pci_dev *hostbridge;

This was added way back Sep'02 by Dominic (@Dominic: I hope you are the same
Dominic with a different email id) and I don't think we need it to be static
here. Anyway, Dominic can respond on that.

commit 1673f3b404bd ("[PATCH] CPUfreq i386 drivers update")

(Note: You can find it in history kernel git repo, not the current one).

Acked-by: Viresh Kumar <[email protected]>

--
viresh

2017-07-05 10:14:09

by Dominik Brodowski

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: speedstep: remove unnecessary static in speedstep_detect_chipset()

Viresh, Gustavo,

On Wed, Jul 05, 2017 at 09:23:44AM +0530, Viresh Kumar wrote:
> + Dominic,
>
> On 04-07-17, 22:09, Gustavo A. R. Silva wrote:
> > Remove unnecessary static on local variable hostbridge.
> > 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
> > 5084 3392 256 8732 221c drivers/cpufreq/speedstep-ich.o
> >
> > after:
> > text data bss dec hex filename
> > 5062 3304 192 8558 216e drivers/cpufreq/speedstep-ich.o
> >
> > Signed-off-by: Gustavo A. R. Silva <[email protected]>
> > ---
> > drivers/cpufreq/speedstep-ich.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
> > index b86953a..0412a24 100644
> > --- a/drivers/cpufreq/speedstep-ich.c
> > +++ b/drivers/cpufreq/speedstep-ich.c
> > @@ -207,7 +207,7 @@ static unsigned int speedstep_detect_chipset(void)
> > * 8100 which use a pretty old revision of the 82815
> > * host bridge. Abort on these systems.
> > */
> > - static struct pci_dev *hostbridge;
> > + struct pci_dev *hostbridge;
>
> This was added way back Sep'02 by Dominic (@Dominic: I hope you are the same
> Dominic with a different email id) and I don't think we need it to be static
> here. Anyway, Dominic can respond on that.
>
> commit 1673f3b404bd ("[PATCH] CPUfreq i386 drivers update")
>
> (Note: You can find it in history kernel git repo, not the current one).
>
> Acked-by: Viresh Kumar <[email protected]>

indeed, that's me, and the patch seems to be valid and therefore is a useful
improvement:

Acked-by: Dominik Brodowski <[email protected]>

Thanks,
Dominik

2017-07-21 22:46:17

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] cpufreq: speedstep: remove unnecessary static in speedstep_detect_chipset()

On Tuesday, July 04, 2017 10:09:21 PM Gustavo A. R. Silva wrote:
> Remove unnecessary static on local variable hostbridge.
> 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
> 5084 3392 256 8732 221c drivers/cpufreq/speedstep-ich.o
>
> after:
> text data bss dec hex filename
> 5062 3304 192 8558 216e drivers/cpufreq/speedstep-ich.o
>
> Signed-off-by: Gustavo A. R. Silva <[email protected]>
> ---
> drivers/cpufreq/speedstep-ich.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
> index b86953a..0412a24 100644
> --- a/drivers/cpufreq/speedstep-ich.c
> +++ b/drivers/cpufreq/speedstep-ich.c
> @@ -207,7 +207,7 @@ static unsigned int speedstep_detect_chipset(void)
> * 8100 which use a pretty old revision of the 82815
> * host bridge. Abort on these systems.
> */
> - static struct pci_dev *hostbridge;
> + struct pci_dev *hostbridge;
>
> hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL,
> PCI_DEVICE_ID_INTEL_82815_MC,
>

Applied, thanks!