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

net: dsa: mv88e6xxx: Constify struct devlink_region_ops and struct mv88e6xxx_region

'struct devlink_region_ops' and 'struct mv88e6xxx_region' are not modified
in this driver.

Constifying these structures moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.

On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
18076 6496 64 24636 603c drivers/net/dsa/mv88e6xxx/devlink.o

After:
=====
text data bss dec hex filename
18652 5920 64 24636 603c drivers/net/dsa/mv88e6xxx/devlink.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/46040062161dda211580002f950a6d60433243dc.1751200453.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Christophe JAILLET and committed by
Jakub Kicinski
ff2d4cfd fad9cf21

+9 -9
+9 -9
drivers/net/dsa/mv88e6xxx/devlink.c
··· 647 647 .id = MV88E6XXX_REGION_GLOBAL1, 648 648 }; 649 649 650 - static struct devlink_region_ops mv88e6xxx_region_global1_ops = { 650 + static const struct devlink_region_ops mv88e6xxx_region_global1_ops = { 651 651 .name = "global1", 652 652 .snapshot = mv88e6xxx_region_global_snapshot, 653 653 .destructor = kfree, ··· 658 658 .id = MV88E6XXX_REGION_GLOBAL2, 659 659 }; 660 660 661 - static struct devlink_region_ops mv88e6xxx_region_global2_ops = { 661 + static const struct devlink_region_ops mv88e6xxx_region_global2_ops = { 662 662 .name = "global2", 663 663 .snapshot = mv88e6xxx_region_global_snapshot, 664 664 .destructor = kfree, 665 665 .priv = &mv88e6xxx_region_global2_priv, 666 666 }; 667 667 668 - static struct devlink_region_ops mv88e6xxx_region_atu_ops = { 668 + static const struct devlink_region_ops mv88e6xxx_region_atu_ops = { 669 669 .name = "atu", 670 670 .snapshot = mv88e6xxx_region_atu_snapshot, 671 671 .destructor = kfree, 672 672 }; 673 673 674 - static struct devlink_region_ops mv88e6xxx_region_vtu_ops = { 674 + static const struct devlink_region_ops mv88e6xxx_region_vtu_ops = { 675 675 .name = "vtu", 676 676 .snapshot = mv88e6xxx_region_vtu_snapshot, 677 677 .destructor = kfree, 678 678 }; 679 679 680 - static struct devlink_region_ops mv88e6xxx_region_stu_ops = { 680 + static const struct devlink_region_ops mv88e6xxx_region_stu_ops = { 681 681 .name = "stu", 682 682 .snapshot = mv88e6xxx_region_stu_snapshot, 683 683 .destructor = kfree, 684 684 }; 685 685 686 - static struct devlink_region_ops mv88e6xxx_region_pvt_ops = { 686 + static const struct devlink_region_ops mv88e6xxx_region_pvt_ops = { 687 687 .name = "pvt", 688 688 .snapshot = mv88e6xxx_region_pvt_snapshot, 689 689 .destructor = kfree, ··· 696 696 }; 697 697 698 698 struct mv88e6xxx_region { 699 - struct devlink_region_ops *ops; 699 + const struct devlink_region_ops *ops; 700 700 u64 size; 701 701 702 702 bool (*cond)(struct mv88e6xxx_chip *chip); 703 703 }; 704 704 705 - static struct mv88e6xxx_region mv88e6xxx_regions[] = { 705 + static const struct mv88e6xxx_region mv88e6xxx_regions[] = { 706 706 [MV88E6XXX_REGION_GLOBAL1] = { 707 707 .ops = &mv88e6xxx_region_global1_ops, 708 708 .size = 32 * sizeof(u16) ··· 768 768 { 769 769 bool (*cond)(struct mv88e6xxx_chip *chip); 770 770 struct mv88e6xxx_chip *chip = ds->priv; 771 - struct devlink_region_ops *ops; 771 + const struct devlink_region_ops *ops; 772 772 struct devlink_region *region; 773 773 u64 size; 774 774 int i, j;