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

Driver core: Constify struct sysfs_ops in struct kobj_type

Constify struct sysfs_ops.

This is part of the ops structure constification
effort started by Arjan van de Ven et al.

Benefits of this constification:

* prevents modification of data that is shared
(referenced) by many other structure instances
at runtime

* detects/prevents accidental (but not intentional)
modification attempts on archs that enforce
read-only kernel data at runtime

* potentially better optimized code as the compiler
can assume that the const data cannot be changed

* the compiler/linker move const data into .rodata
and therefore exclude them from false sharing

Signed-off-by: Emese Revfy <re.emese@gmail.com>
Acked-by: David Teigland <teigland@redhat.com>
Acked-by: Matt Domsch <Matt_Domsch@dell.com>
Acked-by: Maciej Sosnowski <maciej.sosnowski@intel.com>
Acked-by: Hans J. Koch <hjk@linutronix.de>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Emese Revfy and committed by
Greg Kroah-Hartman
52cf25d0 6c1733ac

+69 -70
+1 -1
Documentation/kobject.txt
··· 266 266 267 267 struct kobj_type { 268 268 void (*release)(struct kobject *); 269 - struct sysfs_ops *sysfs_ops; 269 + const struct sysfs_ops *sysfs_ops; 270 270 struct attribute **default_attrs; 271 271 }; 272 272
+1 -1
arch/ia64/kernel/topology.c
··· 282 282 return ret; 283 283 } 284 284 285 - static struct sysfs_ops cache_sysfs_ops = { 285 + static const struct sysfs_ops cache_sysfs_ops = { 286 286 .show = cache_show 287 287 }; 288 288
+1 -1
arch/powerpc/kernel/cacheinfo.c
··· 642 642 &cache_assoc_attr, 643 643 }; 644 644 645 - static struct sysfs_ops cache_index_ops = { 645 + static const struct sysfs_ops cache_index_ops = { 646 646 .show = cache_index_show, 647 647 }; 648 648
+1 -1
arch/sh/kernel/cpu/sh4/sq.c
··· 326 326 NULL, 327 327 }; 328 328 329 - static struct sysfs_ops sq_sysfs_ops = { 329 + static const struct sysfs_ops sq_sysfs_ops = { 330 330 .show = sq_sysfs_show, 331 331 .store = sq_sysfs_store, 332 332 };
+1 -1
arch/x86/kernel/cpu/intel_cacheinfo.c
··· 903 903 return ret; 904 904 } 905 905 906 - static struct sysfs_ops sysfs_ops = { 906 + static const struct sysfs_ops sysfs_ops = { 907 907 .show = show, 908 908 .store = store, 909 909 };
+1 -1
arch/x86/kernel/cpu/mcheck/mce_amd.c
··· 388 388 return ret; 389 389 } 390 390 391 - static struct sysfs_ops threshold_ops = { 391 + static const struct sysfs_ops threshold_ops = { 392 392 .show = show, 393 393 .store = store, 394 394 };
+1 -1
block/blk-integrity.c
··· 278 278 NULL, 279 279 }; 280 280 281 - static struct sysfs_ops integrity_ops = { 281 + static const struct sysfs_ops integrity_ops = { 282 282 .show = &integrity_attr_show, 283 283 .store = &integrity_attr_store, 284 284 };
+1 -1
block/blk-sysfs.c
··· 450 450 kmem_cache_free(blk_requestq_cachep, q); 451 451 } 452 452 453 - static struct sysfs_ops queue_sysfs_ops = { 453 + static const struct sysfs_ops queue_sysfs_ops = { 454 454 .show = queue_attr_show, 455 455 .store = queue_attr_store, 456 456 };
+1 -1
block/elevator.c
··· 892 892 return error; 893 893 } 894 894 895 - static struct sysfs_ops elv_sysfs_ops = { 895 + static const struct sysfs_ops elv_sysfs_ops = { 896 896 .show = elv_attr_show, 897 897 .store = elv_attr_store, 898 898 };
+2 -2
drivers/base/bus.c
··· 70 70 return ret; 71 71 } 72 72 73 - static struct sysfs_ops driver_sysfs_ops = { 73 + static const struct sysfs_ops driver_sysfs_ops = { 74 74 .show = drv_attr_show, 75 75 .store = drv_attr_store, 76 76 }; ··· 115 115 return ret; 116 116 } 117 117 118 - static struct sysfs_ops bus_sysfs_ops = { 118 + static const struct sysfs_ops bus_sysfs_ops = { 119 119 .show = bus_attr_show, 120 120 .store = bus_attr_store, 121 121 };
+1 -1
drivers/base/class.c
··· 63 63 kfree(cp); 64 64 } 65 65 66 - static struct sysfs_ops class_sysfs_ops = { 66 + static const struct sysfs_ops class_sysfs_ops = { 67 67 .show = class_attr_show, 68 68 .store = class_attr_store, 69 69 };
+1 -1
drivers/base/core.c
··· 100 100 return ret; 101 101 } 102 102 103 - static struct sysfs_ops dev_sysfs_ops = { 103 + static const struct sysfs_ops dev_sysfs_ops = { 104 104 .show = dev_attr_show, 105 105 .store = dev_attr_store, 106 106 };
+2 -2
drivers/base/sys.c
··· 54 54 return -EIO; 55 55 } 56 56 57 - static struct sysfs_ops sysfs_ops = { 57 + static const struct sysfs_ops sysfs_ops = { 58 58 .show = sysdev_show, 59 59 .store = sysdev_store, 60 60 }; ··· 104 104 return -EIO; 105 105 } 106 106 107 - static struct sysfs_ops sysfs_class_ops = { 107 + static const struct sysfs_ops sysfs_class_ops = { 108 108 .show = sysdev_class_show, 109 109 .store = sysdev_class_store, 110 110 };
+1 -1
drivers/block/pktcdvd.c
··· 284 284 return len; 285 285 } 286 286 287 - static struct sysfs_ops kobj_pkt_ops = { 287 + static const struct sysfs_ops kobj_pkt_ops = { 288 288 .show = kobj_pkt_show, 289 289 .store = kobj_pkt_store 290 290 };
+1 -1
drivers/cpufreq/cpufreq.c
··· 766 766 complete(&policy->kobj_unregister); 767 767 } 768 768 769 - static struct sysfs_ops sysfs_ops = { 769 + static const struct sysfs_ops sysfs_ops = { 770 770 .show = show, 771 771 .store = store, 772 772 };
+2 -2
drivers/cpuidle/sysfs.c
··· 195 195 return ret; 196 196 } 197 197 198 - static struct sysfs_ops cpuidle_sysfs_ops = { 198 + static const struct sysfs_ops cpuidle_sysfs_ops = { 199 199 .show = cpuidle_show, 200 200 .store = cpuidle_store, 201 201 }; ··· 281 281 return ret; 282 282 } 283 283 284 - static struct sysfs_ops cpuidle_state_sysfs_ops = { 284 + static const struct sysfs_ops cpuidle_state_sysfs_ops = { 285 285 .show = cpuidle_state_show, 286 286 }; 287 287
+1 -1
drivers/dma/ioat/dma.c
··· 1138 1138 return entry->show(&chan->common, page); 1139 1139 } 1140 1140 1141 - struct sysfs_ops ioat_sysfs_ops = { 1141 + const struct sysfs_ops ioat_sysfs_ops = { 1142 1142 .show = ioat_attr_show, 1143 1143 }; 1144 1144
+1 -1
drivers/dma/ioat/dma.h
··· 346 346 unsigned long *phys_complete); 347 347 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type); 348 348 void ioat_kobject_del(struct ioatdma_device *device); 349 - extern struct sysfs_ops ioat_sysfs_ops; 349 + extern const struct sysfs_ops ioat_sysfs_ops; 350 350 extern struct ioat_sysfs_entry ioat_version_attr; 351 351 extern struct ioat_sysfs_entry ioat_cap_attr; 352 352 #endif /* IOATDMA_H */
+3 -3
drivers/edac/edac_device_sysfs.c
··· 137 137 } 138 138 139 139 /* edac_dev file operations for an 'ctl_info' */ 140 - static struct sysfs_ops device_ctl_info_ops = { 140 + static const struct sysfs_ops device_ctl_info_ops = { 141 141 .show = edac_dev_ctl_info_show, 142 142 .store = edac_dev_ctl_info_store 143 143 }; ··· 373 373 } 374 374 375 375 /* edac_dev file operations for an 'instance' */ 376 - static struct sysfs_ops device_instance_ops = { 376 + static const struct sysfs_ops device_instance_ops = { 377 377 .show = edac_dev_instance_show, 378 378 .store = edac_dev_instance_store 379 379 }; ··· 476 476 } 477 477 478 478 /* edac_dev file operations for a 'block' */ 479 - static struct sysfs_ops device_block_ops = { 479 + static const struct sysfs_ops device_block_ops = { 480 480 .show = edac_dev_block_show, 481 481 .store = edac_dev_block_store 482 482 };
+2 -2
drivers/edac/edac_mc_sysfs.c
··· 245 245 return -EIO; 246 246 } 247 247 248 - static struct sysfs_ops csrowfs_ops = { 248 + static const struct sysfs_ops csrowfs_ops = { 249 249 .show = csrowdev_show, 250 250 .store = csrowdev_store 251 251 }; ··· 575 575 } 576 576 577 577 /* Intermediate show/store table */ 578 - static struct sysfs_ops mci_ops = { 578 + static const struct sysfs_ops mci_ops = { 579 579 .show = mcidev_show, 580 580 .store = mcidev_store 581 581 };
+2 -2
drivers/edac/edac_pci_sysfs.c
··· 121 121 } 122 122 123 123 /* fs_ops table */ 124 - static struct sysfs_ops pci_instance_ops = { 124 + static const struct sysfs_ops pci_instance_ops = { 125 125 .show = edac_pci_instance_show, 126 126 .store = edac_pci_instance_store 127 127 }; ··· 261 261 return -EIO; 262 262 } 263 263 264 - static struct sysfs_ops edac_pci_sysfs_ops = { 264 + static const struct sysfs_ops edac_pci_sysfs_ops = { 265 265 .show = edac_pci_dev_show, 266 266 .store = edac_pci_dev_store 267 267 };
+1 -1
drivers/firmware/edd.c
··· 122 122 return ret; 123 123 } 124 124 125 - static struct sysfs_ops edd_attr_ops = { 125 + static const struct sysfs_ops edd_attr_ops = { 126 126 .show = edd_attr_show, 127 127 }; 128 128
+1 -1
drivers/firmware/efivars.c
··· 362 362 return ret; 363 363 } 364 364 365 - static struct sysfs_ops efivar_attr_ops = { 365 + static const struct sysfs_ops efivar_attr_ops = { 366 366 .show = efivar_attr_show, 367 367 .store = efivar_attr_store, 368 368 };
+1 -1
drivers/firmware/iscsi_ibft.c
··· 519 519 return ret; 520 520 } 521 521 522 - static struct sysfs_ops ibft_attr_ops = { 522 + static const struct sysfs_ops ibft_attr_ops = { 523 523 .show = ibft_show_attribute, 524 524 }; 525 525
+1 -1
drivers/firmware/memmap.c
··· 74 74 NULL 75 75 }; 76 76 77 - static struct sysfs_ops memmap_attr_ops = { 77 + static const struct sysfs_ops memmap_attr_ops = { 78 78 .show = memmap_attr_show, 79 79 }; 80 80
+1 -1
drivers/gpu/drm/ttm/ttm_bo.c
··· 128 128 NULL 129 129 }; 130 130 131 - static struct sysfs_ops ttm_bo_global_ops = { 131 + static const struct sysfs_ops ttm_bo_global_ops = { 132 132 .show = &ttm_bo_global_show 133 133 }; 134 134
+1 -1
drivers/gpu/drm/ttm/ttm_memory.c
··· 152 152 NULL 153 153 }; 154 154 155 - static struct sysfs_ops ttm_mem_zone_ops = { 155 + static const struct sysfs_ops ttm_mem_zone_ops = { 156 156 .show = &ttm_mem_zone_show, 157 157 .store = &ttm_mem_zone_store 158 158 };
+1 -1
drivers/infiniband/core/cm.c
··· 3597 3597 atomic_long_read(&group->counter[cm_attr->index])); 3598 3598 } 3599 3599 3600 - static struct sysfs_ops cm_counter_ops = { 3600 + static const struct sysfs_ops cm_counter_ops = { 3601 3601 .show = cm_show_counter 3602 3602 }; 3603 3603
+1 -1
drivers/infiniband/core/sysfs.c
··· 79 79 return port_attr->show(p, port_attr, buf); 80 80 } 81 81 82 - static struct sysfs_ops port_sysfs_ops = { 82 + static const struct sysfs_ops port_sysfs_ops = { 83 83 .show = port_attr_show 84 84 }; 85 85
+1 -1
drivers/md/dm-sysfs.c
··· 75 75 NULL, 76 76 }; 77 77 78 - static struct sysfs_ops dm_sysfs_ops = { 78 + static const struct sysfs_ops dm_sysfs_ops = { 79 79 .show = dm_attr_show, 80 80 }; 81 81
+2 -2
drivers/md/md.c
··· 2642 2642 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj); 2643 2643 kfree(rdev); 2644 2644 } 2645 - static struct sysfs_ops rdev_sysfs_ops = { 2645 + static const struct sysfs_ops rdev_sysfs_ops = { 2646 2646 .show = rdev_attr_show, 2647 2647 .store = rdev_attr_store, 2648 2648 }; ··· 4059 4059 kfree(mddev); 4060 4060 } 4061 4061 4062 - static struct sysfs_ops md_sysfs_ops = { 4062 + static const struct sysfs_ops md_sysfs_ops = { 4063 4063 .show = md_attr_show, 4064 4064 .store = md_attr_store, 4065 4065 };
+1 -1
drivers/net/ibmveth.c
··· 1577 1577 NULL, 1578 1578 }; 1579 1579 1580 - static struct sysfs_ops veth_pool_ops = { 1580 + static const struct sysfs_ops veth_pool_ops = { 1581 1581 .show = veth_pool_show, 1582 1582 .store = veth_pool_store, 1583 1583 };
+2 -2
drivers/net/iseries_veth.c
··· 384 384 NULL 385 385 }; 386 386 387 - static struct sysfs_ops veth_cnx_sysfs_ops = { 387 + static const struct sysfs_ops veth_cnx_sysfs_ops = { 388 388 .show = veth_cnx_attribute_show 389 389 }; 390 390 ··· 441 441 NULL 442 442 }; 443 443 444 - static struct sysfs_ops veth_port_sysfs_ops = { 444 + static const struct sysfs_ops veth_port_sysfs_ops = { 445 445 .show = veth_port_attribute_show 446 446 }; 447 447
+1 -1
drivers/parisc/pdc_stable.c
··· 481 481 return ret; 482 482 } 483 483 484 - static struct sysfs_ops pdcspath_attr_ops = { 484 + static const struct sysfs_ops pdcspath_attr_ops = { 485 485 .show = pdcspath_attr_show, 486 486 .store = pdcspath_attr_store, 487 487 };
+1 -1
drivers/pci/hotplug/fakephp.c
··· 73 73 } 74 74 75 75 static struct kobj_type legacy_ktype = { 76 - .sysfs_ops = &(struct sysfs_ops){ 76 + .sysfs_ops = &(const struct sysfs_ops){ 77 77 .store = legacy_store, .show = legacy_show 78 78 }, 79 79 .release = &legacy_release,
+1 -1
drivers/pci/slot.c
··· 29 29 return attribute->store ? attribute->store(slot, buf, len) : -EIO; 30 30 } 31 31 32 - static struct sysfs_ops pci_slot_sysfs_ops = { 32 + static const struct sysfs_ops pci_slot_sysfs_ops = { 33 33 .show = pci_slot_attr_show, 34 34 .store = pci_slot_attr_store, 35 35 };
+2 -2
drivers/uio/uio.c
··· 129 129 return entry->show(mem, buf); 130 130 } 131 131 132 - static struct sysfs_ops map_sysfs_ops = { 132 + static const struct sysfs_ops map_sysfs_ops = { 133 133 .show = map_type_show, 134 134 }; 135 135 ··· 217 217 return entry->show(port, buf); 218 218 } 219 219 220 - static struct sysfs_ops portio_sysfs_ops = { 220 + static const struct sysfs_ops portio_sysfs_ops = { 221 221 .show = portio_type_show, 222 222 }; 223 223
+1 -2
drivers/uwb/wlp/sysfs.c
··· 615 615 return ret; 616 616 } 617 617 618 - static 619 - struct sysfs_ops wss_sysfs_ops = { 618 + static const struct sysfs_ops wss_sysfs_ops = { 620 619 .show = wlp_wss_attr_show, 621 620 .store = wlp_wss_attr_store, 622 621 };
+1 -1
drivers/video/omap2/dss/manager.c
··· 341 341 return manager_attr->store(manager, buf, size); 342 342 } 343 343 344 - static struct sysfs_ops manager_sysfs_ops = { 344 + static const struct sysfs_ops manager_sysfs_ops = { 345 345 .show = manager_attr_show, 346 346 .store = manager_attr_store, 347 347 };
+1 -1
drivers/video/omap2/dss/overlay.c
··· 320 320 return overlay_attr->store(overlay, buf, size); 321 321 } 322 322 323 - static struct sysfs_ops overlay_sysfs_ops = { 323 + static const struct sysfs_ops overlay_sysfs_ops = { 324 324 .show = overlay_attr_show, 325 325 .store = overlay_attr_store, 326 326 };
+1 -1
drivers/xen/sys-hypervisor.c
··· 426 426 return 0; 427 427 } 428 428 429 - static struct sysfs_ops hyp_sysfs_ops = { 429 + static const struct sysfs_ops hyp_sysfs_ops = { 430 430 .show = hyp_sysfs_show, 431 431 .store = hyp_sysfs_store, 432 432 };
+2 -2
fs/btrfs/sysfs.c
··· 164 164 complete(&root->kobj_unregister); 165 165 } 166 166 167 - static struct sysfs_ops btrfs_super_attr_ops = { 167 + static const struct sysfs_ops btrfs_super_attr_ops = { 168 168 .show = btrfs_super_attr_show, 169 169 .store = btrfs_super_attr_store, 170 170 }; 171 171 172 - static struct sysfs_ops btrfs_root_attr_ops = { 172 + static const struct sysfs_ops btrfs_root_attr_ops = { 173 173 .show = btrfs_root_attr_show, 174 174 .store = btrfs_root_attr_store, 175 175 };
+1 -1
fs/dlm/lockspace.c
··· 148 148 kfree(ls); 149 149 } 150 150 151 - static struct sysfs_ops dlm_attr_ops = { 151 + static const struct sysfs_ops dlm_attr_ops = { 152 152 .show = dlm_attr_show, 153 153 .store = dlm_attr_store, 154 154 };
+1 -1
fs/ext4/super.c
··· 2358 2358 } 2359 2359 2360 2360 2361 - static struct sysfs_ops ext4_attr_ops = { 2361 + static const struct sysfs_ops ext4_attr_ops = { 2362 2362 .show = ext4_attr_show, 2363 2363 .store = ext4_attr_store, 2364 2364 };
+1 -1
fs/gfs2/sys.c
··· 49 49 return a->store ? a->store(sdp, buf, len) : len; 50 50 } 51 51 52 - static struct sysfs_ops gfs2_attr_ops = { 52 + static const struct sysfs_ops gfs2_attr_ops = { 53 53 .show = gfs2_attr_show, 54 54 .store = gfs2_attr_store, 55 55 };
+1 -1
fs/ocfs2/cluster/masklog.c
··· 136 136 return mlog_mask_store(mlog_attr->mask, buf, count); 137 137 } 138 138 139 - static struct sysfs_ops mlog_attr_ops = { 139 + static const struct sysfs_ops mlog_attr_ops = { 140 140 .show = mlog_show, 141 141 .store = mlog_store, 142 142 };
+4 -4
fs/sysfs/file.c
··· 53 53 size_t count; 54 54 loff_t pos; 55 55 char * page; 56 - struct sysfs_ops * ops; 56 + const struct sysfs_ops * ops; 57 57 struct mutex mutex; 58 58 int needs_read_fill; 59 59 int event; ··· 75 75 { 76 76 struct sysfs_dirent *attr_sd = dentry->d_fsdata; 77 77 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; 78 - struct sysfs_ops * ops = buffer->ops; 78 + const struct sysfs_ops * ops = buffer->ops; 79 79 int ret = 0; 80 80 ssize_t count; 81 81 ··· 199 199 { 200 200 struct sysfs_dirent *attr_sd = dentry->d_fsdata; 201 201 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; 202 - struct sysfs_ops * ops = buffer->ops; 202 + const struct sysfs_ops * ops = buffer->ops; 203 203 int rc; 204 204 205 205 /* need attr_sd for attr and ops, its parent for kobj */ ··· 335 335 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 336 336 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; 337 337 struct sysfs_buffer *buffer; 338 - struct sysfs_ops *ops; 338 + const struct sysfs_ops *ops; 339 339 int error = -EACCES; 340 340 char *p; 341 341
+2 -2
include/linux/kobject.h
··· 106 106 107 107 struct kobj_type { 108 108 void (*release)(struct kobject *kobj); 109 - struct sysfs_ops *sysfs_ops; 109 + const struct sysfs_ops *sysfs_ops; 110 110 struct attribute **default_attrs; 111 111 }; 112 112 ··· 132 132 const char *buf, size_t count); 133 133 }; 134 134 135 - extern struct sysfs_ops kobj_sysfs_ops; 135 + extern const struct sysfs_ops kobj_sysfs_ops; 136 136 137 137 /** 138 138 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
+1 -1
kernel/params.c
··· 722 722 return ret; 723 723 } 724 724 725 - static struct sysfs_ops module_sysfs_ops = { 725 + static const struct sysfs_ops module_sysfs_ops = { 726 726 .show = module_attr_show, 727 727 .store = module_attr_store, 728 728 };
+1 -1
lib/kobject.c
··· 700 700 return ret; 701 701 } 702 702 703 - struct sysfs_ops kobj_sysfs_ops = { 703 + const struct sysfs_ops kobj_sysfs_ops = { 704 704 .show = kobj_attr_show, 705 705 .store = kobj_attr_store, 706 706 };
+1 -1
mm/slub.c
··· 4390 4390 kfree(s); 4391 4391 } 4392 4392 4393 - static struct sysfs_ops slab_sysfs_ops = { 4393 + static const struct sysfs_ops slab_sysfs_ops = { 4394 4394 .show = slab_attr_show, 4395 4395 .store = slab_attr_store, 4396 4396 };
+1 -1
net/bridge/br_private.h
··· 423 423 424 424 #ifdef CONFIG_SYSFS 425 425 /* br_sysfs_if.c */ 426 - extern struct sysfs_ops brport_sysfs_ops; 426 + extern const struct sysfs_ops brport_sysfs_ops; 427 427 extern int br_sysfs_addif(struct net_bridge_port *p); 428 428 429 429 /* br_sysfs_br.c */
+1 -1
net/bridge/br_sysfs_if.c
··· 238 238 return ret; 239 239 } 240 240 241 - struct sysfs_ops brport_sysfs_ops = { 241 + const struct sysfs_ops brport_sysfs_ops = { 242 242 .show = brport_show, 243 243 .store = brport_store, 244 244 };
+1 -1
samples/kobject/kset-example.c
··· 87 87 } 88 88 89 89 /* Our custom sysfs_ops that we will associate with our ktype later on */ 90 - static struct sysfs_ops foo_sysfs_ops = { 90 + static const struct sysfs_ops foo_sysfs_ops = { 91 91 .show = foo_attr_show, 92 92 .store = foo_attr_store, 93 93 };