2024-02-04 16:29:25

by Ricardo B. Marliere

[permalink] [raw]
Subject: [PATCH] gpio: gpiolib: make gpio_bus_type const

Now that the driver core can properly handle constant struct bus_type,
move the gpio_bus_type variable to be a constant structure as well,
placing it into read-only memory which can not be modified at runtime.

Cc: Greg Kroah-Hartman <[email protected]>
Suggested-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Ricardo B. Marliere <[email protected]>
---
drivers/gpio/gpiolib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index d50a786f8176..24d046268a01 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -63,7 +63,7 @@ static int gpio_bus_match(struct device *dev, struct device_driver *drv)
return 1;
}

-static struct bus_type gpio_bus_type = {
+static const struct bus_type gpio_bus_type = {
.name = "gpio",
.match = gpio_bus_match,
};

---
base-commit: 3eac8bbed22e940ac1645a884f221bef408f675c
change-id: 20240204-bus_cleanup-gpio-57eea8d32a5a

Best regards,
--
Ricardo B. Marliere <[email protected]>



2024-02-04 19:41:48

by Ricardo B. Marliere

[permalink] [raw]
Subject: Re: [PATCH] gpio: gpiolib: make gpio_bus_type const

Hi Bartosz,

On 4 Feb 19:34, Bartosz Golaszewski wrote:
> On Sun, Feb 4, 2024 at 5:29 PM Ricardo B. Marliere <[email protected]> wrote:
> >
> > Now that the driver core can properly handle constant struct bus_type,
> > move the gpio_bus_type variable to be a constant structure as well,
> > placing it into read-only memory which can not be modified at runtime.
> >
> > Cc: Greg Kroah-Hartman <[email protected]>
> > Suggested-by: Greg Kroah-Hartman <[email protected]>
> > Signed-off-by: Ricardo B. Marliere <[email protected]>
> > ---
> > drivers/gpio/gpiolib.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index d50a786f8176..24d046268a01 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -63,7 +63,7 @@ static int gpio_bus_match(struct device *dev, struct device_driver *drv)
> > return 1;
> > }
> >
> > -static struct bus_type gpio_bus_type = {
> > +static const struct bus_type gpio_bus_type = {
> > .name = "gpio",
> > .match = gpio_bus_match,
> > };
> >
> > ---
> > base-commit: 3eac8bbed22e940ac1645a884f221bef408f675c
> > change-id: 20240204-bus_cleanup-gpio-57eea8d32a5a
> >
> > Best regards,
> > --
> > Ricardo B. Marliere <[email protected]>
> >
>
> Ha! Does the same work now for struct device_type?

From a quick grep it seems to be the case, but maybe you should wait for
Greg for confirmation. Also found this:
https://lore.kernel.org/all/[email protected]/

Best regards,
- Ricardo.



>
> Because I just sent this:
> https://lore.kernel.org/linux-gpio/[email protected]/
>
> And maybe I should make it const right away.
>
> Bart

2024-02-04 23:24:27

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH] gpio: gpiolib: make gpio_bus_type const

On Sun, Feb 4, 2024 at 5:29 PM Ricardo B. Marliere <[email protected]> wrote:
>
> Now that the driver core can properly handle constant struct bus_type,
> move the gpio_bus_type variable to be a constant structure as well,
> placing it into read-only memory which can not be modified at runtime.
>
> Cc: Greg Kroah-Hartman <[email protected]>
> Suggested-by: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Ricardo B. Marliere <[email protected]>
> ---
> drivers/gpio/gpiolib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index d50a786f8176..24d046268a01 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -63,7 +63,7 @@ static int gpio_bus_match(struct device *dev, struct device_driver *drv)
> return 1;
> }
>
> -static struct bus_type gpio_bus_type = {
> +static const struct bus_type gpio_bus_type = {
> .name = "gpio",
> .match = gpio_bus_match,
> };
>
> ---
> base-commit: 3eac8bbed22e940ac1645a884f221bef408f675c
> change-id: 20240204-bus_cleanup-gpio-57eea8d32a5a
>
> Best regards,
> --
> Ricardo B. Marliere <[email protected]>
>

Ha! Does the same work now for struct device_type?

Because I just sent this:
https://lore.kernel.org/linux-gpio/[email protected]/

And maybe I should make it const right away.

Bart

2024-02-05 08:46:08

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH] gpio: gpiolib: make gpio_bus_type const

On Sun, 4 Feb 2024 20:41:52 +0100, "Ricardo B. Marliere"
<[email protected]> said:
> Hi Bartosz,
>
> On 4 Feb 19:34, Bartosz Golaszewski wrote:
>> On Sun, Feb 4, 2024 at 5:29 PM Ricardo B. Marliere <[email protected]> wrote:
>> >
>> > Now that the driver core can properly handle constant struct bus_type,
>> > move the gpio_bus_type variable to be a constant structure as well,
>> > placing it into read-only memory which can not be modified at runtime.
>> >
>> > Cc: Greg Kroah-Hartman <[email protected]>
>> > Suggested-by: Greg Kroah-Hartman <[email protected]>
>> > Signed-off-by: Ricardo B. Marliere <[email protected]>
>> > ---
>> > drivers/gpio/gpiolib.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
>> > index d50a786f8176..24d046268a01 100644
>> > --- a/drivers/gpio/gpiolib.c
>> > +++ b/drivers/gpio/gpiolib.c
>> > @@ -63,7 +63,7 @@ static int gpio_bus_match(struct device *dev, struct device_driver *drv)
>> > return 1;
>> > }
>> >
>> > -static struct bus_type gpio_bus_type = {
>> > +static const struct bus_type gpio_bus_type = {
>> > .name = "gpio",
>> > .match = gpio_bus_match,
>> > };
>> >
>> > ---
>> > base-commit: 3eac8bbed22e940ac1645a884f221bef408f675c
>> > change-id: 20240204-bus_cleanup-gpio-57eea8d32a5a
>> >
>> > Best regards,
>> > --
>> > Ricardo B. Marliere <[email protected]>
>> >
>>
>> Ha! Does the same work now for struct device_type?
>
> From a quick grep it seems to be the case, but maybe you should wait for
> Greg for confirmation. Also found this:
> https://lore.kernel.org/all/[email protected]/
>
> Best regards,
> - Ricardo.
>
>
>
>>
>> Because I just sent this:
>> https://lore.kernel.org/linux-gpio/[email protected]/
>>
>> And maybe I should make it const right away.
>>
>> Bart
>

Turns out it has been like that for years:

commit aed65af1cc2f6fc9ded5a8158f1405a02cf6d2ff
Author: Stephen Hemminger <[email protected]>
Date: Mon Mar 28 09:12:52 2011 -0700

drivers: make device_type const

The device_type structure does not contain data that changes
during usage and should be const. This allows devices to declare
the struct const.

I have patches to change all the subsystems, but need the infra
structure change first.

Signed-off-by: Stephen Hemminger <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

I queued your patch too.

Bart

2024-02-05 19:12:28

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] gpio: gpiolib: make gpio_bus_type const

On Sun, Feb 04, 2024 at 07:34:43PM +0100, Bartosz Golaszewski wrote:
> On Sun, Feb 4, 2024 at 5:29 PM Ricardo B. Marliere <[email protected]> wrote:
> >
> > Now that the driver core can properly handle constant struct bus_type,
> > move the gpio_bus_type variable to be a constant structure as well,
> > placing it into read-only memory which can not be modified at runtime.
> >
> > Cc: Greg Kroah-Hartman <[email protected]>
> > Suggested-by: Greg Kroah-Hartman <[email protected]>
> > Signed-off-by: Ricardo B. Marliere <[email protected]>
> > ---
> > drivers/gpio/gpiolib.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index d50a786f8176..24d046268a01 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -63,7 +63,7 @@ static int gpio_bus_match(struct device *dev, struct device_driver *drv)
> > return 1;
> > }
> >
> > -static struct bus_type gpio_bus_type = {
> > +static const struct bus_type gpio_bus_type = {
> > .name = "gpio",
> > .match = gpio_bus_match,
> > };
> >
> > ---
> > base-commit: 3eac8bbed22e940ac1645a884f221bef408f675c
> > change-id: 20240204-bus_cleanup-gpio-57eea8d32a5a
> >
> > Best regards,
> > --
> > Ricardo B. Marliere <[email protected]>
> >
>
> Ha! Does the same work now for struct device_type?

Very much so, please feel free to do so, that's next on my list of
things to do for the tree.

greg k-h

2024-02-05 19:22:24

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] gpio: gpiolib: make gpio_bus_type const

On Sun, Feb 04, 2024 at 01:29:42PM -0300, Ricardo B. Marliere wrote:
> Now that the driver core can properly handle constant struct bus_type,
> move the gpio_bus_type variable to be a constant structure as well,
> placing it into read-only memory which can not be modified at runtime.
>
> Cc: Greg Kroah-Hartman <[email protected]>
> Suggested-by: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Ricardo B. Marliere <[email protected]>

Reviewed-by: Greg Kroah-Hartman <[email protected]>