public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: Document the 'valid_mask' being internal
@ 2025-02-25  7:00 Matti Vaittinen
  2025-02-25 21:36 ` Linus Walleij
  0 siblings, 1 reply; 15+ messages in thread
From: Matti Vaittinen @ 2025-02-25  7:00 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1802 bytes --]

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@gmail.com>
---
Alternative approach would be to check whether the valid_mask is NULL at
gpio_chip registration and touch it only if it is NULL. This, however,
might cause problems if any of the existing drivers pass the struct
gpio_chip with uninitialized valid_mask field to the registration. In
order to avoid this I decided to keep current behaviour while
documenting it a bit better.
---
 include/linux/gpio/driver.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 2dd7cb9cc270..fe80c65dacb0 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -503,7 +503,8 @@ struct gpio_chip {
 	 * @valid_mask:
 	 *
 	 * 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;
 

base-commit: d082ecbc71e9e0bf49883ee4afd435a77a5101b6
-- 
2.48.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-02-28 11:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25  7:00 [PATCH] gpio: Document the 'valid_mask' being internal Matti Vaittinen
2025-02-25 21:36 ` Linus Walleij
2025-02-26  6:09   ` Matti Vaittinen
2025-02-26 10:18     ` Linus Walleij
2025-02-26 11:42       ` Matti Vaittinen
2025-02-27  8:24         ` Matti Vaittinen
2025-02-28  8:23           ` Linus Walleij
2025-02-28  8:31             ` Matti Vaittinen
2025-02-28  9:28             ` Matti Vaittinen
2025-02-28  9:42               ` Matti Vaittinen
2025-02-28 10:00                 ` Matti Vaittinen
2025-02-28  8:06         ` Linus Walleij
2025-02-28  9:32           ` Geert Uytterhoeven
2025-02-28 10:28             ` Biju Das
2025-02-28 11:02               ` Matti Vaittinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox