Skip to contentSkip to conversation

fs: check f_op before dereference its field

PATCH In review Jiang Fang 2 participants 2 messages Jan 24, 2013 VFS

lore
Share & tools
lore

Jiang Fang

author
#0 lore raw

PATCH 1/1 fs: check f_op before dereference its field

I don't know whether we can have NULL f_op today, but a quick grep of '!file->f_op->' in fs directory shows most of times we do the check. So fix the missing one.

---
 fs/open.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/open.c +1 -1
index 9b33c0c..192dd86 100644
@@ -275,7 +275,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
 		return -EFBIG;
 
-	if (!file->f_op->fallocate)
+	if (!file->f_op || !file->f_op->fallocate)
 		return -EOPNOTSUPP;
 
 	sb_start_write(inode->i_sb);
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 3 lines · Jiang Fang

I don't know whether we can have NULL f_op today, but a quick grep of '!file->f_op->' in fs directory shows most of times we do the check. So fix the missing one.

We should remove the bogus ones, actually, and hunt down the remaining few places that set ->f_op to NULL (AFAICS, all of them in dvb and in ->release() instances, at that; note that no methods can be ever called after ->release(), so these assignments are pointless _and_ irrelevant for any call sites of the methods).