From: David Woodhouse Subject: [PATCH] const struct file_operations * Date: Tue, 24 Jun 2003 15:05:58 +0100 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <1056463558.29264.499.camel@passion.cambridge.redhat.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: linux-fsdevel@vger.kernel.org Return-path: Received: from pub237.cambridge.redhat.com ([213.86.99.237]:2279 "EHLO passion.cambridge.redhat.com") by vger.kernel.org with ESMTP id S262093AbTFXNvv (ORCPT ); Tue, 24 Jun 2003 09:51:51 -0400 To: torvalds@osdl.org List-Id: linux-fsdevel.vger.kernel.org I found driver authors overriding individual file_operations members at runtime. Let's make it hurt at least a little... For configurations with kernel .rodata in ROM instead of RAM, it's actually slightly advantageous to have these structures marked as const too -- but that can be done later and isn't mandatory. ===== drivers/char/misc.c 1.20 vs edited ===== --- 1.20/drivers/char/misc.c Sat May 17 20:39:13 2003 +++ edited/drivers/char/misc.c Tue Jun 24 14:56:39 2003 @@ -103,7 +103,7 @@ int minor = minor(inode->i_rdev); struct miscdevice *c; int err = -ENODEV; - struct file_operations *old_fops, *new_fops = NULL; + const struct file_operations *old_fops, *new_fops = NULL; down(&misc_sem); ===== drivers/input/input.c 1.32 vs edited ===== --- 1.32/drivers/input/input.c Mon Jun 9 12:44:00 2003 +++ edited/drivers/input/input.c Tue Jun 24 14:57:24 2003 @@ -528,7 +528,7 @@ static int input_open_file(struct inode *inode, struct file *file) { struct input_handler *handler = input_table[minor(inode->i_rdev) >> 5]; - struct file_operations *old_fops, *new_fops = NULL; + const struct file_operations *old_fops, *new_fops = NULL; int err; /* No load-on-demand here? */ ===== fs/select.c 1.20 vs edited ===== --- 1.20/fs/select.c Thu May 8 05:21:13 2003 +++ edited/fs/select.c Tue Jun 24 14:53:35 2003 @@ -203,7 +203,7 @@ for (i = 0; i < n; ++rinp, ++routp, ++rexp) { unsigned long in, out, ex, all_bits, bit = 1, mask, j; unsigned long res_in = 0, res_out = 0, res_ex = 0; - struct file_operations *f_op = NULL; + const struct file_operations *f_op = NULL; struct file *file = NULL; in = *inp++; out = *outp++; ex = *exp++; ===== fs/proc/generic.c 1.21 vs edited ===== --- 1.21/fs/proc/generic.c Fri Apr 25 16:46:19 2003 +++ edited/fs/proc/generic.c Tue Jun 24 14:55:30 2003 @@ -498,7 +498,7 @@ struct file * filp = list_entry(p, struct file, f_list); struct dentry * dentry = filp->f_dentry; struct inode * inode; - struct file_operations *fops; + const struct file_operations *fops; if (dentry->d_op != &proc_dentry_operations) continue; ===== include/linux/fs.h 1.251 vs edited ===== --- 1.251/include/linux/fs.h Fri Jun 20 21:16:06 2003 +++ edited/include/linux/fs.h Tue Jun 24 14:51:39 2003 @@ -371,8 +371,8 @@ unsigned short i_bytes; spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ struct semaphore i_sem; - struct inode_operations *i_op; - struct file_operations *i_fop; /* former ->i_op->default_file_ops */ + const struct inode_operations *i_op; + const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ struct super_block *i_sb; struct file_lock *i_flock; struct address_space *i_mapping; @@ -426,7 +426,7 @@ struct list_head f_list; struct dentry *f_dentry; struct vfsmount *f_vfsmnt; - struct file_operations *f_op; + const struct file_operations *f_op; atomic_t f_count; unsigned int f_flags; mode_t f_mode; -- dwmw2