* [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init
@ 2026-05-16 10:57 Len Bao
2026-05-25 8:10 ` Linus Walleij
2026-05-26 8:56 ` Bartosz Golaszewski
0 siblings, 2 replies; 4+ messages in thread
From: Len Bao @ 2026-05-16 10:57 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski; +Cc: Len Bao, linux-gpio, linux-kernel
The 'gpio_devt' and 'gpiolib_initialized' variables are initialized only
during the init phase in the 'gpiolib_dev_init' function and never
changed. So, mark these as __ro_after_init.
The 'gpio_stub_drv' variable is initialized only in the declaration and
never changed. So, this variable could be 'const', but using the
'driver_register' and 'driver_unregister' functions discards the 'const'
qualifier. Therefore, as an alternative, mark it as a __ro_after_init.
Signed-off-by: Len Bao <len.bao@gmx.us>
---
drivers/gpio/gpiolib.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1e6dce430..6b2bc0b78 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -55,7 +55,7 @@
/* Device and char device-related information */
static DEFINE_IDA(gpio_ida);
-static dev_t gpio_devt;
+static dev_t gpio_devt __ro_after_init;
#define GPIO_DEV_MAX 256 /* 256 GPIO chip devices supported */
static int gpio_bus_match(struct device *dev, const struct device_driver *drv)
@@ -114,7 +114,7 @@ static int gpiochip_irqchip_init_hw(struct gpio_chip *gc);
static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc);
static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);
-static bool gpiolib_initialized;
+static bool gpiolib_initialized __ro_after_init;
const char *gpiod_get_label(struct gpio_desc *desc)
{
@@ -5340,7 +5340,7 @@ EXPORT_SYMBOL_GPL(gpiod_put_array);
* gpio_device of the GPIO chip with the firmware node and then simply
* bind it to this stub driver.
*/
-static struct device_driver gpio_stub_drv = {
+static struct device_driver gpio_stub_drv __ro_after_init = {
.name = "gpio_stub_drv",
.bus = &gpio_bus_type,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init
2026-05-16 10:57 [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init Len Bao
@ 2026-05-25 8:10 ` Linus Walleij
2026-05-30 10:08 ` Len Bao
2026-05-26 8:56 ` Bartosz Golaszewski
1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2026-05-25 8:10 UTC (permalink / raw)
To: Len Bao
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b,
Kees Cook
Hi Len,
thanks for your patch!
On Sat, May 16, 2026 at 12:58 PM Len Bao <len.bao@gmx.us> wrote:
> The 'gpio_devt' and 'gpiolib_initialized' variables are initialized only
> during the init phase in the 'gpiolib_dev_init' function and never
> changed. So, mark these as __ro_after_init.
>
> The 'gpio_stub_drv' variable is initialized only in the declaration and
> never changed. So, this variable could be 'const', but using the
> 'driver_register' and 'driver_unregister' functions discards the 'const'
> qualifier. Therefore, as an alternative, mark it as a __ro_after_init.
>
> Signed-off-by: Len Bao <len.bao@gmx.us>
Patches like this should be CC to linux-hardening.
Anyways it looks good to me!
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init
2026-05-16 10:57 [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init Len Bao
2026-05-25 8:10 ` Linus Walleij
@ 2026-05-26 8:56 ` Bartosz Golaszewski
1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-05-26 8:56 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Len Bao
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel
On Sat, 16 May 2026 10:57:34 +0000, Len Bao wrote:
> The 'gpio_devt' and 'gpiolib_initialized' variables are initialized only
> during the init phase in the 'gpiolib_dev_init' function and never
> changed. So, mark these as __ro_after_init.
>
> The 'gpio_stub_drv' variable is initialized only in the declaration and
> never changed. So, this variable could be 'const', but using the
> 'driver_register' and 'driver_unregister' functions discards the 'const'
> qualifier. Therefore, as an alternative, mark it as a __ro_after_init.
>
> [...]
Applied, thanks!
[1/1] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init
https://git.kernel.org/brgl/c/b12e12ee4138e30d786eda02223e87044c989bb1
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init
2026-05-25 8:10 ` Linus Walleij
@ 2026-05-30 10:08 ` Len Bao
0 siblings, 0 replies; 4+ messages in thread
From: Len Bao @ 2026-05-30 10:08 UTC (permalink / raw)
To: Linus Walleij
Cc: Len Bao, Bartosz Golaszewski, linux-gpio, linux-kernel,
linux-hardening, Kees Cook
Hi Linus,
On Mon, May 25, 2026 at 10:10:02AM +0200, Linus Walleij wrote:
> Hi Len,
>
> thanks for your patch!
>
> On Sat, May 16, 2026 at 12:58 PM Len Bao <len.bao@gmx.us> wrote:
>
> > The 'gpio_devt' and 'gpiolib_initialized' variables are initialized only
> > during the init phase in the 'gpiolib_dev_init' function and never
> > changed. So, mark these as __ro_after_init.
> >
> > The 'gpio_stub_drv' variable is initialized only in the declaration and
> > never changed. So, this variable could be 'const', but using the
> > 'driver_register' and 'driver_unregister' functions discards the 'const'
> > qualifier. Therefore, as an alternative, mark it as a __ro_after_init.
> >
> > Signed-off-by: Len Bao <len.bao@gmx.us>
>
> Patches like this should be CC to linux-hardening.
Ok, next time I will CC to linux-hardening. Thanks for the guidance.
> Anyways it looks good to me!
> Reviewed-by: Linus Walleij <linusw@kernel.org>
Thanks for your time to look at this.
Regards,
Len Bao
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-30 10:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-16 10:57 [PATCH] gpiolib: Mark gpio_devt, gpiolib_initialized and gpio_stub_drv as __ro_after_init Len Bao
2026-05-25 8:10 ` Linus Walleij
2026-05-30 10:08 ` Len Bao
2026-05-26 8:56 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox