pinctrl: renesas: no need to initialise global statics
Subsystems (3)
PATCH 1/1 pinctrl: renesas: no need to initialise global statics
Global static variables dont need to be initialised to 0. Because the compiler will initialise them.
--- drivers/pinctrl/renesas/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/pinctrl/renesas/core.c +6 -6
@@ -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 { \
Signature · 1 line
2.33.0
Hi Jason,
Quoted 4 lines · Jason Wang
Global static variables dont need to be initialised to 0. Because the compiler will initialise them.
Signed-off-by Jason Wang <[email protected]>
Thanks for your patch!
Quoted 8 lines
drivers/pinctrl/renesas/core.c +0
-2@@ -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 ;
drivers/pinctrl/renesas/core.c static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } · line 749
Quoted 10 lines
drivers/pinctrl/renesas/core.c +6
-4-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).
drivers/pinctrl/renesas/core.c static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } · line 752
Quoted 2 lines
drivers/pinctrl/renesas/core.c +0
-0#define sh_pfc_err (fmt, ...) \ do { \
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
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
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines
drivers/pinctrl/renesas/core.c +0
-2@@ -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 ;drivers/pinctrl/renesas/core.c static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } · line 749
Quoted 10 lines
drivers/pinctrl/renesas/core.c +6
-4-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.
Quoted 8 lines
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
Geert Uytterhoeven
Reviewed-byQuoted 41 lines · Arnd Bergmann
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines
drivers/pinctrl/renesas/core.c +0
-2@@ -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 ;drivers/pinctrl/renesas/core.c static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } · line 749
Quoted 10 lines
drivers/pinctrl/renesas/core.c +6
-4-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.Quoted 8 lines
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.
Quoted 3 lines
I'm rather sure that regardless of the compiler version, adding an explicit section attribute like the
__initdatawould force the section even on the pre-4.1 compilers.
I must be misremembering...
i.e. will queue in renesas-pinctrl-for-v5.16.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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