Skip to content

Commit

Permalink
file->f_op is never NULL...
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Oct 25, 2013
1 parent 22bd002 commit 72c2d53
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 97 deletions.
2 changes: 1 addition & 1 deletion drivers/mtd/nand/nandsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static int alloc_device(struct nandsim *ns)
cfile = filp_open(cache_file, O_CREAT | O_RDWR | O_LARGEFILE, 0600);
if (IS_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");
err = -EINVAL;
goto err_close;
Expand Down
3 changes: 0 additions & 3 deletions drivers/staging/comedi/comedi_compat32.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ struct comedi32_insnlist_struct {
static int translated_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
if (!file->f_op)
return -ENOTTY;

if (file->f_op->unlocked_ioctl)
return file->f_op->unlocked_ioctl(file, cmd, arg);

Expand Down
2 changes: 1 addition & 1 deletion fs/autofs4/autofs_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void autofs4_clean_ino(struct autofs_info *);

static inline int autofs_prepare_pipe(struct file *pipe)
{
if (!pipe->f_op || !pipe->f_op->write)
if (!pipe->f_op->write)
return -EINVAL;
if (!S_ISFIFO(file_inode(pipe)->i_mode))
return -EINVAL;
Expand Down
6 changes: 0 additions & 6 deletions fs/autofs4/dev-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,12 +658,6 @@ static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __use
goto out;
}

if (!fp->f_op) {
err = -ENOTTY;
fput(fp);
goto out;
}

sbi = autofs_dev_ioctl_sbi(fp);
if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
err = -EINVAL;
Expand Down
4 changes: 2 additions & 2 deletions fs/binfmt_aout.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
* Requires a mmap handler. This prevents people from using a.out
* 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;

fd_offset = N_TXTOFF(ex);
Expand Down Expand Up @@ -374,7 +374,7 @@ static int load_aout_library(struct file *file)
* Requires a mmap handler. This prevents people from using a.out
* 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;

if (N_FLAGS(ex))
Expand Down
6 changes: 3 additions & 3 deletions fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
goto out;
if (!elf_check_arch(interp_elf_ex))
goto out;
if (!interpreter->f_op || !interpreter->f_op->mmap)
if (!interpreter->f_op->mmap)
goto out;

/*
Expand Down Expand Up @@ -607,7 +607,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
goto out;
if (!elf_check_arch(&loc->elf_ex))
goto out;
if (!bprm->file->f_op || !bprm->file->f_op->mmap)
if (!bprm->file->f_op->mmap)
goto out;

/* Now read in all of the header information */
Expand Down Expand Up @@ -1028,7 +1028,7 @@ static int load_elf_library(struct file *file)

/* First of all, some simple consistency checks */
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;

/* Now read in all of the header information */
Expand Down
2 changes: 1 addition & 1 deletion fs/binfmt_elf_fdpic.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static int is_elf_fdpic(struct elfhdr *hdr, struct file *file)
return 0;
if (!elf_check_arch(hdr) || !elf_check_fdpic(hdr))
return 0;
if (!file->f_op || !file->f_op->mmap)
if (!file->f_op->mmap)
return 0;
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/binfmt_em86.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int load_em86(struct linux_binprm *bprm)
/* First of all, some simple consistency checks */
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))) ||
(!bprm->file->f_op || !bprm->file->f_op->mmap)) {
!bprm->file->f_op->mmap) {
return -ENOEXEC;
}

Expand Down
3 changes: 0 additions & 3 deletions fs/coda/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx)
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container;

if (!host_file->f_op)
return -ENOTDIR;

if (host_file->f_op->iterate) {
struct inode *host_inode = file_inode(host_file);
mutex_lock(&host_inode->i_mutex);
Expand Down
6 changes: 3 additions & 3 deletions fs/coda/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
host_file = cfi->cfi_container;

if (!host_file->f_op || !host_file->f_op->read)
if (!host_file->f_op->read)
return -EINVAL;

return host_file->f_op->read(host_file, buf, count, ppos);
Expand Down Expand Up @@ -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);
host_file = cfi->cfi_container;

if (!host_file->f_op || !host_file->f_op->write)
if (!host_file->f_op->write)
return -EINVAL;

host_inode = file_inode(host_file);
Expand Down Expand Up @@ -105,7 +105,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container;

if (!host_file->f_op || !host_file->f_op->mmap)
if (!host_file->f_op->mmap)
return -ENODEV;

coda_inode = file_inode(coda_file);
Expand Down
4 changes: 2 additions & 2 deletions fs/compat_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1583,13 +1583,13 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
/*FALL THROUGH*/

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);
if (error != -ENOIOCTLCMD)
goto out_fput;
}

if (!f.file->f_op || !f.file->f_op->unlocked_ioctl)
if (!f.file->f_op->unlocked_ioctl)
goto do_ioctl;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ void do_coredump(siginfo_t *siginfo)
*/
if (!uid_eq(inode->i_uid, current_fsuid()))
goto close_fail;
if (!cprm.file->f_op || !cprm.file->f_op->write)
if (!cprm.file->f_op->write)
goto close_fail;
if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file))
goto close_fail;
Expand Down
8 changes: 4 additions & 4 deletions fs/ecryptfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static int ecryptfs_flush(struct file *file, fl_owner_t td)
{
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);
return lower_file->f_op->flush(lower_file, td);
}
Expand Down Expand Up @@ -305,7 +305,7 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
struct file *lower_file = NULL;

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);
return rc;
}
Expand All @@ -318,7 +318,7 @@ ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

if (ecryptfs_file_to_private(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);
return rc;
}
Expand All @@ -332,7 +332,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

if (ecryptfs_file_to_private(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);
return rc;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,

/* The target file descriptor must support poll */
error = -EPERM;
if (!tf.file->f_op || !tf.file->f_op->poll)
if (!tf.file->f_op->poll)
goto error_tgt_fput;

/* Check if EPOLLWAKEUP is allowed */
Expand Down
35 changes: 15 additions & 20 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static inline void put_binfmt(struct linux_binfmt * fmt)
*/
SYSCALL_DEFINE1(uselib, const char __user *, library)
{
struct linux_binfmt *fmt;
struct file *file;
struct filename *tmp = getname(library);
int error = PTR_ERR(tmp);
Expand Down Expand Up @@ -136,24 +137,21 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
fsnotify_open(file);

error = -ENOEXEC;
if(file->f_op) {
struct linux_binfmt * fmt;

read_lock(&binfmt_lock);
list_for_each_entry(fmt, &formats, lh) {
if (!fmt->load_shlib)
continue;
if (!try_module_get(fmt->module))
continue;
read_unlock(&binfmt_lock);
error = fmt->load_shlib(file);
read_lock(&binfmt_lock);
put_binfmt(fmt);
if (error != -ENOEXEC)
break;
}
read_lock(&binfmt_lock);
list_for_each_entry(fmt, &formats, lh) {
if (!fmt->load_shlib)
continue;
if (!try_module_get(fmt->module))
continue;
read_unlock(&binfmt_lock);
error = fmt->load_shlib(file);
read_lock(&binfmt_lock);
put_binfmt(fmt);
if (error != -ENOEXEC)
break;
}
read_unlock(&binfmt_lock);
exit:
fput(file);
out:
Expand Down Expand Up @@ -1277,13 +1275,10 @@ static int check_unsafe_exec(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;

mode = inode->i_mode;
if (bprm->file->f_op == NULL)
return -EACCES;

/* clear any previous set[ug]id data from a previous binary */
bprm->cred->euid = current_euid();
Expand Down
5 changes: 2 additions & 3 deletions fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
return -EINVAL;
}

if (filp->f_op && filp->f_op->check_flags)
if (filp->f_op->check_flags)
error = filp->f_op->check_flags(arg);
if (error)
return error;

/*
* ->fasync() is responsible for setting the FASYNC bit.
*/
if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op &&
filp->f_op->fasync) {
if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op->fasync) {
error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
if (error < 0)
goto out;
Expand Down
4 changes: 2 additions & 2 deletions fs/file_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ static void __fput(struct file *file)
locks_remove_flock(file);

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);
}
ima_file_free(file);
if (file->f_op && file->f_op->release)
if (file->f_op->release)
file->f_op->release(inode, file);
security_file_free(file);
if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
Expand Down
4 changes: 2 additions & 2 deletions fs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd,
{
int error = -ENOTTY;

if (!filp->f_op || !filp->f_op->unlocked_ioctl)
if (!filp->f_op->unlocked_ioctl)
goto out;

error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
Expand Down Expand Up @@ -501,7 +501,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,

/* Did FASYNC state change ? */
if ((flag ^ filp->f_flags) & FASYNC) {
if (filp->f_op && filp->f_op->fasync)
if (filp->f_op->fasync)
/* fasync() adjusts filp->f_flags */
error = filp->f_op->fasync(fd, filp, on);
else
Expand Down
12 changes: 6 additions & 6 deletions fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ EXPORT_SYMBOL(generic_setlease);

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);
else
return generic_setlease(filp, arg, lease);
Expand Down Expand Up @@ -1771,7 +1771,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
if (error)
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,
(can_sleep) ? F_SETLKW : F_SETLK,
lock);
Expand All @@ -1797,7 +1797,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
*/
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);
posix_test_lock(filp, fl);
return 0;
Expand Down Expand Up @@ -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)
{
if (filp->f_op && filp->f_op->lock)
if (filp->f_op->lock)
return filp->f_op->lock(filp, cmd, fl);
else
return posix_lock_file(filp, fl, conf);
Expand Down Expand Up @@ -2182,7 +2182,7 @@ void locks_remove_flock(struct file *filp)
if (!inode->i_flock)
return;

if (filp->f_op && filp->f_op->flock) {
if (filp->f_op->flock) {
struct file_lock fl = {
.fl_pid = current->tgid,
.fl_file = filp,
Expand Down Expand Up @@ -2246,7 +2246,7 @@ EXPORT_SYMBOL(posix_unblock_lock);
*/
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 0;
}
Expand Down
Loading

0 comments on commit 72c2d53

Please sign in to comment.