From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Dan Carpenter <dan.carpenter@linaro.org>,
linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Biju Das <biju.das.jz@bp.renesas.com>,
Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: Re: [PATCH] pinctrl: renesas: rzg2l: Use BIT_ULL for PIN_CFG_* macros
Date: Mon, 17 Jun 2024 18:05:22 +0100 [thread overview]
Message-ID: <CA+V-a8s8HO4HNjNjs181RR-ffgz68m_+qesP+nk-uJLyif_uDg@mail.gmail.com> (raw)
In-Reply-To: <CAMuHMdUDDfOeQUwmuYKPvAXaXBJCB17ecH8sfpC4=7dTVKthhw@mail.gmail.com>
Hi Geert,
Thank you for the review.
On Mon, Jun 17, 2024 at 2:36 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Prabhakar,
>
> On Mon, Jun 17, 2024 at 3:15 PM Prabhakar <prabhakar.csengg@gmail.com> wrote:
> > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> >
> > Commit 13a8cae6e561 ("pinctrl: renesas: rzg2l: Drop struct
> > rzg2l_variable_pin_cfg") introduced a Smatch static checker warning:
> >
> > drivers/pinctrl/renesas/pinctrl-rzg2l.c:374 rzg2l_pinctrl_get_variable_pin_cfg()
> > warn: was expecting a 64 bit value instead of '~((((1))) << (16))'
> >
> > The function `rzg2l_pinctrl_get_variable_pin_cfg` attempts to mask out
> > `PIN_CFG_VARIABLE` using `BIT(16)`. However, since `pincfg` is a `u64`,
> > this inadvertently masks the high 32 bits as well, which is unintended
> > (on non 64-bit platforms). To correct this, `PIN_CFG_VARIABLE` should
> > be defined using `BIT_ULL(16)`, ensuring proper 64-bit masking.
> >
> > To avoid such issues, update `PIN_CFG_*` macros to use `BIT_ULL()`.
> >
> > Fixes: 13a8cae6e561 ("pinctrl: renesas: rzg2l: Drop struct rzg2l_variable_pin_cfg")
> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Closes: https://lore.kernel.org/all/5c1bf20b-7e94-4b06-95e5-da9f99750203@moroto.mountain/
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Thanks for your patch!
>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> I would like to brainstorm a bit about this, though. See below...
>
> > --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c
> > +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
> > @@ -41,28 +41,28 @@
> > #define MUX_FUNC_MASK GENMASK(31, 16)
> >
> > /* PIN capabilities */
> > -#define PIN_CFG_IOLH_A BIT(0)
> > -#define PIN_CFG_IOLH_B BIT(1)
> > -#define PIN_CFG_SR BIT(2)
> > -#define PIN_CFG_IEN BIT(3)
> > -#define PIN_CFG_PUPD BIT(4)
> > -#define PIN_CFG_IO_VMC_SD0 BIT(5)
> > -#define PIN_CFG_IO_VMC_SD1 BIT(6)
> > -#define PIN_CFG_IO_VMC_QSPI BIT(7)
> > -#define PIN_CFG_IO_VMC_ETH0 BIT(8)
> > -#define PIN_CFG_IO_VMC_ETH1 BIT(9)
> > -#define PIN_CFG_FILONOFF BIT(10)
> > -#define PIN_CFG_FILNUM BIT(11)
> > -#define PIN_CFG_FILCLKSEL BIT(12)
> > -#define PIN_CFG_IOLH_C BIT(13)
> > -#define PIN_CFG_SOFT_PS BIT(14)
> > -#define PIN_CFG_OEN BIT(15)
> > -#define PIN_CFG_VARIABLE BIT(16)
> > -#define PIN_CFG_NOGPIO_INT BIT(17)
> > -#define PIN_CFG_NOD BIT(18) /* N-ch Open Drain */
> > -#define PIN_CFG_SMT BIT(19) /* Schmitt-trigger input control */
> > -#define PIN_CFG_ELC BIT(20)
> > -#define PIN_CFG_IOLH_RZV2H BIT(21)
> > +#define PIN_CFG_IOLH_A BIT_ULL(0)
> > +#define PIN_CFG_IOLH_B BIT_ULL(1)
> > +#define PIN_CFG_SR BIT_ULL(2)
> > +#define PIN_CFG_IEN BIT_ULL(3)
> > +#define PIN_CFG_PUPD BIT_ULL(4)
> > +#define PIN_CFG_IO_VMC_SD0 BIT_ULL(5)
> > +#define PIN_CFG_IO_VMC_SD1 BIT_ULL(6)
> > +#define PIN_CFG_IO_VMC_QSPI BIT_ULL(7)
> > +#define PIN_CFG_IO_VMC_ETH0 BIT_ULL(8)
> > +#define PIN_CFG_IO_VMC_ETH1 BIT_ULL(9)
> > +#define PIN_CFG_FILONOFF BIT_ULL(10)
> > +#define PIN_CFG_FILNUM BIT_ULL(11)
> > +#define PIN_CFG_FILCLKSEL BIT_ULL(12)
> > +#define PIN_CFG_IOLH_C BIT_ULL(13)
> > +#define PIN_CFG_SOFT_PS BIT_ULL(14)
> > +#define PIN_CFG_OEN BIT_ULL(15)
> > +#define PIN_CFG_VARIABLE BIT_ULL(16)
>
> PIN_CFG_VARIABLE looks a bit misplaced here, in between all the flags
> indicating actual capabilities of a pin.
>
> What about relocating it to the "high" half, and moving it next to
> RZG2L_SINGLE_PIN? Perhaps even renaming it to RZG2L_CFG_VARIABLE?
>
OK, I will rename it to RZG2L_CFG_VARIABLE and make it BIT(62) instead.
> > +#define PIN_CFG_NOGPIO_INT BIT_ULL(17)
> > +#define PIN_CFG_NOD BIT_ULL(18) /* N-ch Open Drain */
> > +#define PIN_CFG_SMT BIT_ULL(19) /* Schmitt-trigger input control */
> > +#define PIN_CFG_ELC BIT_ULL(20)
> > +#define PIN_CFG_IOLH_RZV2H BIT_ULL(21)
> >
> > #define RZG2L_MPXED_COMMON_PIN_FUNCS(group) \
> > (PIN_CFG_IOLH_##group | \
>
> Then the other PIN_CFG_* definitions can keep on using BIT().
> To make that safer, PIN_CFG_MASK should be restricted to 32-bit:
>
> -#define PIN_CFG_MASK GENMASK_ULL(46, 0)
> +#define PIN_CFG_MASK GENMASK_ULL(31, 0)
>
> and several u64 variables can be changed to u32 again.
>
> What do you think?
>
Agreed.
Cheers,
Prabhakar
prev parent reply other threads:[~2024-06-17 17:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-17 13:15 [PATCH] pinctrl: renesas: rzg2l: Use BIT_ULL for PIN_CFG_* macros Prabhakar
2024-06-17 13:36 ` Geert Uytterhoeven
2024-06-17 17:05 ` Lad, Prabhakar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+V-a8s8HO4HNjNjs181RR-ffgz68m_+qesP+nk-uJLyif_uDg@mail.gmail.com \
--to=prabhakar.csengg@gmail.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=dan.carpenter@linaro.org \
--cc=fabrizio.castro.jz@renesas.com \
--cc=geert@linux-m68k.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).