Skip to content

Commit

Permalink
[PATCH] mark struct file_operations const 9
Browse files Browse the repository at this point in the history
Many struct file_operations in the kernel can be "const".  Marking them const
moves these to the .rodata section, which avoids false sharing with potential
dirty data.  In addition it'll catch accidental writes at compile time to
these shared resources.

Signed-off-by: Arjan van de Ven <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
fenrus75 authored and Linus Torvalds committed Feb 12, 2007
1 parent da7071d commit 9c2e08c
Show file tree
Hide file tree
Showing 32 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/cell/spufs/spufs.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ long spufs_run_spu(struct file *file,
struct spu_context *ctx, u32 *npc, u32 *status);
long spufs_create(struct nameidata *nd,
unsigned int flags, mode_t mode);
extern struct file_operations spufs_context_fops;
extern const struct file_operations spufs_context_fops;

/* gang management */
struct spu_gang *alloc_spu_gang(void);
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/char/tape_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static struct class *tape_class;
struct tape_class_device *register_tape_dev(
struct device * device,
dev_t dev,
struct file_operations *fops,
const struct file_operations *fops,
char * device_name,
char * mode_name)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/char/tape_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct tape_class_device {
struct tape_class_device *register_tape_dev(
struct device * device,
dev_t dev,
struct file_operations *fops,
const struct file_operations *fops,
char * device_name,
char * node_name
);
Expand Down
4 changes: 2 additions & 2 deletions security/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int default_open(struct inode *inode, struct file *file)
return 0;
}

static struct file_operations default_file_ops = {
static const struct file_operations default_file_ops = {
.read = default_read_file,
.write = default_write_file,
.open = default_open,
Expand Down Expand Up @@ -215,7 +215,7 @@ static int create_by_name(const char *name, mode_t mode,
*/
struct dentry *securityfs_create_file(const char *name, mode_t mode,
struct dentry *parent, void *data,
struct file_operations *fops)
const struct file_operations *fops)
{
struct dentry *dentry = NULL;
int error;
Expand Down
4 changes: 2 additions & 2 deletions security/keys/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct seq_operations proc_keys_ops = {
.show = proc_keys_show,
};

static struct file_operations proc_keys_fops = {
static const struct file_operations proc_keys_fops = {
.open = proc_keys_open,
.read = seq_read,
.llseek = seq_lseek,
Expand All @@ -54,7 +54,7 @@ static struct seq_operations proc_key_users_ops = {
.show = proc_key_users_show,
};

static struct file_operations proc_key_users_fops = {
static const struct file_operations proc_key_users_fops = {
.open = proc_key_users_open,
.read = seq_read,
.llseek = seq_lseek,
Expand Down
26 changes: 13 additions & 13 deletions security/selinux/selinuxfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static ssize_t sel_write_enforce(struct file * file, const char __user * buf,
#define sel_write_enforce NULL
#endif

static struct file_operations sel_enforce_ops = {
static const struct file_operations sel_enforce_ops = {
.read = sel_read_enforce,
.write = sel_write_enforce,
};
Expand Down Expand Up @@ -211,7 +211,7 @@ static ssize_t sel_write_disable(struct file * file, const char __user * buf,
#define sel_write_disable NULL
#endif

static struct file_operations sel_disable_ops = {
static const struct file_operations sel_disable_ops = {
.write = sel_write_disable,
};

Expand All @@ -225,7 +225,7 @@ static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
}

static struct file_operations sel_policyvers_ops = {
static const struct file_operations sel_policyvers_ops = {
.read = sel_read_policyvers,
};

Expand All @@ -242,7 +242,7 @@ static ssize_t sel_read_mls(struct file *filp, char __user *buf,
return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
}

static struct file_operations sel_mls_ops = {
static const struct file_operations sel_mls_ops = {
.read = sel_read_mls,
};

Expand Down Expand Up @@ -294,7 +294,7 @@ static ssize_t sel_write_load(struct file * file, const char __user * buf,
return length;
}

static struct file_operations sel_load_ops = {
static const struct file_operations sel_load_ops = {
.write = sel_write_load,
};

Expand Down Expand Up @@ -374,7 +374,7 @@ static ssize_t sel_write_checkreqprot(struct file * file, const char __user * bu
free_page((unsigned long) page);
return length;
}
static struct file_operations sel_checkreqprot_ops = {
static const struct file_operations sel_checkreqprot_ops = {
.read = sel_read_checkreqprot,
.write = sel_write_checkreqprot,
};
Expand Down Expand Up @@ -423,7 +423,7 @@ static ssize_t sel_write_compat_net(struct file * file, const char __user * buf,
free_page((unsigned long) page);
return length;
}
static struct file_operations sel_compat_net_ops = {
static const struct file_operations sel_compat_net_ops = {
.read = sel_read_compat_net,
.write = sel_write_compat_net,
};
Expand Down Expand Up @@ -467,7 +467,7 @@ static ssize_t selinux_transaction_write(struct file *file, const char __user *b
return rv;
}

static struct file_operations transaction_ops = {
static const struct file_operations transaction_ops = {
.write = selinux_transaction_write,
.read = simple_transaction_read,
.release = simple_transaction_release,
Expand Down Expand Up @@ -875,7 +875,7 @@ static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
return length;
}

static struct file_operations sel_bool_ops = {
static const struct file_operations sel_bool_ops = {
.read = sel_read_bool,
.write = sel_write_bool,
};
Expand Down Expand Up @@ -932,7 +932,7 @@ static ssize_t sel_commit_bools_write(struct file *filep,
return length;
}

static struct file_operations sel_commit_bools_ops = {
static const struct file_operations sel_commit_bools_ops = {
.write = sel_commit_bools_write,
};

Expand Down Expand Up @@ -1131,12 +1131,12 @@ static ssize_t sel_read_avc_hash_stats(struct file *filp, char __user *buf,
return ret;
}

static struct file_operations sel_avc_cache_threshold_ops = {
static const struct file_operations sel_avc_cache_threshold_ops = {
.read = sel_read_avc_cache_threshold,
.write = sel_write_avc_cache_threshold,
};

static struct file_operations sel_avc_hash_stats_ops = {
static const struct file_operations sel_avc_hash_stats_ops = {
.read = sel_read_avc_hash_stats,
};

Expand Down Expand Up @@ -1198,7 +1198,7 @@ static int sel_open_avc_cache_stats(struct inode *inode, struct file *file)
return seq_open(file, &sel_avc_cache_stats_seq_ops);
}

static struct file_operations sel_avc_cache_stats_ops = {
static const struct file_operations sel_avc_cache_stats_ops = {
.open = sel_open_avc_cache_stats,
.read = seq_read,
.llseek = seq_lseek,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ static int snd_ctl_fasync(int fd, struct file * file, int on)
* INIT PART
*/

static struct file_operations snd_ctl_f_ops =
static const struct file_operations snd_ctl_f_ops =
{
.owner = THIS_MODULE,
.read = snd_ctl_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/hwdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,
*/

static struct file_operations snd_hwdep_f_ops =
static const struct file_operations snd_hwdep_f_ops =
{
.owner = THIS_MODULE,
.llseek = snd_hwdep_llseek,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma)
return -ENXIO;
}

static struct file_operations snd_info_entry_operations =
static const struct file_operations snd_info_entry_operations =
{
.owner = THIS_MODULE,
.llseek = snd_info_entry_llseek,
Expand Down
4 changes: 2 additions & 2 deletions sound/core/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static DEFINE_SPINLOCK(shutdown_lock);
static LIST_HEAD(shutdown_files);

static struct file_operations snd_shutdown_f_ops;
static const struct file_operations snd_shutdown_f_ops;

static unsigned int snd_cards_lock; /* locked for registering/using */
struct snd_card *snd_cards[SNDRV_CARDS];
Expand Down Expand Up @@ -244,7 +244,7 @@ static int snd_disconnect_fasync(int fd, struct file *file, int on)
return -ENODEV;
}

static struct file_operations snd_shutdown_f_ops =
static const struct file_operations snd_shutdown_f_ops =
{
.owner = THIS_MODULE,
.llseek = snd_disconnect_llseek,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/oss/mixer_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned l
* REGISTRATION PART
*/

static struct file_operations snd_mixer_oss_f_ops =
static const struct file_operations snd_mixer_oss_f_ops =
{
.owner = THIS_MODULE,
.open = snd_mixer_oss_open,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/oss/pcm_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ static void snd_pcm_oss_proc_done(struct snd_pcm *pcm)
* ENTRY functions
*/

static struct file_operations snd_pcm_oss_f_reg =
static const struct file_operations snd_pcm_oss_f_reg =
{
.owner = THIS_MODULE,
.read = snd_pcm_oss_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/pcm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -3424,7 +3424,7 @@ static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
* Register section
*/

struct file_operations snd_pcm_f_ops[2] = {
const struct file_operations snd_pcm_f_ops[2] = {
{
.owner = THIS_MODULE,
.write = snd_pcm_write,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
* Register functions
*/

static struct file_operations snd_rawmidi_f_ops =
static const struct file_operations snd_rawmidi_f_ops =
{
.owner = THIS_MODULE,
.read = snd_rawmidi_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/seq/oss/seq_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ odev_poll(struct file *file, poll_table * wait)
* registration of sequencer minor device
*/

static struct file_operations seq_oss_f_ops =
static const struct file_operations seq_oss_f_ops =
{
.owner = THIS_MODULE,
.read = odev_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/seq/seq_clientmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ void snd_seq_info_clients_read(struct snd_info_entry *entry,
* REGISTRATION PART
*/

static struct file_operations snd_seq_f_ops =
static const struct file_operations snd_seq_f_ops =
{
.owner = THIS_MODULE,
.read = snd_seq_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/core/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int snd_open(struct inode *inode, struct file *file)
return err;
}

static struct file_operations snd_fops =
static const struct file_operations snd_fops =
{
.owner = THIS_MODULE,
.open = snd_open
Expand Down
2 changes: 1 addition & 1 deletion sound/core/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ static unsigned int snd_timer_user_poll(struct file *file, poll_table * wait)
#define snd_timer_user_ioctl_compat NULL
#endif

static struct file_operations snd_timer_f_ops =
static const struct file_operations snd_timer_f_ops =
{
.owner = THIS_MODULE,
.read = snd_timer_user_read,
Expand Down
4 changes: 2 additions & 2 deletions sound/oss/ad1889.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ static int ad1889_release(struct inode *inode, struct file *file)
return 0;
}

static struct file_operations ad1889_fops = {
static const struct file_operations ad1889_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = ad1889_read,
Expand Down Expand Up @@ -812,7 +812,7 @@ static int ad1889_mixer_ioctl(struct inode *inode, struct file *file,
return codec->mixer_ioctl(codec, cmd, arg);
}

static struct file_operations ad1889_mixer_fops = {
static const struct file_operations ad1889_mixer_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.ioctl = ad1889_mixer_ioctl,
Expand Down
6 changes: 3 additions & 3 deletions sound/oss/btaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ static int btaudio_mixer_ioctl(struct inode *inode, struct file *file,
return 0;
}

static struct file_operations btaudio_mixer_fops = {
static const struct file_operations btaudio_mixer_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.open = btaudio_mixer_open,
Expand Down Expand Up @@ -796,7 +796,7 @@ static unsigned int btaudio_dsp_poll(struct file *file, struct poll_table_struct
return mask;
}

static struct file_operations btaudio_digital_dsp_fops = {
static const struct file_operations btaudio_digital_dsp_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.open = btaudio_dsp_open_digital,
Expand All @@ -807,7 +807,7 @@ static struct file_operations btaudio_digital_dsp_fops = {
.poll = btaudio_dsp_poll,
};

static struct file_operations btaudio_analog_dsp_fops = {
static const struct file_operations btaudio_analog_dsp_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.open = btaudio_dsp_open_analog,
Expand Down
6 changes: 3 additions & 3 deletions sound/oss/dmasound/dmasound_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
return -EINVAL;
}

static struct file_operations mixer_fops =
static const struct file_operations mixer_fops =
{
.owner = THIS_MODULE,
.llseek = no_llseek,
Expand Down Expand Up @@ -1337,7 +1337,7 @@ static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
return -EINVAL;
}

static struct file_operations sq_fops =
static const struct file_operations sq_fops =
{
.owner = THIS_MODULE,
.llseek = no_llseek,
Expand Down Expand Up @@ -1561,7 +1561,7 @@ static ssize_t state_read(struct file *file, char __user *buf, size_t count,
return n;
}

static struct file_operations state_fops = {
static const struct file_operations state_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = state_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/oss/emu10k1/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ static void emu10k1_waveout_bh(unsigned long refdata)
return;
}

struct file_operations emu10k1_audio_fops = {
const struct file_operations emu10k1_audio_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = emu10k1_audio_read,
Expand Down
2 changes: 1 addition & 1 deletion sound/oss/emu10k1/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ int emu10k1_midi_callback(unsigned long msg, unsigned long refdata, unsigned lon
}

/* MIDI file operations */
struct file_operations emu10k1_midi_fops = {
const struct file_operations emu10k1_midi_fops = {
.owner = THIS_MODULE,
.read = emu10k1_midi_read,
.write = emu10k1_midi_write,
Expand Down
2 changes: 1 addition & 1 deletion sound/oss/emu10k1/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ static int emu10k1_mixer_release(struct inode *inode, struct file *file)
return 0;
}

struct file_operations emu10k1_mixer_fops = {
const struct file_operations emu10k1_mixer_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.ioctl = emu10k1_mixer_ioctl,
Expand Down
Loading

0 comments on commit 9c2e08c

Please sign in to comment.