[PATCH net-next v2 1/2] net: bridge: make kobj_type structure constant

Thomas Weißschuh posted 2 patches 2 years, 6 months ago
[PATCH net-next v2 1/2] net: bridge: make kobj_type structure constant
Posted by Thomas Weißschuh 2 years, 6 months ago
Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.")
the driver core allows the usage of const struct kobj_type.

Take advantage of this to constify the structure definition to prevent
modification at runtime.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 net/bridge/br_if.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index ad13b48e3e08..24f01ff113f0 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -269,7 +269,7 @@ static void brport_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t
 	net_ns_get_ownership(dev_net(p->dev), uid, gid);
 }
 
-static struct kobj_type brport_ktype = {
+static const struct kobj_type brport_ktype = {
 #ifdef CONFIG_SYSFS
 	.sysfs_ops = &brport_sysfs_ops,
 #endif

-- 
2.39.1

Re: [PATCH net-next v2 1/2] net: bridge: make kobj_type structure constant
Posted by Nikolay Aleksandrov 2 years, 6 months ago
On 14/02/2023 06:23, Thomas Weißschuh wrote:
> Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.")
> the driver core allows the usage of const struct kobj_type.
> 
> Take advantage of this to constify the structure definition to prevent
> modification at runtime.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  net/bridge/br_if.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index ad13b48e3e08..24f01ff113f0 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -269,7 +269,7 @@ static void brport_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t
>  	net_ns_get_ownership(dev_net(p->dev), uid, gid);
>  }
>  
> -static struct kobj_type brport_ktype = {
> +static const struct kobj_type brport_ktype = {
>  #ifdef CONFIG_SYSFS
>  	.sysfs_ops = &brport_sysfs_ops,
>  #endif
> 

Acked-by: Nikolay Aleksandrov <razor@blackwall.org>