[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdXq-ACdy8C7Efamnwz_h=h8_C4-3y14O8-S61EnB7pWmQ@mail.gmail.com>
Date: Mon, 6 Sep 2021 16:36:27 +0200
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Jason Wang <wangborong@...rlc.com>
Cc: Linus Walleij <linus.walleij@...aro.org>,
Linux-Renesas <linux-renesas-soc@...r.kernel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Arnd Bergmann <arnd@...db.de>
Subject: Re: [PATCH] pinctrl: renesas: no need to initialise global statics
Hi Jason,
On Mon, Sep 6, 2021 at 3:41 PM Jason Wang <wangborong@...rlc.com> wrote:
> Global static variables dont need to be initialised to 0. Because
> the compiler will initialise them.
>
> Signed-off-by: Jason Wang <wangborong@...rlc.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@...ux-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
Powered by blists - more mailing lists