lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VfMb_=XKoQNbbVphLg-eQgc6eJbZOW36g_hU=-iK2bSOQ@mail.gmail.com>
Date: Mon, 22 Apr 2024 11:16:31 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Jacky Huang <ychuang570808@...il.com>
Cc: linus.walleij@...aro.org, robh+dt@...nel.org, 
	krzysztof.kozlowski+dt@...aro.org, conor+dt@...nel.org, 
	p.zabel@...gutronix.de, j.neuschaefer@....net, 
	linux-arm-kernel@...ts.infradead.org, linux-gpio@...r.kernel.org, 
	devicetree@...r.kernel.org, linux-kernel@...r.kernel.org, 
	ychuang3@...oton.com, schung@...oton.com
Subject: Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver

On Mon, Apr 22, 2024 at 7:10 AM Jacky Huang <ychuang570808@...il.com> wrote:
> On 2024/4/10 下午 04:54, Andy Shevchenko wrote:

..

> >> +#define MA35_GP_MODE_MASK_WIDTH              2
> >> +
> >> +#define MA35_GP_SLEWCTL_MASK_WIDTH   2
> > I looked at the code how you use these... Oh, please switch to FIELD_GET() /
> > FIELD_PREP() (don't forget to include bitfield.h)
> >
> > ...
> >
> > ...
> >> +             regval &= ~GENMASK(setting->shift + MA35_MFP_BITS_PER_PORT - 1,
> >> +                                setting->shift);
> > This will generate an awful code. Use respective FIELD_*() macros.
> >
> > ...
> >
> >> +     regval &= ~GENMASK(gpio * MA35_GP_MODE_MASK_WIDTH - 1,
> >> +                        gpio * MA35_GP_MODE_MASK_WIDTH);
> >> +     regval |= mode << gpio * MA35_GP_MODE_MASK_WIDTH;
> > Ditto.
> >
> > ...
> >
> >> +     regval &= GENMASK(gpio * MA35_GP_MODE_MASK_WIDTH - 1,
> >> +                       gpio * MA35_GP_MODE_MASK_WIDTH);
> >> +
> >> +     return regval >> gpio * MA35_GP_MODE_MASK_WIDTH;
> > Ditto.

..

> Allow me to remove irrelevant parts.
>
> I attempted to follow your advice and use FIELD_GET() and FIELD_PREP(),
> but found
> it impractical. The reason is that these two macros require their 'mask'
> argument
> to be a constant, otherwise compilation errors occur, which is the issue
> I encountered.
> Since the mask here is calculated and not a constant, compilation errors
> occur.
>
> Taking MA35_GP_REG_MODE as an example, within 32 bits, every 2 bits
> represent
> the mode of a GPIO pin, and the mask is obtained by GENMASK(gpio * 2 -1,
> gpio * 2),

This is not good for the compiler, it can't figure out (at least in
some _supported_ by Linux kernel versions on some architectures) that
GENMASK can be constant here just left-shifted by arbitrary bits.

> where the 'gpio' argument is a variable, not a constant, leading to
> compilation
> errors.
>
> Due to this reason, I will leave this part unchanged, or do you have any
> other suggestions?

If you need non-constant field_get()/field_prep(), add a new patch
that moves them from drivers/iio/temperature/mlx90614.c (and there are
more custom implementations:
https://elixir.bootlin.com/linux/latest/A/ident/field_get) to the
bitfield.h and use them in your code.

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ