[PATCH] kobject: make dynamic_kobj_ktype and kset_ktype const

From: Thomas Weißschuh
Date: Sat Feb 04 2023 - 17:00:09 EST


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 definitions to prevent
modification at runtime.

Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
lib/kobject.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 985ee1c4f2c6..52e2f9634f61 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -729,7 +729,7 @@ static void dynamic_kobj_release(struct kobject *kobj)
kfree(kobj);
}

-static struct kobj_type dynamic_kobj_ktype = {
+static const struct kobj_type dynamic_kobj_ktype = {
.release = dynamic_kobj_release,
.sysfs_ops = &kobj_sysfs_ops,
};
@@ -913,7 +913,7 @@ static void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *
kobject_get_ownership(kobj->parent, uid, gid);
}

-static struct kobj_type kset_ktype = {
+static const struct kobj_type kset_ktype = {
.sysfs_ops = &kobj_sysfs_ops,
.release = kset_release,
.get_ownership = kset_get_ownership,

---
base-commit: db27c22251e7c8f3a9d5bfb55c9c8c701a70bbb3
change-id: 20230204-kobj_type-kobj-d1f02471bbac

Best regards,
--
Thomas Weißschuh <linux@xxxxxxxxxxxxxx>