Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio/mdev: Constify struct kobj_type

This 'struct kobj_type' is not modified. It is only used in
kobject_init_and_add() which takes a 'const struct kobj_type *ktype'
parameter.

Constifying this structure and moving it to a read-only section,
and this can increase over all security.

```
[Before]
text data bss dec hex filename
2372 600 0 2972 b9c drivers/vfio/mdev/mdev_sysfs.o

[After]
text data bss dec hex filename
2436 568 0 3004 bbc drivers/vfio/mdev/mdev_sysfs.o
```

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20240904011837.2010444-1-lihongbo22@huawei.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Hongbo Li and committed by
Alex Williamson
27a8204b 7555c7d2

+1 -1
+1 -1
drivers/vfio/mdev/mdev_sysfs.c
··· 160 160 put_device(type->parent->dev); 161 161 } 162 162 163 - static struct kobj_type mdev_type_ktype = { 163 + static const struct kobj_type mdev_type_ktype = { 164 164 .sysfs_ops = &mdev_type_sysfs_ops, 165 165 .release = mdev_type_release, 166 166 .default_groups = mdev_type_groups,