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_is_visible()

The is_bin_visible() 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: Martin K. Petersen <martin.petersen@oracle.com>
Acked-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Ira Weiny <ira.weiny@intel.com>
Acked-by: Krzysztof Wilczyński <kw@linux.com>
Link: https://lore.kernel.org/r/20241103-sysfs-const-bin_attr-v2-5-71110628844c@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
b626816f 00ab6e97

+27 -26
+1 -1
drivers/cxl/port.c
··· 173 173 static BIN_ATTR_ADMIN_RO(CDAT, 0); 174 174 175 175 static umode_t cxl_port_bin_attr_is_visible(struct kobject *kobj, 176 - struct bin_attribute *attr, int i) 176 + const struct bin_attribute *attr, int i) 177 177 { 178 178 struct device *dev = kobj_to_dev(kobj); 179 179 struct cxl_port *port = to_cxl_port(dev);
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
··· 3999 3999 } 4000 4000 4001 4001 static umode_t amdgpu_bin_flash_attr_is_visible(struct kobject *kobj, 4002 - struct bin_attribute *attr, 4002 + const struct bin_attribute *attr, 4003 4003 int idx) 4004 4004 { 4005 4005 struct device *dev = kobj_to_dev(kobj);
+1 -1
drivers/infiniband/hw/qib/qib_sysfs.c
··· 283 283 }; 284 284 285 285 static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj, 286 - struct bin_attribute *attr, int n) 286 + const struct bin_attribute *attr, int n) 287 287 { 288 288 struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj); 289 289
+1 -1
drivers/mtd/spi-nor/sysfs.c
··· 87 87 } 88 88 89 89 static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj, 90 - struct bin_attribute *attr, int n) 90 + const struct bin_attribute *attr, int n) 91 91 { 92 92 struct spi_device *spi = to_spi_device(kobj_to_dev(kobj)); 93 93 struct spi_mem *spimem = spi_get_drvdata(spi);
+2 -1
drivers/nvmem/core.c
··· 298 298 } 299 299 300 300 static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, 301 - struct bin_attribute *attr, int i) 301 + const struct bin_attribute *attr, 302 + int i) 302 303 { 303 304 struct device *dev = kobj_to_dev(kobj); 304 305 struct nvmem_device *nvmem = to_nvmem_device(dev);
+1 -1
drivers/pci/pci-sysfs.c
··· 1326 1326 }; 1327 1327 1328 1328 static umode_t pci_dev_rom_attr_is_visible(struct kobject *kobj, 1329 - struct bin_attribute *a, int n) 1329 + const struct bin_attribute *a, int n) 1330 1330 { 1331 1331 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); 1332 1332
+1 -1
drivers/pci/vpd.c
··· 325 325 }; 326 326 327 327 static umode_t vpd_attr_is_visible(struct kobject *kobj, 328 - struct bin_attribute *a, int n) 328 + const struct bin_attribute *a, int n) 329 329 { 330 330 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); 331 331
+1 -1
drivers/platform/x86/amd/hsmp.c
··· 620 620 } 621 621 622 622 static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, 623 - struct bin_attribute *battr, int id) 623 + const struct bin_attribute *battr, int id) 624 624 { 625 625 if (plat_dev.proto_ver == HSMP_PROTO_VER6) 626 626 return battr->attr.mode;
+1 -1
drivers/platform/x86/intel/sdsi.c
··· 541 541 }; 542 542 543 543 static umode_t 544 - sdsi_battr_is_visible(struct kobject *kobj, struct bin_attribute *attr, int n) 544 + sdsi_battr_is_visible(struct kobject *kobj, const struct bin_attribute *attr, int n) 545 545 { 546 546 struct device *dev = kobj_to_dev(kobj); 547 547 struct sdsi_priv *priv = dev_get_drvdata(dev);
+1 -1
drivers/scsi/scsi_sysfs.c
··· 1274 1274 } 1275 1275 1276 1276 static umode_t scsi_sdev_bin_attr_is_visible(struct kobject *kobj, 1277 - struct bin_attribute *attr, int i) 1277 + const struct bin_attribute *attr, int i) 1278 1278 { 1279 1279 struct device *dev = kobj_to_dev(kobj); 1280 1280 struct scsi_device *sdev = to_scsi_device(dev);
+1 -1
drivers/usb/core/sysfs.c
··· 925 925 }; 926 926 927 927 static umode_t dev_bin_attrs_are_visible(struct kobject *kobj, 928 - struct bin_attribute *a, int n) 928 + const struct bin_attribute *a, int n) 929 929 { 930 930 struct device *dev = kobj_to_dev(kobj); 931 931 struct usb_device *udev = to_usb_device(dev);
+15 -15
include/linux/sysfs.h
··· 101 101 umode_t (*is_visible)(struct kobject *, 102 102 struct attribute *, int); 103 103 umode_t (*is_bin_visible)(struct kobject *, 104 - struct bin_attribute *, int); 104 + const struct bin_attribute *, int); 105 105 size_t (*bin_size)(struct kobject *, 106 106 const struct bin_attribute *, 107 107 int); ··· 199 199 * attributes, the group visibility is determined by the function 200 200 * specified to is_visible() not is_bin_visible() 201 201 */ 202 - #define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \ 203 - static inline umode_t sysfs_group_visible_##name( \ 204 - struct kobject *kobj, struct bin_attribute *attr, int n) \ 205 - { \ 206 - if (n == 0 && !name##_group_visible(kobj)) \ 207 - return SYSFS_GROUP_INVISIBLE; \ 208 - return name##_attr_visible(kobj, attr, n); \ 202 + #define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \ 203 + static inline umode_t sysfs_group_visible_##name( \ 204 + struct kobject *kobj, const struct bin_attribute *attr, int n) \ 205 + { \ 206 + if (n == 0 && !name##_group_visible(kobj)) \ 207 + return SYSFS_GROUP_INVISIBLE; \ 208 + return name##_attr_visible(kobj, attr, n); \ 209 209 } 210 210 211 - #define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \ 212 - static inline umode_t sysfs_group_visible_##name( \ 213 - struct kobject *kobj, struct bin_attribute *a, int n) \ 214 - { \ 215 - if (n == 0 && !name##_group_visible(kobj)) \ 216 - return SYSFS_GROUP_INVISIBLE; \ 217 - return a->mode; \ 211 + #define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \ 212 + static inline umode_t sysfs_group_visible_##name( \ 213 + struct kobject *kobj, const struct bin_attribute *a, int n) \ 214 + { \ 215 + if (n == 0 && !name##_group_visible(kobj)) \ 216 + return SYSFS_GROUP_INVISIBLE; \ 217 + return a->mode; \ 218 218 } 219 219 220 220 #define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn