Commit 72c2d531 authored by Al Viro's avatar Al Viro

file->f_op is never NULL...

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 22bd002e
...@@ -575,7 +575,7 @@ static int alloc_device(struct nandsim *ns) ...@@ -575,7 +575,7 @@ static int alloc_device(struct nandsim *ns)
cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600); cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600);
if (IS_ERR(cfile)) if (IS_ERR(cfile))
return PTR_ERR(cfile); return PTR_ERR(cfile);
if (!cfile->f_op || (!cfile->f_op->read && !cfile->f_op->aio_read)) { if (!cfile->f_op->read && !cfile->f_op->aio_read) {
NS_ERR("alloc_device: cache file not readable\n"); NS_ERR("alloc_device: cache file not readable\n");
err = -EINVAL; err = -EINVAL;
goto err_close; goto err_close;
......
...@@ -86,9 +86,6 @@ struct comedi32_insnlist_struct { ...@@ -86,9 +86,6 @@ struct comedi32_insnlist_struct {
static int translated_ioctl(struct file *file, unsigned int cmd, static int translated_ioctl(struct file *file, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
if (!file->f_op)
return -ENOTTY;
if (file->f_op->unlocked_ioctl) if (file->f_op->unlocked_ioctl)
return file->f_op->unlocked_ioctl(file, cmd, arg); return file->f_op->unlocked_ioctl(file, cmd, arg);
......
...@@ -271,7 +271,7 @@ void autofs4_clean_ino(struct autofs_info *); ...@@ -271,7 +271,7 @@ void autofs4_clean_ino(struct autofs_info *);
static inline int autofs_prepare_pipe(struct file *pipe) static inline int autofs_prepare_pipe(struct file *pipe)
{ {
if (!pipe->f_op || !pipe->f_op->write) if (!pipe->f_op->write)
return -EINVAL; return -EINVAL;
if (!S_ISFIFO(file_inode(pipe)->i_mode)) if (!S_ISFIFO(file_inode(pipe)->i_mode))
return -EINVAL; return -EINVAL;
......
...@@ -658,12 +658,6 @@ static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __use ...@@ -658,12 +658,6 @@ static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __use
goto out; goto out;
} }
if (!fp->f_op) {
err = -ENOTTY;
fput(fp);
goto out;
}
sbi = autofs_dev_ioctl_sbi(fp); sbi = autofs_dev_ioctl_sbi(fp);
if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
err = -EINVAL; err = -EINVAL;
......
...@@ -221,7 +221,7 @@ static int load_aout_binary(struct linux_binprm * bprm) ...@@ -221,7 +221,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
* Requires a mmap handler. This prevents people from using a.out * Requires a mmap handler. This prevents people from using a.out
* as part of an exploit attack against /proc-related vulnerabilities. * as part of an exploit attack against /proc-related vulnerabilities.
*/ */
if (!bprm->file->f_op || !bprm->file->f_op->mmap) if (!bprm->file->f_op->mmap)
return -ENOEXEC; return -ENOEXEC;
fd_offset = N_TXTOFF(ex); fd_offset = N_TXTOFF(ex);
...@@ -374,7 +374,7 @@ static int load_aout_library(struct file *file) ...@@ -374,7 +374,7 @@ static int load_aout_library(struct file *file)
* Requires a mmap handler. This prevents people from using a.out * Requires a mmap handler. This prevents people from using a.out
* as part of an exploit attack against /proc-related vulnerabilities. * as part of an exploit attack against /proc-related vulnerabilities.
*/ */
if (!file->f_op || !file->f_op->mmap) if (!file->f_op->mmap)
goto out; goto out;
if (N_FLAGS(ex)) if (N_FLAGS(ex))
......
...@@ -406,7 +406,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex, ...@@ -406,7 +406,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
goto out; goto out;
if (!elf_check_arch(interp_elf_ex)) if (!elf_check_arch(interp_elf_ex))
goto out; goto out;
if (!interpreter->f_op || !interpreter->f_op->mmap) if (!interpreter->f_op->mmap)
goto out; goto out;
/* /*
...@@ -607,7 +607,7 @@ static int load_elf_binary(struct linux_binprm *bprm) ...@@ -607,7 +607,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
goto out; goto out;
if (!elf_check_arch(&loc->elf_ex)) if (!elf_check_arch(&loc->elf_ex))
goto out; goto out;
if (!bprm->file->f_op || !bprm->file->f_op->mmap) if (!bprm->file->f_op->mmap)
goto out; goto out;
/* Now read in all of the header information */ /* Now read in all of the header information */
...@@ -1028,7 +1028,7 @@ static int load_elf_library(struct file *file) ...@@ -1028,7 +1028,7 @@ static int load_elf_library(struct file *file)
/* First of all, some simple consistency checks */ /* First of all, some simple consistency checks */
if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 || if (elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
!elf_check_arch(&elf_ex) || !file->f_op || !file->f_op->mmap) !elf_check_arch(&elf_ex) || !file->f_op->mmap)
goto out; goto out;
/* Now read in all of the header information */ /* Now read in all of the header information */
......
...@@ -111,7 +111,7 @@ static int is_elf_fdpic(struct elfhdr *hdr, struct file *file) ...@@ -111,7 +111,7 @@ static int is_elf_fdpic(struct elfhdr *hdr, struct file *file)
return 0; return 0;
if (!elf_check_arch(hdr) || !elf_check_fdpic(hdr)) if (!elf_check_arch(hdr) || !elf_check_fdpic(hdr))
return 0; return 0;
if (!file->f_op || !file->f_op->mmap) if (!file->f_op->mmap)
return 0; return 0;
return 1; return 1;
} }
......
...@@ -38,7 +38,7 @@ static int load_em86(struct linux_binprm *bprm) ...@@ -38,7 +38,7 @@ static int load_em86(struct linux_binprm *bprm)
/* First of all, some simple consistency checks */ /* First of all, some simple consistency checks */
if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) || if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
(!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) || (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
(!bprm->file->f_op || !bprm->file->f_op->mmap)) { !bprm->file->f_op->mmap) {
return -ENOEXEC; return -ENOEXEC;
} }
......
...@@ -387,9 +387,6 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx) ...@@ -387,9 +387,6 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx)
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container; host_file = cfi->cfi_container;
if (!host_file->f_op)
return -ENOTDIR;
if (host_file->f_op->iterate) { if (host_file->f_op->iterate) {
struct inode *host_inode = file_inode(host_file); struct inode *host_inode = file_inode(host_file);
mutex_lock(&host_inode->i_mutex); mutex_lock(&host_inode->i_mutex);
......
...@@ -36,7 +36,7 @@ coda_file_read(struct file *coda_file, char __user *buf, size_t count, loff_t *p ...@@ -36,7 +36,7 @@ coda_file_read(struct file *coda_file, char __user *buf, size_t count, loff_t *p
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container; host_file = cfi->cfi_container;
if (!host_file->f_op || !host_file->f_op->read) if (!host_file->f_op->read)
return -EINVAL; return -EINVAL;
return host_file->f_op->read(host_file, buf, count, ppos); 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,7 +75,7 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container; host_file = cfi->cfi_container;
if (!host_file->f_op || !host_file->f_op->write) if (!host_file->f_op->write)
return -EINVAL; return -EINVAL;
host_inode = file_inode(host_file); host_inode = file_inode(host_file);
...@@ -105,7 +105,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) ...@@ -105,7 +105,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container; host_file = cfi->cfi_container;
if (!host_file->f_op || !host_file->f_op->mmap) if (!host_file->f_op->mmap)
return -ENODEV; return -ENODEV;
coda_inode = file_inode(coda_file); coda_inode = file_inode(coda_file);
......
...@@ -1583,13 +1583,13 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, ...@@ -1583,13 +1583,13 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
/*FALL THROUGH*/ /*FALL THROUGH*/
default: default:
if (f.file->f_op && f.file->f_op->compat_ioctl) { if (f.file->f_op->compat_ioctl) {
error = f.file->f_op->compat_ioctl(f.file, cmd, arg); error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
if (error != -ENOIOCTLCMD) if (error != -ENOIOCTLCMD)
goto out_fput; goto out_fput;
} }
if (!f.file->f_op || !f.file->f_op->unlocked_ioctl) if (!f.file->f_op->unlocked_ioctl)
goto do_ioctl; goto do_ioctl;
break; break;
} }
......
...@@ -645,7 +645,7 @@ void do_coredump(siginfo_t *siginfo) ...@@ -645,7 +645,7 @@ void do_coredump(siginfo_t *siginfo)
*/ */
if (!uid_eq(inode->i_uid, current_fsuid())) if (!uid_eq(inode->i_uid, current_fsuid()))
goto close_fail; goto close_fail;
if (!cprm.file->f_op || !cprm.file->f_op->write) if (!cprm.file->f_op->write)
goto close_fail; goto close_fail;
if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file)) if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file))
goto close_fail; goto close_fail;
......
...@@ -271,7 +271,7 @@ static int ecryptfs_flush(struct file *file, fl_owner_t td) ...@@ -271,7 +271,7 @@ static int ecryptfs_flush(struct file *file, fl_owner_t td)
{ {
struct file *lower_file = ecryptfs_file_to_lower(file); struct file *lower_file = ecryptfs_file_to_lower(file);
if (lower_file->f_op && lower_file->f_op->flush) { if (lower_file->f_op->flush) {
filemap_write_and_wait(file->f_mapping); filemap_write_and_wait(file->f_mapping);
return lower_file->f_op->flush(lower_file, td); return lower_file->f_op->flush(lower_file, td);
} }
...@@ -305,7 +305,7 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag) ...@@ -305,7 +305,7 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
struct file *lower_file = NULL; struct file *lower_file = NULL;
lower_file = ecryptfs_file_to_lower(file); lower_file = ecryptfs_file_to_lower(file);
if (lower_file->f_op && lower_file->f_op->fasync) if (lower_file->f_op->fasync)
rc = lower_file->f_op->fasync(fd, lower_file, flag); rc = lower_file->f_op->fasync(fd, lower_file, flag);
return rc; return rc;
} }
...@@ -318,7 +318,7 @@ ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -318,7 +318,7 @@ ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (ecryptfs_file_to_private(file)) if (ecryptfs_file_to_private(file))
lower_file = ecryptfs_file_to_lower(file); lower_file = ecryptfs_file_to_lower(file);
if (lower_file && lower_file->f_op && lower_file->f_op->unlocked_ioctl) if (lower_file->f_op && lower_file->f_op->unlocked_ioctl)
rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg); rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
return rc; return rc;
} }
...@@ -332,7 +332,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -332,7 +332,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (ecryptfs_file_to_private(file)) if (ecryptfs_file_to_private(file))
lower_file = ecryptfs_file_to_lower(file); lower_file = ecryptfs_file_to_lower(file);
if (lower_file && lower_file->f_op && lower_file->f_op->compat_ioctl) if (lower_file->f_op && lower_file->f_op->compat_ioctl)
rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg); rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
return rc; return rc;
} }
......
...@@ -1816,7 +1816,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1816,7 +1816,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
/* The target file descriptor must support poll */ /* The target file descriptor must support poll */
error = -EPERM; error = -EPERM;
if (!tf.file->f_op || !tf.file->f_op->poll) if (!tf.file->f_op->poll)
goto error_tgt_fput; goto error_tgt_fput;
/* Check if EPOLLWAKEUP is allowed */ /* Check if EPOLLWAKEUP is allowed */
......
...@@ -106,6 +106,7 @@ static inline void put_binfmt(struct linux_binfmt * fmt) ...@@ -106,6 +106,7 @@ static inline void put_binfmt(struct linux_binfmt * fmt)
*/ */
SYSCALL_DEFINE1(uselib, const char __user *, library) SYSCALL_DEFINE1(uselib, const char __user *, library)
{ {
struct linux_binfmt *fmt;
struct file *file; struct file *file;
struct filename *tmp = getname(library); struct filename *tmp = getname(library);
int error = PTR_ERR(tmp); int error = PTR_ERR(tmp);
...@@ -136,8 +137,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) ...@@ -136,8 +137,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
fsnotify_open(file); fsnotify_open(file);
error = -ENOEXEC; error = -ENOEXEC;
if(file->f_op) {
struct linux_binfmt * fmt;
read_lock(&binfmt_lock); read_lock(&binfmt_lock);
list_for_each_entry(fmt, &formats, lh) { list_for_each_entry(fmt, &formats, lh) {
...@@ -153,7 +152,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) ...@@ -153,7 +152,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
break; break;
} }
read_unlock(&binfmt_lock); read_unlock(&binfmt_lock);
}
exit: exit:
fput(file); fput(file);
out: out:
...@@ -1277,13 +1275,10 @@ static int check_unsafe_exec(struct linux_binprm *bprm) ...@@ -1277,13 +1275,10 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
*/ */
int prepare_binprm(struct linux_binprm *bprm) int prepare_binprm(struct linux_binprm *bprm)
{ {
umode_t mode; struct inode *inode = file_inode(bprm->file);
struct inode * inode = file_inode(bprm->file); umode_t mode = inode->i_mode;
int retval; int retval;
mode = inode->i_mode;
if (bprm->file->f_op == NULL)
return -EACCES;
/* clear any previous set[ug]id data from a previous binary */ /* clear any previous set[ug]id data from a previous binary */
bprm->cred->euid = current_euid(); bprm->cred->euid = current_euid();
......
...@@ -56,7 +56,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg) ...@@ -56,7 +56,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
return -EINVAL; return -EINVAL;
} }
if (filp->f_op && filp->f_op->check_flags) if (filp->f_op->check_flags)
error = filp->f_op->check_flags(arg); error = filp->f_op->check_flags(arg);
if (error) if (error)
return error; return error;
...@@ -64,8 +64,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg) ...@@ -64,8 +64,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
/* /*
* ->fasync() is responsible for setting the FASYNC bit. * ->fasync() is responsible for setting the FASYNC bit.
*/ */
if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op && if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op->fasync) {
filp->f_op->fasync) {
error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
if (error < 0) if (error < 0)
goto out; goto out;
......
...@@ -240,11 +240,11 @@ static void __fput(struct file *file) ...@@ -240,11 +240,11 @@ static void __fput(struct file *file)
locks_remove_flock(file); locks_remove_flock(file);
if (unlikely(file->f_flags & FASYNC)) { if (unlikely(file->f_flags & FASYNC)) {
if (file->f_op && file->f_op->fasync) if (file->f_op->fasync)
file->f_op->fasync(-1, file, 0); file->f_op->fasync(-1, file, 0);
} }
ima_file_free(file); ima_file_free(file);
if (file->f_op && file->f_op->release) if (file->f_op->release)
file->f_op->release(inode, file); file->f_op->release(inode, file);
security_file_free(file); security_file_free(file);
if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL && if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
......
...@@ -37,7 +37,7 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd, ...@@ -37,7 +37,7 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd,
{ {
int error = -ENOTTY; int error = -ENOTTY;
if (!filp->f_op || !filp->f_op->unlocked_ioctl) if (!filp->f_op->unlocked_ioctl)
goto out; goto out;
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
...@@ -501,7 +501,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp, ...@@ -501,7 +501,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,
/* Did FASYNC state change ? */ /* Did FASYNC state change ? */
if ((flag ^ filp->f_flags) & FASYNC) { if ((flag ^ filp->f_flags) & FASYNC) {
if (filp->f_op && filp->f_op->fasync) if (filp->f_op->fasync)
/* fasync() adjusts filp->f_flags */ /* fasync() adjusts filp->f_flags */
error = filp->f_op->fasync(fd, filp, on); error = filp->f_op->fasync(fd, filp, on);
else else
......
...@@ -1579,7 +1579,7 @@ EXPORT_SYMBOL(generic_setlease); ...@@ -1579,7 +1579,7 @@ EXPORT_SYMBOL(generic_setlease);
static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease) static int __vfs_setlease(struct file *filp, long arg, struct file_lock **lease)
{ {
if (filp->f_op && filp->f_op->setlease) if (filp->f_op->setlease)
return filp->f_op->setlease(filp, arg, lease); return filp->f_op->setlease(filp, arg, lease);
else else
return generic_setlease(filp, arg, lease); return generic_setlease(filp, arg, lease);
...@@ -1771,7 +1771,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) ...@@ -1771,7 +1771,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
if (error) if (error)
goto out_free; goto out_free;
if (f.file->f_op && f.file->f_op->flock) if (f.file->f_op->flock)
error = f.file->f_op->flock(f.file, error = f.file->f_op->flock(f.file,
(can_sleep) ? F_SETLKW : F_SETLK, (can_sleep) ? F_SETLKW : F_SETLK,
lock); lock);
...@@ -1797,7 +1797,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) ...@@ -1797,7 +1797,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
*/ */
int vfs_test_lock(struct file *filp, struct file_lock *fl) int vfs_test_lock(struct file *filp, struct file_lock *fl)
{ {
if (filp->f_op && filp->f_op->lock) if (filp->f_op->lock)
return filp->f_op->lock(filp, F_GETLK, fl); return filp->f_op->lock(filp, F_GETLK, fl);
posix_test_lock(filp, fl); posix_test_lock(filp, fl);
return 0; return 0;
...@@ -1909,7 +1909,7 @@ int fcntl_getlk(struct file *filp, struct flock __user *l) ...@@ -1909,7 +1909,7 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)
*/ */
int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf) int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf)
{ {
if (filp->f_op && filp->f_op->lock) if (filp->f_op->lock)
return filp->f_op->lock(filp, cmd, fl); return filp->f_op->lock(filp, cmd, fl);
else else
return posix_lock_file(filp, fl, conf); return posix_lock_file(filp, fl, conf);
...@@ -2182,7 +2182,7 @@ void locks_remove_flock(struct file *filp) ...@@ -2182,7 +2182,7 @@ void locks_remove_flock(struct file *filp)
if (!inode->i_flock) if (!inode->i_flock)
return; return;
if (filp->f_op && filp->f_op->flock) { if (filp->f_op->flock) {
struct file_lock fl = { struct file_lock fl = {
.fl_pid = current->tgid, .fl_pid = current->tgid,
.fl_file = filp, .fl_file = filp,
...@@ -2246,7 +2246,7 @@ EXPORT_SYMBOL(posix_unblock_lock); ...@@ -2246,7 +2246,7 @@ EXPORT_SYMBOL(posix_unblock_lock);
*/ */
int vfs_cancel_lock(struct file *filp, struct file_lock *fl) int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
{ {
if (filp->f_op && filp->f_op->lock) if (filp->f_op->lock)
return filp->f_op->lock(filp, F_CANCELLK, fl); return filp->f_op->lock(filp, F_CANCELLK, fl);
return 0; return 0;
} }
......
...@@ -693,6 +693,10 @@ static int do_dentry_open(struct file *f, ...@@ -693,6 +693,10 @@ static int do_dentry_open(struct file *f,
} }
f->f_op = fops_get(inode->i_fop); f->f_op = fops_get(inode->i_fop);
if (unlikely(WARN_ON(!f->f_op))) {
error = -ENODEV;
goto cleanup_all;
}
error = security_file_open(f, cred); error = security_file_open(f, cred);
if (error) if (error)
...@@ -702,7 +706,7 @@ static int do_dentry_open(struct file *f, ...@@ -702,7 +706,7 @@ static int do_dentry_open(struct file *f,
if (error) if (error)
goto cleanup_all; goto cleanup_all;
if (!open && f->f_op) if (!open)
open = f->f_op->open; open = f->f_op->open;
if (open) { if (open) {
error = open(inode, f); error = open(inode, f);
...@@ -1023,7 +1027,7 @@ int filp_close(struct file *filp, fl_owner_t id) ...@@ -1023,7 +1027,7 @@ int filp_close(struct file *filp, fl_owner_t id)
return 0; return 0;
} }
if (filp->f_op && filp->f_op->flush) if (filp->f_op->flush)
retval = filp->f_op->flush(filp, id); retval = filp->f_op->flush(filp, id);
if (likely(!(filp->f_mode & FMODE_PATH))) { if (likely(!(filp->f_mode & FMODE_PATH))) {
......
...@@ -257,7 +257,7 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence) ...@@ -257,7 +257,7 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
fn = no_llseek; fn = no_llseek;
if (file->f_mode & FMODE_LSEEK) { if (file->f_mode & FMODE_LSEEK) {
if (file->f_op && file->f_op->llseek) if (file->f_op->llseek)
fn = file->f_op->llseek; fn = file->f_op->llseek;
} }
return fn(file, offset, whence); 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,7 +384,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
if (!(file->f_mode & FMODE_READ)) if (!(file->f_mode & FMODE_READ))
return -EBADF; return -EBADF;
if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read)) if (!file->f_op->read && !file->f_op->aio_read)
return -EINVAL; return -EINVAL;
if (unlikely(!access_ok(VERIFY_WRITE, buf, count))) if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
return -EFAULT; return -EFAULT;
...@@ -433,7 +433,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t ...@@ -433,7 +433,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
const char __user *p; const char __user *p;
ssize_t ret; ssize_t ret;
if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write)) if (!file->f_op->write && !file->f_op->aio_write)
return -EINVAL; return -EINVAL;
old_fs = get_fs(); old_fs = get_fs();
...@@ -460,7 +460,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ ...@@ -460,7 +460,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
if (!(file->f_mode & FMODE_WRITE)) if (!(file->f_mode & FMODE_WRITE))
return -EBADF; return -EBADF;
if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write)) if (!file->f_op->write && !file->f_op->aio_write)
return -EINVAL; return -EINVAL;
if (unlikely(!access_ok(VERIFY_READ, buf, count))) if (unlikely(!access_ok(VERIFY_READ, buf, count)))
return -EFAULT; return -EFAULT;
...@@ -727,11 +727,6 @@ static ssize_t do_readv_writev(int type, struct file *file, ...@@ -727,11 +727,6 @@ static ssize_t do_readv_writev(int type, struct file *file,
io_fn_t fn; io_fn_t fn;
iov_fn_t fnv; iov_fn_t fnv;
if (!file->f_op) {
ret = -EINVAL;
goto out;
}
ret = rw_copy_check_uvector(type, uvector, nr_segs, ret = rw_copy_check_uvector(type, uvector, nr_segs,
ARRAY_SIZE(iovstack), iovstack, &iov); ARRAY_SIZE(iovstack), iovstack, &iov);
if (ret <= 0) if (ret <= 0)
...@@ -778,7 +773,7 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, ...@@ -778,7 +773,7 @@ ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
{ {
if (!(file->f_mode & FMODE_READ)) if (!(file->f_mode & FMODE_READ))
return -EBADF; return -EBADF;
if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read)) if (!file->f_op->aio_read && !file->f_op->read)
return -EINVAL; return -EINVAL;
return do_readv_writev(READ, file, vec, vlen, pos); 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,7 +786,7 @@ ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
{ {
if (!(file->f_mode & FMODE_WRITE)) if (!(file->f_mode & FMODE_WRITE))
return -EBADF; return -EBADF;
if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write)) if (!file->f_op->aio_write && !file->f_op->write)
return -EINVAL; return -EINVAL;
return do_readv_writev(WRITE, file, vec, vlen, pos); 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,10 +901,6 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
io_fn_t fn; io_fn_t fn;
iov_fn_t fnv; iov_fn_t fnv;
ret = -EINVAL;
if (!file->f_op)
goto out;
ret = -EFAULT; ret = -EFAULT;
if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector))) if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
goto out; goto out;
...@@ -965,7 +956,7 @@ static size_t compat_readv(struct file *file, ...@@ -965,7 +956,7 @@ static size_t compat_readv(struct file *file,
goto out; goto out;
ret = -EINVAL; ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read)) if (!file->f_op->aio_read && !file->f_op->read)
goto out; goto out;
ret = compat_do_readv_writev(READ, file, vec, vlen, pos); ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
...@@ -1032,7 +1023,7 @@ static size_t compat_writev(struct file *file, ...@@ -1032,7 +1023,7 @@ static size_t compat_writev(struct file *file,
goto out; goto out;
ret = -EINVAL; ret = -EINVAL;
if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write)) if (!file->f_op->aio_write && !file->f_op->write)
goto out; goto out;
ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos); ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
......
...@@ -24,7 +24,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx) ...@@ -24,7 +24,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
int res = -ENOTDIR; int res = -ENOTDIR;
if (!file->f_op || !file->f_op->iterate) if (!file->f_op->iterate)
goto out; goto out;
res = security_file_permission(file, MAY_READ); res = security_file_permission(file, MAY_READ);
......
...@@ -455,7 +455,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time) ...@@ -455,7 +455,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
const struct file_operations *f_op; const struct file_operations *f_op;
f_op = f.file->f_op; f_op = f.file->f_op;
mask = DEFAULT_POLLMASK; mask = DEFAULT_POLLMASK;
if (f_op && f_op->poll) { if (f_op->poll) {
wait_key_set(wait, in, out, wait_key_set(wait, in, out,
bit, busy_flag); bit, busy_flag);
mask = (*f_op->poll)(f.file, wait); mask = (*f_op->poll)(f.file, wait);
...@@ -762,7 +762,7 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait, ...@@ -762,7 +762,7 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait,
mask = POLLNVAL; mask = POLLNVAL;
if (f.file) { if (f.file) {
mask = DEFAULT_POLLMASK; mask = DEFAULT_POLLMASK;
if (f.file->f_op && f.file->f_op->poll) { if (f.file->f_op->poll) {
pwait->_key = pollfd->events|POLLERR|POLLHUP; pwait->_key = pollfd->events|POLLERR|POLLHUP;
pwait->_key |= busy_flag; pwait->_key |= busy_flag;
mask = f.file->f_op->poll(f.file, pwait); mask = f.file->f_op->poll(f.file, pwait);
......
...@@ -695,7 +695,7 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe, ...@@ -695,7 +695,7 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe,
loff_t pos = sd->pos; loff_t pos = sd->pos;
int more; int more;
if (!likely(file->f_op && file->f_op->sendpage)) if (!likely(file->f_op->sendpage))
return -EINVAL; return -EINVAL;
more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0; 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,7 +1099,7 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
loff_t *, size_t, unsigned int); loff_t *, size_t, unsigned int);
if (out->f_op && out->f_op->splice_write) if (out->f_op->splice_write)
splice_write = out->f_op->splice_write; splice_write = out->f_op->splice_write;
else else
splice_write = default_file_splice_write; splice_write = default_file_splice_write;
...@@ -1125,7 +1125,7 @@ static long do_splice_to(struct file *in, loff_t *ppos, ...@@ -1125,7 +1125,7 @@ static long do_splice_to(struct file *in, loff_t *ppos,
if (unlikely(ret < 0)) if (unlikely(ret < 0))
return ret; return ret;
if (in->f_op && in->f_op->splice_read) if (in->f_op->splice_read)
splice_read = in->f_op->splice_read; splice_read = in->f_op->splice_read;
else else
splice_read = default_file_splice_read; splice_read = default_file_splice_read;
......
...@@ -177,7 +177,7 @@ SYSCALL_DEFINE1(syncfs, int, fd) ...@@ -177,7 +177,7 @@ SYSCALL_DEFINE1(syncfs, int, fd)
*/ */
int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync) int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync)
{ {
if (!file->f_op || !file->f_op->fsync) if (!file->f_op->fsync)
return -EINVAL; return -EINVAL;
return file->f_op->fsync(file, start, end, datasync); return file->f_op->fsync(file, start, end, datasync);
} }
......
...@@ -681,7 +681,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr, ...@@ -681,7 +681,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
if (vma->vm_ops) if (vma->vm_ops)
printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n", printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
vma->vm_ops->fault); vma->vm_ops->fault);
if (vma->vm_file && vma->vm_file->f_op) if (vma->vm_file)
printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n", printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
vma->vm_file->f_op->mmap); vma->vm_file->f_op->mmap);
dump_stack(); dump_stack();
......
...@@ -1299,7 +1299,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, ...@@ -1299,7 +1299,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
vm_flags &= ~VM_MAYEXEC; vm_flags &= ~VM_MAYEXEC;
} }
if (!file->f_op || !file->f_op->mmap) if (!file->f_op->mmap)
return -ENODEV; return -ENODEV;
if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP)) if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
return -EINVAL; return -EINVAL;
...@@ -1951,7 +1951,7 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, ...@@ -1951,7 +1951,7 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
return -ENOMEM; return -ENOMEM;
get_area = current->mm->get_unmapped_area; get_area = current->mm->get_unmapped_area;
if (file && file->f_op && file->f_op->get_unmapped_area) if (file && file->f_op->get_unmapped_area)
get_area = file->f_op->get_unmapped_area; get_area = file->f_op->get_unmapped_area;
addr = get_area(file, addr, len, pgoff, flags); addr = get_area(file, addr, len, pgoff, flags);
if (IS_ERR_VALUE(addr)) if (IS_ERR_VALUE(addr))
......
...@@ -937,7 +937,7 @@ static int validate_mmap_request(struct file *file, ...@@ -937,7 +937,7 @@ static int validate_mmap_request(struct file *file,
struct address_space *mapping; struct address_space *mapping;
/* files must support mmap */ /* files must support mmap */
if (!file->f_op || !file->f_op->mmap) if (!file->f_op->mmap)
return -ENODEV; return -ENODEV;
/* work out if what we've got could possibly be shared /* work out if what we've got could possibly be shared
......
...@@ -244,10 +244,10 @@ p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt) ...@@ -244,10 +244,10 @@ p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt)
if (!ts) if (!ts)
return -EREMOTEIO; return -EREMOTEIO;
if (!ts->rd->f_op || !ts->rd->f_op->poll) if (!ts->rd->f_op->poll)
return -EIO; return -EIO;
if (!ts->wr->f_op || !ts->wr->f_op->poll) if (!ts->wr->f_op->poll)
return -EIO; return -EIO;
ret = ts->rd->f_op->poll(ts->rd, pt); ret = ts->rd->f_op->poll(ts->rd, pt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment