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.

firmware_loader: Constify 'struct bin_attribute'

The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Russ Weight <russ.weight@linux.dev>
Link: https://lore.kernel.org/r/20241222-sysfs-const-bin_attr-firmware-v1-1-c35e56bfb4eb@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
c1ecb860 2a8d6abd

+7 -7
+7 -7
drivers/base/firmware_loader/sysfs.c
··· 259 259 } 260 260 261 261 static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj, 262 - struct bin_attribute *bin_attr, 262 + const struct bin_attribute *bin_attr, 263 263 char *buffer, loff_t offset, size_t count) 264 264 { 265 265 struct device *dev = kobj_to_dev(kobj); ··· 316 316 * the driver as a firmware image. 317 317 **/ 318 318 static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj, 319 - struct bin_attribute *bin_attr, 319 + const struct bin_attribute *bin_attr, 320 320 char *buffer, loff_t offset, size_t count) 321 321 { 322 322 struct device *dev = kobj_to_dev(kobj); ··· 356 356 return retval; 357 357 } 358 358 359 - static struct bin_attribute firmware_attr_data = { 359 + static const struct bin_attribute firmware_attr_data = { 360 360 .attr = { .name = "data", .mode = 0644 }, 361 361 .size = 0, 362 - .read = firmware_data_read, 363 - .write = firmware_data_write, 362 + .read_new = firmware_data_read, 363 + .write_new = firmware_data_write, 364 364 }; 365 365 366 366 static struct attribute *fw_dev_attrs[] = { ··· 374 374 NULL 375 375 }; 376 376 377 - static struct bin_attribute *fw_dev_bin_attrs[] = { 377 + static const struct bin_attribute *const fw_dev_bin_attrs[] = { 378 378 &firmware_attr_data, 379 379 NULL 380 380 }; 381 381 382 382 static const struct attribute_group fw_dev_attr_group = { 383 383 .attrs = fw_dev_attrs, 384 - .bin_attrs = fw_dev_bin_attrs, 384 + .bin_attrs_new = fw_dev_bin_attrs, 385 385 #ifdef CONFIG_FW_UPLOAD 386 386 .is_visible = fw_upload_is_visible, 387 387 #endif