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

Configure Feed

Select the types of activity you want to include in your feed.

blk-crypto: make blk_crypto_attr instances const

The blk_crypto_attrs structures are never modified, mark them as const.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: John Garry <john.g.garry@oracle.com>>
Link: https://patch.msgid.link/20260316-b4-sysfs-const-attr-block-v1-3-a35d73b986b0@weissschuh.net
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Thomas Weißschuh and committed by
Jens Axboe
f00d826f 3c912263

+20 -20
+20 -20
block/blk-crypto-sysfs.c
··· 18 18 struct blk_crypto_attr { 19 19 struct attribute attr; 20 20 ssize_t (*show)(struct blk_crypto_profile *profile, 21 - struct blk_crypto_attr *attr, char *page); 21 + const struct blk_crypto_attr *attr, char *page); 22 22 }; 23 23 24 24 static struct blk_crypto_profile *kobj_to_crypto_profile(struct kobject *kobj) ··· 26 26 return container_of(kobj, struct blk_crypto_kobj, kobj)->profile; 27 27 } 28 28 29 - static struct blk_crypto_attr *attr_to_crypto_attr(struct attribute *attr) 29 + static const struct blk_crypto_attr *attr_to_crypto_attr(const struct attribute *attr) 30 30 { 31 - return container_of(attr, struct blk_crypto_attr, attr); 31 + return container_of_const(attr, struct blk_crypto_attr, attr); 32 32 } 33 33 34 34 static ssize_t hw_wrapped_keys_show(struct blk_crypto_profile *profile, 35 - struct blk_crypto_attr *attr, char *page) 35 + const struct blk_crypto_attr *attr, char *page) 36 36 { 37 37 /* Always show supported, since the file doesn't exist otherwise. */ 38 38 return sysfs_emit(page, "supported\n"); 39 39 } 40 40 41 41 static ssize_t max_dun_bits_show(struct blk_crypto_profile *profile, 42 - struct blk_crypto_attr *attr, char *page) 42 + const struct blk_crypto_attr *attr, char *page) 43 43 { 44 44 return sysfs_emit(page, "%u\n", 8 * profile->max_dun_bytes_supported); 45 45 } 46 46 47 47 static ssize_t num_keyslots_show(struct blk_crypto_profile *profile, 48 - struct blk_crypto_attr *attr, char *page) 48 + const struct blk_crypto_attr *attr, char *page) 49 49 { 50 50 return sysfs_emit(page, "%u\n", profile->num_slots); 51 51 } 52 52 53 53 static ssize_t raw_keys_show(struct blk_crypto_profile *profile, 54 - struct blk_crypto_attr *attr, char *page) 54 + const struct blk_crypto_attr *attr, char *page) 55 55 { 56 56 /* Always show supported, since the file doesn't exist otherwise. */ 57 57 return sysfs_emit(page, "supported\n"); 58 58 } 59 59 60 60 #define BLK_CRYPTO_RO_ATTR(_name) \ 61 - static struct blk_crypto_attr _name##_attr = __ATTR_RO(_name) 61 + static const struct blk_crypto_attr _name##_attr = __ATTR_RO(_name) 62 62 63 63 BLK_CRYPTO_RO_ATTR(hw_wrapped_keys); 64 64 BLK_CRYPTO_RO_ATTR(max_dun_bits); ··· 66 66 BLK_CRYPTO_RO_ATTR(raw_keys); 67 67 68 68 static umode_t blk_crypto_is_visible(struct kobject *kobj, 69 - struct attribute *attr, int n) 69 + const struct attribute *attr, int n) 70 70 { 71 71 struct blk_crypto_profile *profile = kobj_to_crypto_profile(kobj); 72 - struct blk_crypto_attr *a = attr_to_crypto_attr(attr); 72 + const struct blk_crypto_attr *a = attr_to_crypto_attr(attr); 73 73 74 74 if (a == &hw_wrapped_keys_attr && 75 75 !(profile->key_types_supported & BLK_CRYPTO_KEY_TYPE_HW_WRAPPED)) ··· 81 81 return 0444; 82 82 } 83 83 84 - static struct attribute *blk_crypto_attrs[] = { 84 + static const struct attribute *const blk_crypto_attrs[] = { 85 85 &hw_wrapped_keys_attr.attr, 86 86 &max_dun_bits_attr.attr, 87 87 &num_keyslots_attr.attr, ··· 90 90 }; 91 91 92 92 static const struct attribute_group blk_crypto_attr_group = { 93 - .attrs = blk_crypto_attrs, 94 - .is_visible = blk_crypto_is_visible, 93 + .attrs_const = blk_crypto_attrs, 94 + .is_visible_const = blk_crypto_is_visible, 95 95 }; 96 96 97 97 /* ··· 99 99 * modes, these are initialized at boot time by blk_crypto_sysfs_init(). 100 100 */ 101 101 static struct blk_crypto_attr __blk_crypto_mode_attrs[BLK_ENCRYPTION_MODE_MAX]; 102 - static struct attribute *blk_crypto_mode_attrs[BLK_ENCRYPTION_MODE_MAX + 1]; 102 + static const struct attribute *blk_crypto_mode_attrs[BLK_ENCRYPTION_MODE_MAX + 1]; 103 103 104 104 static umode_t blk_crypto_mode_is_visible(struct kobject *kobj, 105 - struct attribute *attr, int n) 105 + const struct attribute *attr, int n) 106 106 { 107 107 struct blk_crypto_profile *profile = kobj_to_crypto_profile(kobj); 108 - struct blk_crypto_attr *a = attr_to_crypto_attr(attr); 108 + const struct blk_crypto_attr *a = attr_to_crypto_attr(attr); 109 109 int mode_num = a - __blk_crypto_mode_attrs; 110 110 111 111 if (profile->modes_supported[mode_num]) ··· 114 114 } 115 115 116 116 static ssize_t blk_crypto_mode_show(struct blk_crypto_profile *profile, 117 - struct blk_crypto_attr *attr, char *page) 117 + const struct blk_crypto_attr *attr, char *page) 118 118 { 119 119 int mode_num = attr - __blk_crypto_mode_attrs; 120 120 ··· 123 123 124 124 static const struct attribute_group blk_crypto_modes_attr_group = { 125 125 .name = "modes", 126 - .attrs = blk_crypto_mode_attrs, 127 - .is_visible = blk_crypto_mode_is_visible, 126 + .attrs_const = blk_crypto_mode_attrs, 127 + .is_visible_const = blk_crypto_mode_is_visible, 128 128 }; 129 129 130 130 static const struct attribute_group *blk_crypto_attr_groups[] = { ··· 137 137 struct attribute *attr, char *page) 138 138 { 139 139 struct blk_crypto_profile *profile = kobj_to_crypto_profile(kobj); 140 - struct blk_crypto_attr *a = attr_to_crypto_attr(attr); 140 + const struct blk_crypto_attr *a = attr_to_crypto_attr(attr); 141 141 142 142 return a->show(profile, a, page); 143 143 }