aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/nand/nandsim.c2
-rw-r--r--drivers/staging/comedi/comedi_compat32.c3
-rw-r--r--fs/autofs4/autofs_i.h2
-rw-r--r--fs/autofs4/dev-ioctl.c6
-rw-r--r--fs/binfmt_aout.c4
-rw-r--r--fs/binfmt_elf.c6
-rw-r--r--fs/binfmt_elf_fdpic.c2
-rw-r--r--fs/binfmt_em86.c2
-rw-r--r--fs/coda/dir.c3
-rw-r--r--fs/coda/file.c6
-rw-r--r--fs/compat_ioctl.c4
-rw-r--r--fs/coredump.c2
-rw-r--r--fs/ecryptfs/file.c8
-rw-r--r--fs/eventpoll.c2
-rw-r--r--fs/exec.c35
-rw-r--r--fs/fcntl.c5
-rw-r--r--fs/file_table.c4
-rw-r--r--fs/ioctl.c4
-rw-r--r--fs/locks.c12
-rw-r--r--fs/open.c8
-rw-r--r--fs/read_write.c25
-rw-r--r--fs/readdir.c2
-rw-r--r--fs/select.c4
-rw-r--r--fs/splice.c6
-rw-r--r--fs/sync.c2
-rw-r--r--mm/memory.c2
-rw-r--r--mm/mmap.c4
-rw-r--r--mm/nommu.c2
-rw-r--r--net/9p/trans_fd.c4
29 files changed, 74 insertions, 97 deletions
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index bdc1d15369f8..d1c7de92cfdf 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -575,7 +575,7 @@ static int alloc_device(struct nandsim *ns)
575 cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600); 575 cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600);
576 if (IS_ERR(cfile)) 576 if (IS_ERR(cfile))
577 return PTR_ERR(cfile); 577 return PTR_ERR(cfile);
578 if (!cfile->f_op || (!cfile->f_op->read && !cfile->f_op->aio_read)) { 578 if (!cfile->f_op->read && !cfile->f_op->aio_read) {
579 NS_ERR("alloc_device: cache file not readable\n"); 579 NS_ERR("alloc_device: cache file not readable\n");
580 err = -EINVAL; 580 err = -EINVAL;
581 goto err_close; 581 goto err_close;
diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c
index 2dfb06aedb15..1e9da405d833 100644
--- a/drivers/staging/comedi/comedi_compat32.c
+++ b/drivers/staging/comedi/comedi_compat32.c
@@ -86,9 +86,6 @@ struct comedi32_insnlist_struct {
86static int translated_ioctl(struct file *file, unsigned int cmd, 86static int translated_ioctl(struct file *file, unsigned int cmd,
87 unsigned long arg) 87 unsigned long arg)
88{ 88{
89 if (!file->f_op)
90 return -ENOTTY;
91
92 if (file->f_op->unlocked_ioctl) 89 if (file->f_op->unlocked_ioctl)
93 return file->f_op->unlocked_ioctl(file, cmd, arg); 90 return file->f_op->unlocked_ioctl(file, cmd, arg);
94 91
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index 3f1128b37e46..ebab147e9700 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -271,7 +271,7 @@ void autofs4_clean_ino(struct autofs_info *);
271 271
272static inline int autofs_prepare_pipe(struct file *pipe) 272static inline int autofs_prepare_pipe(struct file *pipe)
273{ 273{
274 if (!pipe->f_op || !pipe->f_op->write) 274 if (!pipe->f_op->write)
275 return -EINVAL; 275 return -EINVAL;
276 if (!S_ISFIFO(file_inode(pipe)->i_mode)) 276 if (!S_ISFIFO(file_inode(pipe)->i_mode))
277 return -EINVAL; 277 return -EINVAL;
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index 0f00da329e71..1818ce7f5a06 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -658,12 +658,6 @@ static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __use
658 goto out; 658 goto out;
659 } 659 }
660 660
661 if (!fp->f_op) {
662 err = -ENOTTY;
663 fput(fp);
664 goto out;
665 }
666
667 sbi = autofs_dev_ioctl_sbi(fp); 661 sbi = autofs_dev_ioctl_sbi(fp);
668 if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { 662 if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
669 err = -EINVAL; 663 err = -EINVAL;
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 89dec7f789a4..faaa819f70fa 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -221,7 +221,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
221 * Requires a mmap handler. This prevents people from using a.out 221 * Requires a mmap handler. This prevents people from using a.out
222 * as part of an exploit attack against /proc-related vulnerabilities. 222 * as part of an exploit attack against /proc-related vulnerabilities.
223 */ 223 */
224 if (!bprm->file->f_op || !bprm->file->f_op->mmap) 224 if (!bprm->file->f_op->mmap)
225 return -ENOEXEC; 225 return -ENOEXEC;
226 226
227 fd_offset = N_TXTOFF(ex); 227 fd_offset = N_TXTOFF(ex);
@@ -374,7 +374,7 @@ static int load_aout_library(struct file *file)
374 * Requires a mmap handler. This prevents people from using a.out 374 * Requires a mmap handler. This prevents people from using a.out
375 * as part of an exploit attack against /proc-related vulnerabilities. 375 * as part of an exploit attack against /proc-related vulnerabilities.
376 */ 376 */
377 if (!file->f_op || !file->f_op->mmap) 377 if (!file->f_op->mmap)
378 goto out; 378 goto out;
379 379
380 if (N_FLAGS(ex)) 380 if (N_FLAGS(ex))
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 4c94a79991bb..501c8a4d6eb1 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -406,7 +406,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
406 goto out; 406 goto out;
407 if (!elf_check_arch(interp_elf_ex)) 407 if (!elf_check_arch(interp_elf_ex))
408 goto out; 408 goto out;
409 if (!interpreter->f_op || !interpreter->f_op->mmap) 409 if (!interpreter->f_op->mmap)
410 goto out; 410 goto out;
411 411
412 /* 412 /*
@@ -607,7 +607,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
607 goto out; 607 goto out;
608 if (!elf_check_arch(&loc->elf_ex)) 608 if (!elf_check_arch(&loc->elf_ex))
609 goto out; 609 goto out;
610 if (!bprm->file->f_op || !bprm->file->f_op->mmap) 610 if (!bprm->file->f_op->mmap)
611 goto out; 611 goto out;
612 612
613 /* Now read in all of the header information */ 613 /* Now read in all of the header information */
@@ -1028,7 +1028,7 @@ static int load_elf_library(struct file *file)
1028 1028
1029 /* First of all, some simple consistency checks */ 1029 /* First of all, some simple consistency checks */
1030 if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 || 1030 if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
1031 !elf_check_arch(&elf_ex) || !file->f_op || !file->f_op->mmap) 1031 !elf_check_arch(&elf_ex) || !file->f_op->mmap)
1032 goto out; 1032 goto out;
1033 1033
1034 /* Now read in all of the header information */ 1034 /* Now read in all of the header information */
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index c166f325a183..ea4c6273b4a5 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -111,7 +111,7 @@ static int is_elf_fdpic(struct elfhdr *hdr, struct file *file)
111 return 0; 111 return 0;
112 if (!elf_check_arch(hdr) || !elf_check_fdpic(hdr)) 112 if (!elf_check_arch(hdr) || !elf_check_fdpic(hdr))
113 return 0; 113 return 0;
114 if (!file->f_op || !file->f_op->mmap) 114 if (!file->f_op->mmap)
115 return 0; 115 return 0;
116 return 1; 116 return 1;
117} 117}
diff --git a/fs/binfmt_em86.c b/fs/binfmt_em86.c
index 037a3e2b045b..f37b08cea1f7 100644
--- a/fs/binfmt_em86.c
+++ b/fs/binfmt_em86.c
@@ -38,7 +38,7 @@ static int load_em86(struct linux_binprm *bprm)
38 /* First of all, some simple consistency checks */ 38 /* First of all, some simple consistency checks */
39 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) || 39 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
40 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) || 40 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
41 (!bprm->file->f_op || !bprm->file->f_op->mmap)) { 41 !bprm->file->f_op->mmap) {
42 return -ENOEXEC; 42 return -ENOEXEC;
43 } 43 }
44 44
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 190effc6a6fa..8c8d469c9283 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -387,9 +387,6 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx)
387 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 387 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
388 host_file = cfi->cfi_container; 388 host_file = cfi->cfi_container;
389 389
390 if (!host_file->f_op)
391 return -ENOTDIR;
392
393 if (host_file->f_op->iterate) { 390 if (host_file->f_op->iterate) {
394 struct inode *host_inode = file_inode(host_file); 391 struct inode *host_inode = file_inode(host_file);
395 mutex_lock(&host_inode->i_mutex); 392 mutex_lock(&host_inode->i_mutex);
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 380b798f8443..9e83b7790212 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -36,7 +36,7 @@ coda_file_read(struct file *coda_file, char __user *buf, size_t count, loff_t *p
36 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 36 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
37 host_file = cfi->cfi_container; 37 host_file = cfi->cfi_container;
38 38
39 if (!host_file->f_op || !host_file->f_op->read) 39 if (!host_file->f_op->read)
40 return -EINVAL; 40 return -EINVAL;
41 41
42 return host_file->f_op->read(host_file, buf, count, ppos); 42 return host_file->f_op->read(host_file, buf, count, ppos);
@@ -75,7 +75,7 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo
75 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 75 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
76 host_file = cfi->cfi_container; 76 host_file = cfi->cfi_container;
77 77
78 if (!host_file->f_op || !host_file->f_op->write) 78 if (!host_file->f_op->write)
79 return -EINVAL; 79 return -EINVAL;
80 80
81 host_inode = file_inode(host_file); 81 host_inode = file_inode(host_file);
@@ -105,7 +105,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
105 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 105 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
106 host_file = cfi->cfi_container; 106 host_file = cfi->cfi_container;
107 107
108 if (!host_file->f_op || !host_file->f_op->mmap) 108 if (!host_file->f_op->mmap)
109 return -ENODEV; 109 return -ENODEV;
110 110
111 coda_inode = file_inode(coda_file); 111 coda_inode = file_inode(coda_file);
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 5d19acfa7c6c..dc52e13d58e0 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1583,13 +1583,13 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
1583 /*FALL THROUGH*/ 1583 /*FALL THROUGH*/
1584 1584
1585 default: 1585 default:
1586 if (f.file->f_op && f.file->f_op->compat_ioctl) { 1586 if (f.file->f_op->compat_ioctl) {
1587 error = f.file->f_op->compat_ioctl(f.file, cmd, arg); 1587 error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
1588 if (error != -ENOIOCTLCMD) 1588 if (error != -ENOIOCTLCMD)
1589 goto out_fput; 1589 goto out_fput;
1590 } 1590 }
1591 1591
1592 if (!f.file->f_op || !f.file->f_op->unlocked_ioctl) 1592 if (!f.file->f_op->unlocked_ioctl)
1593 goto do_ioctl; 1593 goto do_ioctl;
1594 break; 1594 break;
1595 } 1595 }
diff --git a/fs/coredump.c b/fs/coredump.c
index 9bdeca12ae0e..42c3b8423669 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -645,7 +645,7 @@ void do_coredump(siginfo_t *siginfo)
645 */ 645 */
646 if (!uid_eq(inode->i_uid, current_fsuid())) 646 if (!uid_eq(inode->i_uid, current_fsuid()))
647 goto close_fail; 647 goto close_fail;
648 if (!cprm.file->f_op || !cprm.file->f_op->write) 648 if (!cprm.file->f_op->write)
649 goto close_fail; 649 goto close_fail;
650 if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file)) 650 if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file))
651 goto close_fail; 651 goto close_fail;
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 992cf95830b5..6b1cd2b0c751 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -271,7 +271,7 @@ static int ecryptfs_flush(struct file *file, fl_owner_t td)
271{ 271{
272 struct file *lower_file = ecryptfs_file_to_lower(file); 272 struct file *lower_file = ecryptfs_file_to_lower(file);
273 273
274 if (lower_file->f_op && lower_file->f_op->flush) { 274 if (lower_file->f_op->flush) {
275 filemap_write_and_wait(file->f_mapping); 275 filemap_write_and_wait(file->f_mapping);
276 return lower_file->f_op->flush(lower_file, td); 276 return lower_file->f_op->flush(lower_file, td);
277 } 277 }
@@ -305,7 +305,7 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
305 struct file *lower_file = NULL; 305 struct file *lower_file = NULL;
306 306
307 lower_file = ecryptfs_file_to_lower(file); 307 lower_file = ecryptfs_file_to_lower(file);
308 if (lower_file->f_op && lower_file->f_op->fasync) 308 if (lower_file->f_op->fasync)
309 rc = lower_file->f_op->fasync(fd, lower_file, flag); 309 rc = lower_file->f_op->fasync(fd, lower_file, flag);
310 return rc; 310 return rc;
311} 311}
@@ -318,7 +318,7 @@ ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
318 318
319 if (ecryptfs_file_to_private(file)) 319 if (ecryptfs_file_to_private(file))
320 lower_file = ecryptfs_file_to_lower(file); 320 lower_file = ecryptfs_file_to_lower(file);
321 if (lower_file && lower_file->f_op && lower_file->f_op->unlocked_ioctl) 321 if (lower_file->f_op && lower_file->f_op->unlocked_ioctl)
322 rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg); 322 rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
323 return rc; 323 return rc;
324} 324}
@@ -332,7 +332,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
332 332
333 if (ecryptfs_file_to_private(file)) 333 if (ecryptfs_file_to_private(file))
334 lower_file = ecryptfs_file_to_lower(file); 334 lower_file = ecryptfs_file_to_lower(file);
335 if (lower_file && lower_file->f_op && lower_file->f_op->compat_ioctl) 335 if (lower_file->f_op && lower_file->f_op->compat_ioctl)
336 rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg); 336 rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
337 return rc; 337 return rc;
338} 338}
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 473e09da7d02..31fd77cd81eb 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1816,7 +1816,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1816 1816
1817 /* The target file descriptor must support poll */ 1817 /* The target file descriptor must support poll */
1818 error = -EPERM; 1818 error = -EPERM;
1819 if (!tf.file->f_op || !tf.file->f_op->poll) 1819 if (!tf.file->f_op->poll)
1820 goto error_tgt_fput; 1820 goto error_tgt_fput;
1821 1821
1822 /* Check if EPOLLWAKEUP is allowed */ 1822 /* Check if EPOLLWAKEUP is allowed */
diff --git a/fs/exec.c b/fs/exec.c
index 8875dd10ae7a..351440fbf1ee 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -106,6 +106,7 @@ static inline void put_binfmt(struct linux_binfmt * fmt)
106 */ 106 */
107SYSCALL_DEFINE1(uselib, const char __user *, library) 107SYSCALL_DEFINE1(uselib, const char __user *, library)
108{ 108{
109 struct linux_binfmt *fmt;
109 struct file *file; 110 struct file *file;
110 struct filename *tmp = getname(library); 111 struct filename *tmp = getname(library);
111 int error = PTR_ERR(tmp); 112 int error = PTR_ERR(tmp);
@@ -136,24 +137,21 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
136 fsnotify_open(file); 137 fsnotify_open(file);
137 138
138 error = -ENOEXEC; 139 error = -ENOEXEC;
139 if(file->f_op) {
140 struct linux_binfmt * fmt;
141 140
142 read_lock(&binfmt_lock); 141 read_lock(&binfmt_lock);
143 list_for_each_entry(fmt, &formats, lh) { 142 list_for_each_entry(fmt, &formats, lh) {
144 if (!fmt->load_shlib) 143 if (!fmt->load_shlib)
145 continue; 144 continue;
146 if (!try_module_get(fmt->module)) 145 if (!try_module_get(fmt->module))
147 continue; 146 continue;
148 read_unlock(&binfmt_lock);
149 error = fmt->load_shlib(file);
150 read_lock(&binfmt_lock);
151 put_binfmt(fmt);
152 if (error != -ENOEXEC)
153 break;
154 }
155 read_unlock(&binfmt_lock); 147 read_unlock(&binfmt_lock);
148 error = fmt->load_shlib(file);
149 read_lock(&binfmt_lock);
150 put_binfmt(fmt);
151 if (error != -ENOEXEC)
152 break;
156 } 153 }
154 read_unlock(&binfmt_lock);
157exit: 155exit:
158 fput(file); 156 fput(file);
159out: 157out:
@@ -1277,13 +1275,10 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
1277 */ 1275 */
1278int prepare_binprm(struct linux_binprm *bprm) 1276int prepare_binprm(struct linux_binprm *bprm)
1279{ 1277{
1280 umode_t mode; 1278 struct inode *inode = file_inode(bprm->file);
1281 struct inode * inode = file_inode(bprm->file); 1279 umode_t mode = inode->i_mode;
1282 int retval; 1280 int retval;
1283 1281
1284 mode = inode->i_mode;
1285 if (bprm->file->f_op == NULL)
1286 return -EACCES;
1287 1282
1288 /* clear any previous set[ug]id data from a previous binary */ 1283 /* clear any previous set[ug]id data from a previous binary */
1289 bprm->cred->euid = current_euid(); 1284 bprm->cred->euid = current_euid();
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 65343c3741ff..ef6866592a0f 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -56,7 +56,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
56 return -EINVAL; 56 return -EINVAL;
57 } 57 }
58 58
59 if (filp->f_op && filp->f_op->check_flags) 59 if (filp->f_op->check_flags)
60 error = filp->f_op->check_flags(arg); 60 error = filp->f_op->check_flags(arg);
61 if (error) 61 if (error)
62 return error; 62 return error;
@@ -64,8 +64,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
64 /* 64 /*
65 * ->fasync() is responsible for setting the FASYNC bit. 65 * ->fasync() is responsible for setting the FASYNC bit.
66 */ 66 */
67 if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op && 67 if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op->fasync) {
68 filp->f_op->fasync) {
69 error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); 68 error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
70 if (error < 0) 69 if (error < 0)
71 goto out; 70 goto out;
diff --git a/fs/file_table.c b/fs/file_table.c
index abdd15ad13c9..e61e5529fa9d 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -240,11 +240,11 @@ static void __fput(struct file *file)
240 locks_remove_flock(file); 240 locks_remove_flock(file);
241 241
242 if (unlikely(file->f_flags & FASYNC)) { 242 if (unlikely(file->f_flags & FASYNC)) {
243 if (file->f_op && file->f_op->fasync) 243 if (file->f_op->fasync)
244 file->f_op->fasync(-1, file, 0); 244 file->f_op->fasync(-1, file, 0);
245 } 245 }
246 ima_file_free(file); 246 ima_file_free(file);
247 if (file->f_op && file->f_op->release) 247 if (file->f_op->release)
248 file->f_op->release(inode, file); 248 file->f_op->release(inode, file);
249 security_file_free(file); 249 security_file_free(file);
250 if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL && 250 if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
diff --git a/fs/ioctl.c b/fs/ioctl.c
index fd507fb460f8..8ac3fad36192 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -37,7 +37,7 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd,
37{ 37{
38 int error = -ENOTTY; 38 int error = -ENOTTY;
39 39
40 if (!filp->f_op || !filp->f_op->unlocked_ioctl) 40 if (!filp->f_op->unlocked_ioctl)
41 goto out; 41 goto out;
42 42
43 error = filp->f_op->unlocked_ioctl(filp, cmd, arg); 43 error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
@@ -501,7 +501,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,
501 501
502 /* Did FASYNC state change ? */ 502 /* Did FASYNC state change ? */
503 if ((flag ^ filp->f_flags) & FASYNC) { 503 if ((flag ^ filp->f_flags) & FASYNC) {
504 if (filp->f_op && filp->f_op->fasync) 504 if (filp->f_op->fasync)
505 /* fasync() adjusts filp->f_flags */ 505 /* fasync() adjusts filp->f_flags */
506 error = filp->f_op->fasync(fd, filp, on); 506 error = filp->f_op->fasync(fd, filp, on);
507 else 507 else
diff --git a/fs/locks.c b/fs/locks.c
index b27a3005d78d..f155ffd648bb 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1579,7 +1579,7 @@ EXPORT_SYMBOL(generic_setlease);
1579 1579
1580static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease) 1580static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
1581{ 1581{
1582 if (filp->f_op && filp->f_op->setlease) 1582 if (filp->f_op->setlease)
1583 return filp->f_op->setlease(filp, arg, lease); 1583 return filp->f_op->setlease(filp, arg, lease);
1584 else 1584 else
1585 return generic_setlease(filp, arg, lease); 1585 return generic_setlease(filp, arg, lease);
@@ -1771,7 +1771,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
1771 if (error) 1771 if (error)
1772 goto out_free; 1772 goto out_free;
1773 1773
1774 if (f.file->f_op && f.file->f_op->flock) 1774 if (f.file->f_op->flock)
1775 error = f.file->f_op->flock(f.file, 1775 error = f.file->f_op->flock(f.file,
1776 (can_sleep) ? F_SETLKW : F_SETLK, 1776 (can_sleep) ? F_SETLKW : F_SETLK,
1777 lock); 1777 lock);
@@ -1797,7 +1797,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
1797 */ 1797 */
1798int vfs_test_lock(struct file *filp, struct file_lock *fl) 1798int vfs_test_lock(struct file *filp, struct file_lock *fl)
1799{ 1799{
1800 if (filp->f_op && filp->f_op->lock) 1800 if (filp->f_op->lock)
1801 return filp->f_op->lock(filp, F_GETLK, fl); 1801 return filp->f_op->lock(filp, F_GETLK, fl);
1802 posix_test_lock(filp, fl); 1802 posix_test_lock(filp, fl);
1803 return 0; 1803 return 0;
@@ -1909,7 +1909,7 @@ out:
1909 */ 1909 */
1910int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf) 1910int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf)
1911{ 1911{
1912 if (filp->f_op && filp->f_op->lock) 1912 if (filp->f_op->lock)
1913 return filp->f_op->lock(filp, cmd, fl); 1913 return filp->f_op->lock(filp, cmd, fl);
1914 else 1914 else
1915 return posix_lock_file(filp, fl, conf); 1915 return posix_lock_file(filp, fl, conf);
@@ -2182,7 +2182,7 @@ void locks_remove_flock(struct file *filp)
2182 if (!inode->i_flock) 2182 if (!inode->i_flock)
2183 return; 2183 return;
2184 2184
2185 if (filp->f_op && filp->f_op->flock) { 2185 if (filp->f_op->flock) {
2186 struct file_lock fl = { 2186 struct file_lock fl = {
2187 .fl_pid = current->tgid, 2187 .fl_pid = current->tgid,
2188 .fl_file = filp, 2188 .fl_file = filp,
@@ -2246,7 +2246,7 @@ EXPORT_SYMBOL(posix_unblock_lock);
2246 */ 2246 */
2247int vfs_cancel_lock(struct file *filp, struct file_lock *fl) 2247int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
2248{ 2248{
2249 if (filp->f_op && filp->f_op->lock) 2249 if (filp->f_op->lock)
2250 return filp->f_op->lock(filp, F_CANCELLK, fl); 2250 return filp->f_op->lock(filp, F_CANCELLK, fl);
2251 return 0; 2251 return 0;
2252} 2252}
diff --git a/fs/open.c b/fs/open.c
index d420331ca32a..a1465b1ec8c7 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -693,6 +693,10 @@ static int do_dentry_open(struct file *f,
693 } 693 }
694 694
695 f->f_op = fops_get(inode->i_fop); 695 f->f_op = fops_get(inode->i_fop);
696 if (unlikely(WARN_ON(!f->f_op))) {
697 error = -ENODEV;
698 goto cleanup_all;
699 }
696 700
697 error = security_file_open(f, cred); 701 error = security_file_open(f, cred);
698 if (error) 702 if (error)
@@ -702,7 +706,7 @@ static int do_dentry_open(struct file *f,
702 if (error) 706 if (error)
703 goto cleanup_all; 707 goto cleanup_all;
704 708
705 if (!open && f->f_op) 709 if (!open)
706 open = f->f_op->open; 710 open = f->f_op->open;
707 if (open) { 711 if (open) {
708 error = open(inode, f); 712 error = open(inode, f);
@@ -1023,7 +1027,7 @@ int filp_close(struct file *filp, fl_owner_t id)
1023 return 0; 1027 return 0;
1024 } 1028 }
1025 1029
1026 if (filp->f_op && filp->f_op->flush) 1030 if (filp->f_op->flush)
1027 retval = filp->f_op->flush(filp, id); 1031 retval = filp->f_op->flush(filp, id);
1028 1032
1029 if (likely(!(filp->f_mode & FMODE_PATH))) { 1033 if (likely(!(filp->f_mode & FMODE_PATH))) {
diff --git a/fs/read_write.c b/fs/read_write.c
index e3cd280b158c..58e440df1bc6 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -257,7 +257,7 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
257 257
258 fn = no_llseek; 258 fn = no_llseek;
259 if (file->f_mode & FMODE_LSEEK) { 259 if (file->f_mode & FMODE_LSEEK) {
260 if (file->f_op && file->f_op->llseek) 260 if (file->f_op->llseek)
261 fn = file->f_op->llseek; 261 fn = file->f_op->llseek;
262 } 262 }
263 return fn(file, offset, whence); 263 return fn(file, offset, whence);
@@ -384,7 +384,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
384 384
385 if (!(file->f_mode & FMODE_READ)) 385 if (!(file->f_mode & FMODE_READ))
386 return -EBADF; 386 return -EBADF;
387 if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) 387 if (!file->f_op->read && !file->f_op->aio_read)
388 return -EINVAL; 388 return -EINVAL;
389 if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) 389 if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
390 return -EFAULT; 390 return -EFAULT;
@@ -433,7 +433,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
433 const char __user *p; 433 const char __user *p;
434 ssize_t ret; 434 ssize_t ret;
435 435
436 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write)) 436 if (!file->f_op->write && !file->f_op->aio_write)
437 return -EINVAL; 437 return -EINVAL;
438 438
439 old_fs = get_fs(); 439 old_fs = get_fs();
@@ -460,7 +460,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
460 460
461 if (!(file->f_mode & FMODE_WRITE)) 461 if (!(file->f_mode & FMODE_WRITE))
462 return -EBADF; 462 return -EBADF;
463 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write)) 463 if (!file->f_op->write && !file->f_op->aio_write)
464 return -EINVAL; 464 return -EINVAL;
465 if (unlikely(!access_ok(VERIFY_READ, buf, count))) 465 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
466 return -EFAULT; 466 return -EFAULT;
@@ -727,11 +727,6 @@ static ssize_t do_readv_writev(int type, struct file *file,
727 io_fn_t fn; 727 io_fn_t fn;
728 iov_fn_t fnv; 728 iov_fn_t fnv;
729 729
730 if (!file->f_op) {
731 ret = -EINVAL;
732 goto out;
733 }
734
735 ret = rw_copy_check_uvector(type, uvector, nr_segs, 730 ret = rw_copy_check_uvector(type, uvector, nr_segs,
736 ARRAY_SIZE(iovstack), iovstack, &iov); 731 ARRAY_SIZE(iovstack), iovstack, &iov);
737 if (ret <= 0) 732 if (ret <= 0)
@@ -778,7 +773,7 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
778{ 773{
779 if (!(file->f_mode & FMODE_READ)) 774 if (!(file->f_mode & FMODE_READ))
780 return -EBADF; 775 return -EBADF;
781 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read)) 776 if (!file->f_op->aio_read && !file->f_op->read)
782 return -EINVAL; 777 return -EINVAL;
783 778
784 return do_readv_writev(READ, file, vec, vlen, pos); 779 return do_readv_writev(READ, file, vec, vlen, pos);
@@ -791,7 +786,7 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
791{ 786{
792 if (!(file->f_mode & FMODE_WRITE)) 787 if (!(file->f_mode & FMODE_WRITE))
793 return -EBADF; 788 return -EBADF;
794 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write)) 789 if (!file->f_op->aio_write && !file->f_op->write)
795 return -EINVAL; 790 return -EINVAL;
796 791
797 return do_readv_writev(WRITE, file, vec, vlen, pos); 792 return do_readv_writev(WRITE, file, vec, vlen, pos);
@@ -906,10 +901,6 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
906 io_fn_t fn; 901 io_fn_t fn;
907 iov_fn_t fnv; 902 iov_fn_t fnv;
908 903
909 ret = -EINVAL;
910 if (!file->f_op)
911 goto out;
912
913 ret = -EFAULT; 904 ret = -EFAULT;
914 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector))) 905 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
915 goto out; 906 goto out;
@@ -965,7 +956,7 @@ static size_t compat_readv(struct file *file,
965 goto out; 956 goto out;
966 957
967 ret = -EINVAL; 958 ret = -EINVAL;
968 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read)) 959 if (!file->f_op->aio_read && !file->f_op->read)
969 goto out; 960 goto out;
970 961
971 ret = compat_do_readv_writev(READ, file, vec, vlen, pos); 962 ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
@@ -1032,7 +1023,7 @@ static size_t compat_writev(struct file *file,
1032 goto out; 1023 goto out;
1033 1024
1034 ret = -EINVAL; 1025 ret = -EINVAL;
1035 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write)) 1026 if (!file->f_op->aio_write && !file->f_op->write)
1036 goto out; 1027 goto out;
1037 1028
1038 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos); 1029 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
diff --git a/fs/readdir.c b/fs/readdir.c
index 93d71e574310..5b53d995cae6 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -24,7 +24,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
24{ 24{
25 struct inode *inode = file_inode(file); 25 struct inode *inode = file_inode(file);
26 int res = -ENOTDIR; 26 int res = -ENOTDIR;
27 if (!file->f_op || !file->f_op->iterate) 27 if (!file->f_op->iterate)
28 goto out; 28 goto out;
29 29
30 res = security_file_permission(file, MAY_READ); 30 res = security_file_permission(file, MAY_READ);
diff --git a/fs/select.c b/fs/select.c
index 35d4adc749d9..55278a36a658 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -455,7 +455,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
455 const struct file_operations *f_op; 455 const struct file_operations *f_op;
456 f_op = f.file->f_op; 456 f_op = f.file->f_op;
457 mask = DEFAULT_POLLMASK; 457 mask = DEFAULT_POLLMASK;
458 if (f_op && f_op->poll) { 458 if (f_op->poll) {
459 wait_key_set(wait, in, out, 459 wait_key_set(wait, in, out,
460 bit, busy_flag); 460 bit, busy_flag);
461 mask = (*f_op->poll)(f.file, wait); 461 mask = (*f_op->poll)(f.file, wait);
@@ -762,7 +762,7 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait,
762 mask = POLLNVAL; 762 mask = POLLNVAL;
763 if (f.file) { 763 if (f.file) {
764 mask = DEFAULT_POLLMASK; 764 mask = DEFAULT_POLLMASK;
765 if (f.file->f_op && f.file->f_op->poll) { 765 if (f.file->f_op->poll) {
766 pwait->_key = pollfd->events|POLLERR|POLLHUP; 766 pwait->_key = pollfd->events|POLLERR|POLLHUP;
767 pwait->_key |= busy_flag; 767 pwait->_key |= busy_flag;
768 mask = f.file->f_op->poll(f.file, pwait); 768 mask = f.file->f_op->poll(f.file, pwait);
diff --git a/fs/splice.c b/fs/splice.c
index 3b7ee656f3aa..46a08f772d7d 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -695,7 +695,7 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe,
695 loff_t pos = sd->pos; 695 loff_t pos = sd->pos;
696 int more; 696 int more;
697 697
698 if (!likely(file->f_op && file->f_op->sendpage)) 698 if (!likely(file->f_op->sendpage))
699 return -EINVAL; 699 return -EINVAL;
700 700
701 more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0; 701 more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0;
@@ -1099,7 +1099,7 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
1099 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, 1099 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
1100 loff_t *, size_t, unsigned int); 1100 loff_t *, size_t, unsigned int);
1101 1101
1102 if (out->f_op && out->f_op->splice_write) 1102 if (out->f_op->splice_write)
1103 splice_write = out->f_op->splice_write; 1103 splice_write = out->f_op->splice_write;
1104 else 1104 else
1105 splice_write = default_file_splice_write; 1105 splice_write = default_file_splice_write;
@@ -1125,7 +1125,7 @@ static long do_splice_to(struct file *in, loff_t *ppos,
1125 if (unlikely(ret < 0)) 1125 if (unlikely(ret < 0))
1126 return ret; 1126 return ret;
1127 1127
1128 if (in->f_op && in->f_op->splice_read) 1128 if (in->f_op->splice_read)
1129 splice_read = in->f_op->splice_read; 1129 splice_read = in->f_op->splice_read;
1130 else 1130 else
1131 splice_read = default_file_splice_read; 1131 splice_read = default_file_splice_read;
diff --git a/fs/sync.c b/fs/sync.c
index 905f3f6b3d85..6c0ca3b75758 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -177,7 +177,7 @@ SYSCALL_DEFINE1(syncfs, int, fd)
177 */ 177 */
178int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync) 178int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync)
179{ 179{
180 if (!file->f_op || !file->f_op->fsync) 180 if (!file->f_op->fsync)
181 return -EINVAL; 181 return -EINVAL;
182 return file->f_op->fsync(file, start, end, datasync); 182 return file->f_op->fsync(file, start, end, datasync);
183} 183}
diff --git a/mm/memory.c b/mm/memory.c
index ca0003947115..e2bbba42604c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -681,7 +681,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
681 if (vma->vm_ops) 681 if (vma->vm_ops)
682 printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n", 682 printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
683 vma->vm_ops->fault); 683 vma->vm_ops->fault);
684 if (vma->vm_file && vma->vm_file->f_op) 684 if (vma->vm_file)
685 printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n", 685 printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
686 vma->vm_file->f_op->mmap); 686 vma->vm_file->f_op->mmap);
687 dump_stack(); 687 dump_stack();
diff --git a/mm/mmap.c b/mm/mmap.c
index 9d548512ff8a..ab199dfc9e26 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1299,7 +1299,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
1299 vm_flags &= ~VM_MAYEXEC; 1299 vm_flags &= ~VM_MAYEXEC;
1300 } 1300 }
1301 1301
1302 if (!file->f_op || !file->f_op->mmap) 1302 if (!file->f_op->mmap)
1303 return -ENODEV; 1303 return -ENODEV;
1304 if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP)) 1304 if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
1305 return -EINVAL; 1305 return -EINVAL;
@@ -1951,7 +1951,7 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
1951 return -ENOMEM; 1951 return -ENOMEM;
1952 1952
1953 get_area = current->mm->get_unmapped_area; 1953 get_area = current->mm->get_unmapped_area;
1954 if (file && file->f_op && file->f_op->get_unmapped_area) 1954 if (file && file->f_op->get_unmapped_area)
1955 get_area = file->f_op->get_unmapped_area; 1955 get_area = file->f_op->get_unmapped_area;
1956 addr = get_area(file, addr, len, pgoff, flags); 1956 addr = get_area(file, addr, len, pgoff, flags);
1957 if (IS_ERR_VALUE(addr)) 1957 if (IS_ERR_VALUE(addr))
diff --git a/mm/nommu.c b/mm/nommu.c
index ecd1f158548e..9e6cb02cba64 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -937,7 +937,7 @@ static int validate_mmap_request(struct file *file,
937 struct address_space *mapping; 937 struct address_space *mapping;
938 938
939 /* files must support mmap */ 939 /* files must support mmap */
940 if (!file->f_op || !file->f_op->mmap) 940 if (!file->f_op->mmap)
941 return -ENODEV; 941 return -ENODEV;
942 942
943 /* work out if what we've got could possibly be shared 943 /* work out if what we've got could possibly be shared
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index 3ffda1b3799b..9321a7763067 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -244,10 +244,10 @@ p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt)
244 if (!ts) 244 if (!ts)
245 return -EREMOTEIO; 245 return -EREMOTEIO;
246 246
247 if (!ts->rd->f_op || !ts->rd->f_op->poll) 247 if (!ts->rd->f_op->poll)
248 return -EIO; 248 return -EIO;
249 249
250 if (!ts->wr->f_op || !ts->wr->f_op->poll) 250 if (!ts->wr->f_op->poll)
251 return -EIO; 251 return -EIO;
252 252
253 ret = ts->rd->f_op->poll(ts->rd, pt); 253 ret = ts->rd->f_op->poll(ts->rd, pt);