Skip to content

Commit

Permalink
Driver core: Constify struct sysfs_ops in struct kobj_type
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ephox-gcc-plugins authored and gregkh committed Mar 8, 2010
1 parent 6c1733a commit 52cf25d
Show file tree
Hide file tree
Showing 54 changed files with 69 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Documentation/kobject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ kobj_type:

struct kobj_type {
void (*release)(struct kobject *);
struct sysfs_ops *sysfs_ops;
const struct sysfs_ops *sysfs_ops;
struct attribute **default_attrs;
};

Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/kernel/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject * kobj, struct attribute * attr, char *
return ret;
}

static struct sysfs_ops cache_sysfs_ops = {
static const struct sysfs_ops cache_sysfs_ops = {
.show = cache_show
};

Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/cacheinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static struct kobj_attribute *cache_index_opt_attrs[] = {
&cache_assoc_attr,
};

static struct sysfs_ops cache_index_ops = {
static const struct sysfs_ops cache_index_ops = {
.show = cache_index_show,
};

Expand Down
2 changes: 1 addition & 1 deletion arch/sh/kernel/cpu/sh4/sq.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static struct attribute *sq_sysfs_attrs[] = {
NULL,
};

static struct sysfs_ops sq_sysfs_ops = {
static const struct sysfs_ops sq_sysfs_ops = {
.show = sq_sysfs_show,
.store = sq_sysfs_store,
};
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/intel_cacheinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops sysfs_ops = {
static const struct sysfs_ops sysfs_ops = {
.show = show,
.store = store,
};
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/mcheck/mce_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops threshold_ops = {
static const struct sysfs_ops threshold_ops = {
.show = show,
.store = store,
};
Expand Down
2 changes: 1 addition & 1 deletion block/blk-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static struct attribute *integrity_attrs[] = {
NULL,
};

static struct sysfs_ops integrity_ops = {
static const struct sysfs_ops integrity_ops = {
.show = &integrity_attr_show,
.store = &integrity_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static void blk_release_queue(struct kobject *kobj)
kmem_cache_free(blk_requestq_cachep, q);
}

static struct sysfs_ops queue_sysfs_ops = {
static const struct sysfs_ops queue_sysfs_ops = {
.show = queue_attr_show,
.store = queue_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion block/elevator.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
return error;
}

static struct sysfs_ops elv_sysfs_ops = {
static const struct sysfs_ops elv_sysfs_ops = {
.show = elv_attr_show,
.store = elv_attr_store,
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops driver_sysfs_ops = {
static const struct sysfs_ops driver_sysfs_ops = {
.show = drv_attr_show,
.store = drv_attr_store,
};
Expand Down Expand Up @@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops bus_sysfs_ops = {
static const struct sysfs_ops bus_sysfs_ops = {
.show = bus_attr_show,
.store = bus_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj)
kfree(cp);
}

static struct sysfs_ops class_sysfs_ops = {
static const struct sysfs_ops class_sysfs_ops = {
.show = class_attr_show,
.store = class_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops dev_sysfs_ops = {
static const struct sysfs_ops dev_sysfs_ops = {
.show = dev_attr_show,
.store = dev_attr_store,
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/base/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr,
return -EIO;
}

static struct sysfs_ops sysfs_ops = {
static const struct sysfs_ops sysfs_ops = {
.show = sysdev_show,
.store = sysdev_store,
};
Expand Down Expand Up @@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
return -EIO;
}

static struct sysfs_ops sysfs_class_ops = {
static const struct sysfs_ops sysfs_class_ops = {
.show = sysdev_class_show,
.store = sysdev_class_store,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/pktcdvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
return len;
}

static struct sysfs_ops kobj_pkt_ops = {
static const struct sysfs_ops kobj_pkt_ops = {
.show = kobj_pkt_show,
.store = kobj_pkt_store
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ static void cpufreq_sysfs_release(struct kobject *kobj)
complete(&policy->kobj_unregister);
}

static struct sysfs_ops sysfs_ops = {
static const struct sysfs_ops sysfs_ops = {
.show = show,
.store = store,
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/cpuidle/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
return ret;
}

static struct sysfs_ops cpuidle_sysfs_ops = {
static const struct sysfs_ops cpuidle_sysfs_ops = {
.show = cpuidle_show,
.store = cpuidle_store,
};
Expand Down Expand Up @@ -281,7 +281,7 @@ static ssize_t cpuidle_state_show(struct kobject * kobj,
return ret;
}

static struct sysfs_ops cpuidle_state_sysfs_ops = {
static const struct sysfs_ops cpuidle_state_sysfs_ops = {
.show = cpuidle_state_show,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/dma/ioat/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
return entry->show(&chan->common, page);
}

struct sysfs_ops ioat_sysfs_ops = {
const struct sysfs_ops ioat_sysfs_ops = {
.show = ioat_attr_show,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/dma/ioat/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
unsigned long *phys_complete);
void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
void ioat_kobject_del(struct ioatdma_device *device);
extern struct sysfs_ops ioat_sysfs_ops;
extern const struct sysfs_ops ioat_sysfs_ops;
extern struct ioat_sysfs_entry ioat_version_attr;
extern struct ioat_sysfs_entry ioat_cap_attr;
#endif /* IOATDMA_H */
6 changes: 3 additions & 3 deletions drivers/edac/edac_device_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
}

/* edac_dev file operations for an 'ctl_info' */
static struct sysfs_ops device_ctl_info_ops = {
static const struct sysfs_ops device_ctl_info_ops = {
.show = edac_dev_ctl_info_show,
.store = edac_dev_ctl_info_store
};
Expand Down Expand Up @@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(struct kobject *kobj,
}

/* edac_dev file operations for an 'instance' */
static struct sysfs_ops device_instance_ops = {
static const struct sysfs_ops device_instance_ops = {
.show = edac_dev_instance_show,
.store = edac_dev_instance_store
};
Expand Down Expand Up @@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(struct kobject *kobj,
}

/* edac_dev file operations for a 'block' */
static struct sysfs_ops device_block_ops = {
static const struct sysfs_ops device_block_ops = {
.show = edac_dev_block_show,
.store = edac_dev_block_store
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/edac/edac_mc_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
return -EIO;
}

static struct sysfs_ops csrowfs_ops = {
static const struct sysfs_ops csrowfs_ops = {
.show = csrowdev_show,
.store = csrowdev_store
};
Expand Down Expand Up @@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
}

/* Intermediate show/store table */
static struct sysfs_ops mci_ops = {
static const struct sysfs_ops mci_ops = {
.show = mcidev_show,
.store = mcidev_store
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/edac/edac_pci_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
}

/* fs_ops table */
static struct sysfs_ops pci_instance_ops = {
static const struct sysfs_ops pci_instance_ops = {
.show = edac_pci_instance_show,
.store = edac_pci_instance_store
};
Expand Down Expand Up @@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct kobject *kobj,
return -EIO;
}

static struct sysfs_ops edac_pci_sysfs_ops = {
static const struct sysfs_ops edac_pci_sysfs_ops = {
.show = edac_pci_dev_show,
.store = edac_pci_dev_store
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/edd.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
return ret;
}

static struct sysfs_ops edd_attr_ops = {
static const struct sysfs_ops edd_attr_ops = {
.show = edd_attr_show,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops efivar_attr_ops = {
static const struct sysfs_ops efivar_attr_ops = {
.show = efivar_attr_show,
.store = efivar_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/iscsi_ibft.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ static ssize_t ibft_show_attribute(struct kobject *kobj,
return ret;
}

static struct sysfs_ops ibft_attr_ops = {
static const struct sysfs_ops ibft_attr_ops = {
.show = ibft_show_attribute,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/memmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
NULL
};

static struct sysfs_ops memmap_attr_ops = {
static const struct sysfs_ops memmap_attr_ops = {
.show = memmap_attr_show,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/ttm/ttm_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static struct attribute *ttm_bo_global_attrs[] = {
NULL
};

static struct sysfs_ops ttm_bo_global_ops = {
static const struct sysfs_ops ttm_bo_global_ops = {
.show = &ttm_bo_global_show
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/ttm/ttm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_attrs[] = {
NULL
};

static struct sysfs_ops ttm_mem_zone_ops = {
static const struct sysfs_ops ttm_mem_zone_ops = {
.show = &ttm_mem_zone_show,
.store = &ttm_mem_zone_store
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3597,7 +3597,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
atomic_long_read(&group->counter[cm_attr->index]));
}

static struct sysfs_ops cm_counter_ops = {
static const struct sysfs_ops cm_counter_ops = {
.show = cm_show_counter
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kobject *kobj,
return port_attr->show(p, port_attr, buf);
}

static struct sysfs_ops port_sysfs_ops = {
static const struct sysfs_ops port_sysfs_ops = {
.show = port_attr_show
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/md/dm-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
NULL,
};

static struct sysfs_ops dm_sysfs_ops = {
static const struct sysfs_ops dm_sysfs_ops = {
.show = dm_attr_show,
};

Expand Down
4 changes: 2 additions & 2 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ static void rdev_free(struct kobject *ko)
mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
kfree(rdev);
}
static struct sysfs_ops rdev_sysfs_ops = {
static const struct sysfs_ops rdev_sysfs_ops = {
.show = rdev_attr_show,
.store = rdev_attr_store,
};
Expand Down Expand Up @@ -4059,7 +4059,7 @@ static void md_free(struct kobject *ko)
kfree(mddev);
}

static struct sysfs_ops md_sysfs_ops = {
static const struct sysfs_ops md_sysfs_ops = {
.show = md_attr_show,
.store = md_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ibmveth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attrs[] = {
NULL,
};

static struct sysfs_ops veth_pool_ops = {
static const struct sysfs_ops veth_pool_ops = {
.show = veth_pool_show,
.store = veth_pool_store,
};
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/iseries_veth.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static struct attribute *veth_cnx_default_attrs[] = {
NULL
};

static struct sysfs_ops veth_cnx_sysfs_ops = {
static const struct sysfs_ops veth_cnx_sysfs_ops = {
.show = veth_cnx_attribute_show
};

Expand Down Expand Up @@ -441,7 +441,7 @@ static struct attribute *veth_port_default_attrs[] = {
NULL
};

static struct sysfs_ops veth_port_sysfs_ops = {
static const struct sysfs_ops veth_port_sysfs_ops = {
.show = veth_port_attribute_show
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/parisc/pdc_stable.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
return ret;
}

static struct sysfs_ops pdcspath_attr_ops = {
static const struct sysfs_ops pdcspath_attr_ops = {
.show = pdcspath_attr_show,
.store = pdcspath_attr_store,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/pci/hotplug/fakephp.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void legacy_release(struct kobject *kobj)
}

static struct kobj_type legacy_ktype = {
.sysfs_ops = &(struct sysfs_ops){
.sysfs_ops = &(const struct sysfs_ops){
.store = legacy_store, .show = legacy_show
},
.release = &legacy_release,
Expand Down
Loading

0 comments on commit 52cf25d

Please sign in to comment.