Re: [PATCH] gpio: Document the 'valid_mask' being internal
From: Linus Walleij
Date: Tue Feb 25 2025 - 16:36:27 EST
On Tue, Feb 25, 2025 at 8:01 AM Matti Vaittinen
<mazziesaccount@xxxxxxxxx> wrote:
> The valid_mask member of the struct gpio_chip is unconditionally written
> by the GPIO core at driver registration. Current documentation does not
> mention this but just says the valid_mask is used if it's not NULL. This
> lured me to try populating it directly in the GPIO driver probe instead
> of using the init_valid_mask() callback. It took some retries with
> different bitmaps and eventually a bit of code-reading to understand why
> the valid_mask was not obeyed. I could've avoided this trial and error if
> it was mentioned in the documentation.
>
> Help the next developer who decides to directly populate the valid_mask
> in struct gpio_chip by documenting the valid_mask as internal to the
> GPIO core.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>
Ah typical.
> * If not %NULL, holds bitmask of GPIOs which are valid to be used
> - * from the chip.
> + * from the chip. Internal to GPIO core. Chip drivers should populate
> + * init_valid_mask instead.
> */
> unsigned long *valid_mask;
Actually if we want to protect this struct member from being manipulated
outside of gpiolib, we can maybe move it to struct gpio_device in
drivers/gpio/gpiolib.h?
This struct exist for every gpio_chip but is entirely gpiolib-internal.
Then it becomes impossible to do it wrong...
Yours,
Linus Walleij