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

sysfs: treewide: constify attribute callback of bin_attribute::mmap()

The mmap() callbacks should not modify the struct
bin_attribute passed as argument.
Enforce this by marking the argument as const.

As there are not many callback implementers perform this change
throughout the tree at once.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Andrew Donnellan <ajd@linux.ibm.com> # ocxl
Acked-by: Krzysztof Wilczyński <kw@linux.com>
Link: https://lore.kernel.org/r/20241103-sysfs-const-bin_attr-v2-6-71110628844c@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
94a20fb9 b626816f

+13 -13
+3 -3
arch/alpha/kernel/pci-sysfs.c
··· 64 64 * Return: %0 on success, negative error code otherwise 65 65 */ 66 66 static int pci_mmap_resource(struct kobject *kobj, 67 - struct bin_attribute *attr, 67 + const struct bin_attribute *attr, 68 68 struct vm_area_struct *vma, int sparse) 69 69 { 70 70 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); ··· 93 93 } 94 94 95 95 static int pci_mmap_resource_sparse(struct file *filp, struct kobject *kobj, 96 - struct bin_attribute *attr, 96 + const struct bin_attribute *attr, 97 97 struct vm_area_struct *vma) 98 98 { 99 99 return pci_mmap_resource(kobj, attr, vma, 1); 100 100 } 101 101 102 102 static int pci_mmap_resource_dense(struct file *filp, struct kobject *kobj, 103 - struct bin_attribute *attr, 103 + const struct bin_attribute *attr, 104 104 struct vm_area_struct *vma) 105 105 { 106 106 return pci_mmap_resource(kobj, attr, vma, 0);
+1 -1
drivers/misc/ocxl/sysfs.c
··· 125 125 }; 126 126 127 127 static int global_mmio_mmap(struct file *filp, struct kobject *kobj, 128 - struct bin_attribute *bin_attr, 128 + const struct bin_attribute *bin_attr, 129 129 struct vm_area_struct *vma) 130 130 { 131 131 struct ocxl_afu *afu = to_afu(kobj_to_dev(kobj));
+1 -1
drivers/pci/p2pdma.c
··· 90 90 static DEVICE_ATTR_RO(published); 91 91 92 92 static int p2pmem_alloc_mmap(struct file *filp, struct kobject *kobj, 93 - struct bin_attribute *attr, struct vm_area_struct *vma) 93 + const struct bin_attribute *attr, struct vm_area_struct *vma) 94 94 { 95 95 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); 96 96 size_t len = vma->vm_end - vma->vm_start;
+5 -5
drivers/pci/pci-sysfs.c
··· 910 910 * memory space. 911 911 */ 912 912 static int pci_mmap_legacy_mem(struct file *filp, struct kobject *kobj, 913 - struct bin_attribute *attr, 913 + const struct bin_attribute *attr, 914 914 struct vm_area_struct *vma) 915 915 { 916 916 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj)); ··· 930 930 * memory space. Returns -ENOSYS if the operation isn't supported 931 931 */ 932 932 static int pci_mmap_legacy_io(struct file *filp, struct kobject *kobj, 933 - struct bin_attribute *attr, 933 + const struct bin_attribute *attr, 934 934 struct vm_area_struct *vma) 935 935 { 936 936 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj)); ··· 1034 1034 * 1035 1035 * Use the regular PCI mapping routines to map a PCI resource into userspace. 1036 1036 */ 1037 - static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, 1037 + static int pci_mmap_resource(struct kobject *kobj, const struct bin_attribute *attr, 1038 1038 struct vm_area_struct *vma, int write_combine) 1039 1039 { 1040 1040 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); ··· 1059 1059 } 1060 1060 1061 1061 static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj, 1062 - struct bin_attribute *attr, 1062 + const struct bin_attribute *attr, 1063 1063 struct vm_area_struct *vma) 1064 1064 { 1065 1065 return pci_mmap_resource(kobj, attr, vma, 0); 1066 1066 } 1067 1067 1068 1068 static int pci_mmap_resource_wc(struct file *filp, struct kobject *kobj, 1069 - struct bin_attribute *attr, 1069 + const struct bin_attribute *attr, 1070 1070 struct vm_area_struct *vma) 1071 1071 { 1072 1072 return pci_mmap_resource(kobj, attr, vma, 1);
+1 -1
drivers/platform/x86/intel/pmt/class.c
··· 103 103 104 104 static int 105 105 intel_pmt_mmap(struct file *filp, struct kobject *kobj, 106 - struct bin_attribute *attr, struct vm_area_struct *vma) 106 + const struct bin_attribute *attr, struct vm_area_struct *vma) 107 107 { 108 108 struct intel_pmt_entry *entry = container_of(attr, 109 109 struct intel_pmt_entry,
+1 -1
drivers/uio/uio_hv_generic.c
··· 135 135 * The ring buffer is allocated as contiguous memory by vmbus_open 136 136 */ 137 137 static int hv_uio_ring_mmap(struct file *filp, struct kobject *kobj, 138 - struct bin_attribute *attr, 138 + const struct bin_attribute *attr, 139 139 struct vm_area_struct *vma) 140 140 { 141 141 struct vmbus_channel *channel
+1 -1
include/linux/sysfs.h
··· 309 309 char *, loff_t, size_t); 310 310 loff_t (*llseek)(struct file *, struct kobject *, struct bin_attribute *, 311 311 loff_t, int); 312 - int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr, 312 + int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr, 313 313 struct vm_area_struct *vma); 314 314 }; 315 315