Skip to contentSkip to conversation

livepatch: Make kobj_type structures constant

PATCH In review Thomas Weißschuh 2 participants 3 messages Feb 17, 2023 – Mar 9, 2023 Live patching

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 livepatch: Make kobj_type structures constant

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.

---
 kernel/livepatch/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/livepatch/core.c +3 -3
index 201f0c0482fb..3da548755d8a 100644
@@ -581,7 +581,7 @@ static void klp_kobj_release_patch(struct kobject *kobj)
 	complete(&patch->finish);
 }
 
-static struct kobj_type klp_ktype_patch = {
+static const struct kobj_type klp_ktype_patch = {
 	.release = klp_kobj_release_patch,
 	.sysfs_ops = &kobj_sysfs_ops,
 	.default_groups = klp_patch_groups,
@@ -597,7 +597,7 @@ static void klp_kobj_release_object(struct kobject *kobj)
 		klp_free_object_dynamic(obj);
 }
 
-static struct kobj_type klp_ktype_object = {
+static const struct kobj_type klp_ktype_object = {
 	.release = klp_kobj_release_object,
 	.sysfs_ops = &kobj_sysfs_ops,
 	.default_groups = klp_object_groups,
@@ -613,7 +613,7 @@ static void klp_kobj_release_func(struct kobject *kobj)
 		klp_free_func_nop(func);
 }
 
-static struct kobj_type klp_ktype_func = {
+static const struct kobj_type klp_ktype_func = {
 	.release = klp_kobj_release_func,
 	.sysfs_ops = &kobj_sysfs_ops,
 };

---
base-commit: 3ac88fa4605ec98e545fb3ad0154f575fda2de5f
change-id: 20230217-kobj_type-livepatch-74ddff6d453f

Best regards,

Signature · 1 line
Thomas Weißschuh <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Thomas Weißschuh

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.

Best Regards,
Petr

PS: I am going to queue this patch for 6.4. I could eventually add
it into a pull request for 6.3-rc if it was needed because of a more important fix.

This patch is trivial. But even trivial patches should spend at least few days in linux-next...

maintainer
#2 lore raw
In reply to Thomas Weißschuh
Quoted 7 lines · Thomas Weißschuh

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.

JFYI, the patch has been comitted into livepatching.git, branch for-6.4/core.

Best Regards,
Petr