linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: renesas: no need to initialise global statics
@ 2021-09-06 13:40 Jason Wang
  2021-09-06 14:36 ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Wang @ 2021-09-06 13:40 UTC (permalink / raw)
  To: linus.walleij
  Cc: geert+renesas, linux-renesas-soc, linux-gpio, linux-kernel, Jason Wang

Global static variables dont need to be initialised to 0. Because
the compiler will initialise them.

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
---
 drivers/pinctrl/renesas/core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/renesas/core.c b/drivers/pinctrl/renesas/core.c
index f2ab02225837..ef8ef05ba930 100644
--- a/drivers/pinctrl/renesas/core.c
+++ b/drivers/pinctrl/renesas/core.c
@@ -741,12 +741,12 @@ static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
 #define SH_PFC_MAX_REGS		300
 #define SH_PFC_MAX_ENUMS	3000
 
-static unsigned int sh_pfc_errors __initdata = 0;
-static unsigned int sh_pfc_warnings __initdata = 0;
-static u32 *sh_pfc_regs __initdata = NULL;
-static u32 sh_pfc_num_regs __initdata = 0;
-static u16 *sh_pfc_enums __initdata = NULL;
-static u32 sh_pfc_num_enums __initdata = 0;
+static unsigned int sh_pfc_errors __initdata;
+static unsigned int sh_pfc_warnings __initdata;
+static u32 *sh_pfc_regs __initdata;
+static u32 sh_pfc_num_regs __initdata;
+static u16 *sh_pfc_enums __initdata;
+static u32 sh_pfc_num_enums __initdata;
 
 #define sh_pfc_err(fmt, ...)					\
 	do {							\
-- 
2.33.0


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

* Re: [PATCH] pinctrl: renesas: no need to initialise global statics
  2021-09-06 13:40 [PATCH] pinctrl: renesas: no need to initialise global statics Jason Wang
@ 2021-09-06 14:36 ` Geert Uytterhoeven
  2021-09-06 15:18   ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2021-09-06 14:36 UTC (permalink / raw)
  To: Jason Wang
  Cc: Linus Walleij, Linux-Renesas, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Arnd Bergmann

Hi Jason,

On Mon, Sep 6, 2021 at 3:41 PM Jason Wang <wangborong@cdjrlc.com> wrote:
> Global static variables dont need to be initialised to 0. Because
> the compiler will initialise them.
>
> Signed-off-by: Jason Wang <wangborong@cdjrlc.com>

Thanks for your patch!

> --- a/drivers/pinctrl/renesas/core.c
> +++ b/drivers/pinctrl/renesas/core.c
> @@ -741,12 +741,12 @@ static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
>  #define SH_PFC_MAX_REGS                300
>  #define SH_PFC_MAX_ENUMS       3000
>
> -static unsigned int sh_pfc_errors __initdata = 0;
> -static unsigned int sh_pfc_warnings __initdata = 0;
> -static u32 *sh_pfc_regs __initdata = NULL;
> -static u32 sh_pfc_num_regs __initdata = 0;
> -static u16 *sh_pfc_enums __initdata = NULL;
> -static u32 sh_pfc_num_enums __initdata = 0;
> +static unsigned int sh_pfc_errors __initdata;
> +static unsigned int sh_pfc_warnings __initdata;
> +static u32 *sh_pfc_regs __initdata;
> +static u32 sh_pfc_num_regs __initdata;
> +static u16 *sh_pfc_enums __initdata;
> +static u32 sh_pfc_num_enums __initdata;

These are special, as they use __initdata.
While dropping the initializers seems to work fine with e.g. gcc 9,
I'm quite sure that would fail with older compiler versions, where
the variable would be put in bss instead of initdata.

See the example in include/linux/init.h, which explicitly
initializes a variable with zero:

    static int init_variable __initdata = 0;

Arnd: do you know in which version of gcc this was fixed?
It seems at least 6.5.0 and later are fine (I don't have all required
shared libs to run e.g. 5.5.0).

>  #define sh_pfc_err(fmt, ...)                                   \
>         do {                                                    \

Gr{oetje,eeting}s,

                        Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] pinctrl: renesas: no need to initialise global statics
  2021-09-06 14:36 ` Geert Uytterhoeven
@ 2021-09-06 15:18   ` Arnd Bergmann
  2021-09-07 11:01     ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2021-09-06 15:18 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jason Wang, Linus Walleij, Linux-Renesas,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	Arnd Bergmann

On Mon, Sep 6, 2021 at 4:36 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > --- a/drivers/pinctrl/renesas/core.c
> > +++ b/drivers/pinctrl/renesas/core.c
> > @@ -741,12 +741,12 @@ static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
> >  #define SH_PFC_MAX_REGS                300
> >  #define SH_PFC_MAX_ENUMS       3000
> >
> > -static unsigned int sh_pfc_errors __initdata = 0;
> > -static unsigned int sh_pfc_warnings __initdata = 0;
> > -static u32 *sh_pfc_regs __initdata = NULL;
> > -static u32 sh_pfc_num_regs __initdata = 0;
> > -static u16 *sh_pfc_enums __initdata = NULL;
> > -static u32 sh_pfc_num_enums __initdata = 0;
> > +static unsigned int sh_pfc_errors __initdata;
> > +static unsigned int sh_pfc_warnings __initdata;
> > +static u32 *sh_pfc_regs __initdata;
> > +static u32 sh_pfc_num_regs __initdata;
> > +static u16 *sh_pfc_enums __initdata;
> > +static u32 sh_pfc_num_enums __initdata;
>
> These are special, as they use __initdata.
> While dropping the initializers seems to work fine with e.g. gcc 9,
> I'm quite sure that would fail with older compiler versions, where
> the variable would be put in bss instead of initdata.
>
> See the example in include/linux/init.h, which explicitly
> initializes a variable with zero:
>
>     static int init_variable __initdata = 0;
>
> Arnd: do you know in which version of gcc this was fixed?
> It seems at least 6.5.0 and later are fine (I don't have all required
> shared libs to run e.g. 5.5.0).

I think you mixed up what happens: As far as I know, older compilers
would put variables without the =0 into .bss, but those with the explicit
=0 would end up in .data. Newer compilers treat them exactly the
same, and these variables all get put into .bss by default. This seems
to already be the case with gcc-4.1, which is the oldest one I could
easily try.

I'm rather sure that regardless of the compiler version, adding an
explicit section attribute like the __initdata would force the section
even on the pre-4.1 compilers.

        Arnd

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

* Re: [PATCH] pinctrl: renesas: no need to initialise global statics
  2021-09-06 15:18   ` Arnd Bergmann
@ 2021-09-07 11:01     ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2021-09-07 11:01 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jason Wang, Linus Walleij, Linux-Renesas,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List

On Mon, Sep 6, 2021 at 5:18 PM Arnd Bergmann <arnd@arndb.de> wrote:
> On Mon, Sep 6, 2021 at 4:36 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > --- a/drivers/pinctrl/renesas/core.c
> > > +++ b/drivers/pinctrl/renesas/core.c
> > > @@ -741,12 +741,12 @@ static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
> > >  #define SH_PFC_MAX_REGS                300
> > >  #define SH_PFC_MAX_ENUMS       3000
> > >
> > > -static unsigned int sh_pfc_errors __initdata = 0;
> > > -static unsigned int sh_pfc_warnings __initdata = 0;
> > > -static u32 *sh_pfc_regs __initdata = NULL;
> > > -static u32 sh_pfc_num_regs __initdata = 0;
> > > -static u16 *sh_pfc_enums __initdata = NULL;
> > > -static u32 sh_pfc_num_enums __initdata = 0;
> > > +static unsigned int sh_pfc_errors __initdata;
> > > +static unsigned int sh_pfc_warnings __initdata;
> > > +static u32 *sh_pfc_regs __initdata;
> > > +static u32 sh_pfc_num_regs __initdata;
> > > +static u16 *sh_pfc_enums __initdata;
> > > +static u32 sh_pfc_num_enums __initdata;
> >
> > These are special, as they use __initdata.
> > While dropping the initializers seems to work fine with e.g. gcc 9,
> > I'm quite sure that would fail with older compiler versions, where
> > the variable would be put in bss instead of initdata.
> >
> > See the example in include/linux/init.h, which explicitly
> > initializes a variable with zero:
> >
> >     static int init_variable __initdata = 0;
> >
> > Arnd: do you know in which version of gcc this was fixed?
> > It seems at least 6.5.0 and later are fine (I don't have all required
> > shared libs to run e.g. 5.5.0).
>
> I think you mixed up what happens: As far as I know, older compilers
> would put variables without the =0 into .bss, but those with the explicit
> =0 would end up in .data. Newer compilers treat them exactly the
> same, and these variables all get put into .bss by default. This seems
> to already be the case with gcc-4.1, which is the oldest one I could
> easily try.
>
> I'm rather sure that regardless of the compiler version, adding an
> explicit section attribute like the __initdata would force the section
> even on the pre-4.1 compilers.

I must be misremembering...

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
i.e. will queue in renesas-pinctrl-for-v5.16.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2021-09-07 11:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 13:40 [PATCH] pinctrl: renesas: no need to initialise global statics Jason Wang
2021-09-06 14:36 ` Geert Uytterhoeven
2021-09-06 15:18   ` Arnd Bergmann
2021-09-07 11:01     ` Geert Uytterhoeven

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).