Skip to contentSkip to conversation

const struct file_operations *

PATCH In review David Woodhouse 2 participants 3 messages Jun 24, 2003

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 const struct file_operations *

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 =====

drivers/char/misc.c +1 -1
@@ -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 =====

drivers/input/input.c +1 -1
@@ -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 =====

fs/select.c +1 -1
@@ -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 =====

fs/proc/generic.c +1 -1
@@ -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 =====

include/linux/fs.h +3 -3
@@ -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;
Signature · 1 line
dwmw2
#1 lore raw
Quoted 3 lines · David Woodhouse

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.

And indeed may not be advantageous. ROM accesses are typically slower than RAM accesses (or were, back when I cared about these kinds of things). Doing this kind of thing is good though -- the more ways we can get compilers to bitch about badly written code, the better.

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#2 lore raw
Quoted 8 lines · Matthew Wilcox
Quoted 3 lines · David Woodhouse

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.

And indeed may not be advantageous. ROM accesses are typically slower than RAM accesses (or were, back when I cared about these kinds of things).

Don't get me started on how pointless XIP is... :)

Signature · 1 line
dwmw2