···6969 umode_t, mode, int, neighbor_fd)7070{7171 long ret;7272- struct file *neighbor;7373- int fput_needed;7472 struct spufs_calls *calls;75737674 calls = spufs_calls_get();···7678 return -ENOSYS;77797880 if (flags & SPU_CREATE_AFFINITY_SPU) {8181+ struct fd neighbor = fdget(neighbor_fd);7982 ret = -EBADF;8080- neighbor = fget_light(neighbor_fd, &fput_needed);8181- if (neighbor) {8282- ret = calls->create_thread(name, flags, mode, neighbor);8383- fput_light(neighbor, fput_needed);8383+ if (neighbor.file) {8484+ ret = calls->create_thread(name, flags, mode, neighbor.file);8585+ fdput(neighbor);8486 }8587 } else8688 ret = calls->create_thread(name, flags, mode, NULL);···9294asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)9395{9496 long ret;9595- struct file *filp;9696- int fput_needed;9797+ struct fd arg;9798 struct spufs_calls *calls;989999100 calls = spufs_calls_get();···100103 return -ENOSYS;101104102105 ret = -EBADF;103103- filp = fget_light(fd, &fput_needed);104104- if (filp) {105105- ret = calls->spu_run(filp, unpc, ustatus);106106- fput_light(filp, fput_needed);106106+ arg = fdget(fd);107107+ if (arg.file) {108108+ ret = calls->spu_run(arg.file, unpc, ustatus);109109+ fdput(arg);107110 }108111109112 spufs_calls_put(calls);
+6-6
drivers/infiniband/core/ucma.c
···11841184 struct rdma_ucm_migrate_id cmd;11851185 struct rdma_ucm_migrate_resp resp;11861186 struct ucma_context *ctx;11871187- struct file *filp;11871187+ struct fd f;11881188 struct ucma_file *cur_file;11891189- int ret = 0, fput_needed;11891189+ int ret = 0;1190119011911191 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))11921192 return -EFAULT;1193119311941194 /* Get current fd to protect against it being closed */11951195- filp = fget_light(cmd.fd, &fput_needed);11961196- if (!filp)11951195+ f = fdget(cmd.fd);11961196+ if (!f.file)11971197 return -ENOENT;1198119811991199 /* Validate current fd and prevent destruction of id. */12001200- ctx = ucma_get_ctx(filp->private_data, cmd.id);12001200+ ctx = ucma_get_ctx(f.file->private_data, cmd.id);12011201 if (IS_ERR(ctx)) {12021202 ret = PTR_ERR(ctx);12031203 goto file_put;···1231123112321232 ucma_put_ctx(ctx);12331233file_put:12341234- fput_light(filp, fput_needed);12341234+ fdput(f);12351235 return ret;12361236}12371237
+9-9
drivers/infiniband/core/uverbs_cmd.c
···705705 struct ib_udata udata;706706 struct ib_uxrcd_object *obj;707707 struct ib_xrcd *xrcd = NULL;708708- struct file *f = NULL;708708+ struct fd f = {NULL, 0};709709 struct inode *inode = NULL;710710- int ret = 0, fput_needed;710710+ int ret = 0;711711 int new_xrcd = 0;712712713713 if (out_len < sizeof resp)···724724725725 if (cmd.fd != -1) {726726 /* search for file descriptor */727727- f = fget_light(cmd.fd, &fput_needed);728728- if (!f) {727727+ f = fdget(cmd.fd);728728+ if (!f.file) {729729 ret = -EBADF;730730 goto err_tree_mutex_unlock;731731 }732732733733- inode = f->f_dentry->d_inode;733733+ inode = f.file->f_path.dentry->d_inode;734734 xrcd = find_xrcd(file->device, inode);735735 if (!xrcd && !(cmd.oflags & O_CREAT)) {736736 /* no file descriptor. Need CREATE flag */···795795 goto err_copy;796796 }797797798798- if (f)799799- fput_light(f, fput_needed);798798+ if (f.file)799799+ fdput(f);800800801801 mutex_lock(&file->mutex);802802 list_add_tail(&obj->uobject.list, &file->ucontext->xrcd_list);···825825 put_uobj_write(&obj->uobject);826826827827err_tree_mutex_unlock:828828- if (f)829829- fput_light(f, fput_needed);828828+ if (f.file)829829+ fdput(f);830830831831 mutex_unlock(&file->device->xrcd_tree_mutex);832832
+5-7
drivers/infiniband/core/uverbs_main.c
···541541struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)542542{543543 struct ib_uverbs_event_file *ev_file = NULL;544544- struct file *filp;545545- int fput_needed;544544+ struct fd f = fdget(fd);546545547547- filp = fget_light(fd, &fput_needed);548548- if (!filp)546546+ if (!f.file)549547 return NULL;550548551551- if (filp->f_op != &uverbs_event_fops)549549+ if (f.file->f_op != &uverbs_event_fops)552550 goto out;553551554554- ev_file = filp->private_data;552552+ ev_file = f.file->private_data;555553 if (ev_file->is_async) {556554 ev_file = NULL;557555 goto out;···558560 kref_get(&ev_file->ref);559561560562out:561561- fput_light(filp, fput_needed);563563+ fdput(f);562564 return ev_file;563565}564566
+8-9
drivers/vfio/vfio.c
···1014101410151015static int vfio_group_set_container(struct vfio_group *group, int container_fd)10161016{10171017- struct file *filep;10171017+ struct fd f;10181018 struct vfio_container *container;10191019 struct vfio_iommu_driver *driver;10201020- int ret = 0, fput_needed;10201020+ int ret = 0;1021102110221022 if (atomic_read(&group->container_users))10231023 return -EINVAL;1024102410251025- filep = fget_light(container_fd, &fput_needed);10261026- if (!filep)10251025+ f = fdget(container_fd);10261026+ if (!f.file)10271027 return -EBADF;1028102810291029 /* Sanity check, is this really our fd? */10301030- if (filep->f_op != &vfio_fops) {10311031- fput_light(filep, fput_needed);10301030+ if (f.file->f_op != &vfio_fops) {10311031+ fdput(f);10321032 return -EINVAL;10331033 }1034103410351035- container = filep->private_data;10351035+ container = f.file->private_data;10361036 WARN_ON(!container); /* fget ensures we don't race vfio_release */1037103710381038 mutex_lock(&container->group_lock);···1054105410551055unlock_out:10561056 mutex_unlock(&container->group_lock);10571057- fput_light(filep, fput_needed);10581058-10571057+ fdput(f);10591058 return ret;10601059}10611060
+5-7
drivers/video/msm/mdp.c
···257257 unsigned long *start, unsigned long *len,258258 struct file **filep)259259{260260- int put_needed, ret = 0;261261- struct file *file;262262-263263- file = fget_light(img->memory_id, &put_needed);264264- if (file == NULL)260260+ int ret = 0;261261+ struct fd f = fdget(img->memory_id);262262+ if (f.file == NULL)265263 return -1;266264267267- if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {265265+ if (MAJOR(f.file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {268266 *start = info->fix.smem_start;269267 *len = info->fix.smem_len;270268 } else271269 ret = -1;272272- fput_light(file, put_needed);270270+ fdput(f);273271274272 return ret;275273}
+12-14
fs/btrfs/ioctl.c
···13971397 u64 *transid, bool readonly,13981398 struct btrfs_qgroup_inherit **inherit)13991399{14001400- struct file *src_file;14011400 int namelen;14021401 int ret = 0;14031402···14201421 ret = btrfs_mksubvol(&file->f_path, name, namelen,14211422 NULL, transid, readonly, inherit);14221423 } else {14241424+ struct fd src = fdget(fd);14231425 struct inode *src_inode;14241424- int fput_needed;14251425- src_file = fget_light(fd, &fput_needed);14261426- if (!src_file) {14261426+ if (!src.file) {14271427 ret = -EINVAL;14281428 goto out_drop_write;14291429 }1430143014311431- src_inode = src_file->f_path.dentry->d_inode;14311431+ src_inode = src.file->f_path.dentry->d_inode;14321432 if (src_inode->i_sb != file->f_path.dentry->d_inode->i_sb) {14331433 printk(KERN_INFO "btrfs: Snapshot src from "14341434 "another FS\n");···14371439 BTRFS_I(src_inode)->root,14381440 transid, readonly, inherit);14391441 }14401440- fput_light(src_file, fput_needed);14421442+ fdput(src);14411443 }14421444out_drop_write:14431445 mnt_drop_write_file(file);···23392341{23402342 struct inode *inode = fdentry(file)->d_inode;23412343 struct btrfs_root *root = BTRFS_I(inode)->root;23422342- struct file *src_file;23442344+ struct fd src_file;23432345 struct inode *src;23442346 struct btrfs_trans_handle *trans;23452347 struct btrfs_path *path;···23482350 struct btrfs_key key;23492351 u32 nritems;23502352 int slot;23512351- int ret, fput_needed;23532353+ int ret;23522354 u64 len = olen;23532355 u64 bs = root->fs_info->sb->s_blocksize;23542356 u64 hint_byte;···23742376 if (ret)23752377 return ret;2376237823772377- src_file = fget_light(srcfd, &fput_needed);23782378- if (!src_file) {23792379+ src_file = fdget(srcfd);23802380+ if (!src_file.file) {23792381 ret = -EBADF;23802382 goto out_drop_write;23812383 }2382238423832385 ret = -EXDEV;23842384- if (src_file->f_path.mnt != file->f_path.mnt)23862386+ if (src_file.file->f_path.mnt != file->f_path.mnt)23852387 goto out_fput;2386238823872387- src = src_file->f_dentry->d_inode;23892389+ src = src_file.file->f_dentry->d_inode;2388239023892391 ret = -EINVAL;23902392 if (src == inode)23912393 goto out_fput;2392239423932395 /* the src must be open for reading */23942394- if (!(src_file->f_mode & FMODE_READ))23962396+ if (!(src_file.file->f_mode & FMODE_READ))23952397 goto out_fput;2396239823972399 /* don't make the dst file partly checksummed */···27222724 vfree(buf);27232725 btrfs_free_path(path);27242726out_fput:27252725- fput_light(src_file, fput_needed);27272727+ fdput(src_file);27262728out_drop_write:27272729 mnt_drop_write_file(file);27282730 return ret;
+7-7
fs/coda/inode.c
···107107108108static int get_device_index(struct coda_mount_data *data)109109{110110- struct file *file;110110+ struct fd f;111111 struct inode *inode;112112- int idx, fput_needed;112112+ int idx;113113114114 if (data == NULL) {115115 printk("coda_read_super: Bad mount data\n");···121121 return -1;122122 }123123124124- file = fget_light(data->fd, &fput_needed);125125- if (!file)124124+ f = fdget(data->fd);125125+ if (!f.file)126126 goto Ebadf;127127- inode = file->f_path.dentry->d_inode;127127+ inode = f.file->f_path.dentry->d_inode;128128 if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) {129129- fput_light(file, fput_needed);129129+ fdput(f);130130 goto Ebadf;131131 }132132133133 idx = iminor(inode);134134- fput_light(file, fput_needed);134134+ fdput(f);135135136136 if (idx < 0 || idx >= MAX_CODADEVS) {137137 printk("coda_read_super: Bad minor number\n");
+40-50
fs/compat.c
···870870 struct compat_old_linux_dirent __user *dirent, unsigned int count)871871{872872 int error;873873- struct file *file;874874- int fput_needed;873873+ struct fd f = fdget(fd);875874 struct compat_readdir_callback buf;876875877877- file = fget_light(fd, &fput_needed);878878- if (!file)876876+ if (!f.file)879877 return -EBADF;880878881879 buf.result = 0;882880 buf.dirent = dirent;883881884884- error = vfs_readdir(file, compat_fillonedir, &buf);882882+ error = vfs_readdir(f.file, compat_fillonedir, &buf);885883 if (buf.result)886884 error = buf.result;887885888888- fput_light(file, fput_needed);886886+ fdput(f);889887 return error;890888}891889···947949asmlinkage long compat_sys_getdents(unsigned int fd,948950 struct compat_linux_dirent __user *dirent, unsigned int count)949951{950950- struct file * file;952952+ struct fd f;951953 struct compat_linux_dirent __user * lastdirent;952954 struct compat_getdents_callback buf;953953- int fput_needed;954955 int error;955956956957 if (!access_ok(VERIFY_WRITE, dirent, count))957958 return -EFAULT;958959959959- file = fget_light(fd, &fput_needed);960960- if (!file)960960+ f = fdget(fd);961961+ if (!f.file)961962 return -EBADF;962963963964 buf.current_dir = dirent;···964967 buf.count = count;965968 buf.error = 0;966969967967- error = vfs_readdir(file, compat_filldir, &buf);970970+ error = vfs_readdir(f.file, compat_filldir, &buf);968971 if (error >= 0)969972 error = buf.error;970973 lastdirent = buf.previous;971974 if (lastdirent) {972972- if (put_user(file->f_pos, &lastdirent->d_off))975975+ if (put_user(f.file->f_pos, &lastdirent->d_off))973976 error = -EFAULT;974977 else975978 error = count - buf.count;976979 }977977- fput_light(file, fput_needed);980980+ fdput(f);978981 return error;979982}980983···10321035asmlinkage long compat_sys_getdents64(unsigned int fd,10331036 struct linux_dirent64 __user * dirent, unsigned int count)10341037{10351035- struct file * file;10381038+ struct fd f;10361039 struct linux_dirent64 __user * lastdirent;10371040 struct compat_getdents_callback64 buf;10381038- int fput_needed;10391041 int error;1040104210411043 if (!access_ok(VERIFY_WRITE, dirent, count))10421044 return -EFAULT;1043104510441044- file = fget_light(fd, &fput_needed);10451045- if (!file)10461046+ f = fdget(fd);10471047+ if (!f.file)10461048 return -EBADF;1047104910481050 buf.current_dir = dirent;···10491053 buf.count = count;10501054 buf.error = 0;1051105510521052- error = vfs_readdir(file, compat_filldir64, &buf);10561056+ error = vfs_readdir(f.file, compat_filldir64, &buf);10531057 if (error >= 0)10541058 error = buf.error;10551059 lastdirent = buf.previous;10561060 if (lastdirent) {10571057- typeof(lastdirent->d_off) d_off = file->f_pos;10611061+ typeof(lastdirent->d_off) d_off = f.file->f_pos;10581062 if (__put_user_unaligned(d_off, &lastdirent->d_off))10591063 error = -EFAULT;10601064 else10611065 error = count - buf.count;10621066 }10631063- fput_light(file, fput_needed);10671067+ fdput(f);10641068 return error;10651069}10661070#endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */···11481152compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,11491153 unsigned long vlen)11501154{11511151- struct file *file;11521152- int fput_needed;11551155+ struct fd f = fdget(fd);11531156 ssize_t ret;11541157 loff_t pos;1155115811561156- file = fget_light(fd, &fput_needed);11571157- if (!file)11591159+ if (!f.file)11581160 return -EBADF;11591159- pos = file->f_pos;11601160- ret = compat_readv(file, vec, vlen, &pos);11611161- file->f_pos = pos;11621162- fput_light(file, fput_needed);11611161+ pos = f.file->f_pos;11621162+ ret = compat_readv(f.file, vec, vlen, &pos);11631163+ f.file->f_pos = pos;11641164+ fdput(f);11631165 return ret;11641166}11651167···11651171compat_sys_preadv64(unsigned long fd, const struct compat_iovec __user *vec,11661172 unsigned long vlen, loff_t pos)11671173{11681168- struct file *file;11691169- int fput_needed;11741174+ struct fd f;11701175 ssize_t ret;1171117611721177 if (pos < 0)11731178 return -EINVAL;11741174- file = fget_light(fd, &fput_needed);11751175- if (!file)11791179+ f = fdget(fd);11801180+ if (!f.file)11761181 return -EBADF;11771182 ret = -ESPIPE;11781178- if (file->f_mode & FMODE_PREAD)11791179- ret = compat_readv(file, vec, vlen, &pos);11801180- fput_light(file, fput_needed);11831183+ if (f.file->f_mode & FMODE_PREAD)11841184+ ret = compat_readv(f.file, vec, vlen, &pos);11851185+ fdput(f);11811186 return ret;11821187}11831188···12141221compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,12151222 unsigned long vlen)12161223{12171217- struct file *file;12181218- int fput_needed;12241224+ struct fd f = fdget(fd);12191225 ssize_t ret;12201226 loff_t pos;1221122712221222- file = fget_light(fd, &fput_needed);12231223- if (!file)12281228+ if (!f.file)12241229 return -EBADF;12251225- pos = file->f_pos;12261226- ret = compat_writev(file, vec, vlen, &pos);12271227- file->f_pos = pos;12281228- fput_light(file, fput_needed);12301230+ pos = f.file->f_pos;12311231+ ret = compat_writev(f.file, vec, vlen, &pos);12321232+ f.file->f_pos = pos;12331233+ fdput(f);12291234 return ret;12301235}12311236···12311240compat_sys_pwritev64(unsigned long fd, const struct compat_iovec __user *vec,12321241 unsigned long vlen, loff_t pos)12331242{12341234- struct file *file;12351235- int fput_needed;12431243+ struct fd f;12361244 ssize_t ret;1237124512381246 if (pos < 0)12391247 return -EINVAL;12401240- file = fget_light(fd, &fput_needed);12411241- if (!file)12481248+ f = fdget(fd);12491249+ if (!f.file)12421250 return -EBADF;12431251 ret = -ESPIPE;12441244- if (file->f_mode & FMODE_PWRITE)12451245- ret = compat_writev(file, vec, vlen, &pos);12461246- fput_light(file, fput_needed);12521252+ if (f.file->f_mode & FMODE_PWRITE)12531253+ ret = compat_writev(f.file, vec, vlen, &pos);12541254+ fdput(f);12471255 return ret;12481256}12491257
+12-15
fs/compat_ioctl.c
···15311531asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,15321532 unsigned long arg)15331533{15341534- struct file *filp;15341534+ struct fd f = fdget(fd);15351535 int error = -EBADF;15361536- int fput_needed;15371537-15381538- filp = fget_light(fd, &fput_needed);15391539- if (!filp)15361536+ if (!f.file)15401537 goto out;1541153815421539 /* RED-PEN how should LSM module know it's handling 32bit? */15431543- error = security_file_ioctl(filp, cmd, arg);15401540+ error = security_file_ioctl(f.file, cmd, arg);15441541 if (error)15451542 goto out_fput;15461543···15571560#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)15581561 case FS_IOC_RESVSP_32:15591562 case FS_IOC_RESVSP64_32:15601560- error = compat_ioctl_preallocate(filp, compat_ptr(arg));15631563+ error = compat_ioctl_preallocate(f.file, compat_ptr(arg));15611564 goto out_fput;15621565#else15631566 case FS_IOC_RESVSP:15641567 case FS_IOC_RESVSP64:15651565- error = ioctl_preallocate(filp, compat_ptr(arg));15681568+ error = ioctl_preallocate(f.file, compat_ptr(arg));15661569 goto out_fput;15671570#endif1568157115691572 case FIBMAP:15701573 case FIGETBSZ:15711574 case FIONREAD:15721572- if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))15751575+ if (S_ISREG(f.file->f_path.dentry->d_inode->i_mode))15731576 break;15741577 /*FALL THROUGH*/1575157815761579 default:15771577- if (filp->f_op && filp->f_op->compat_ioctl) {15781578- error = filp->f_op->compat_ioctl(filp, cmd, arg);15801580+ if (f.file->f_op && f.file->f_op->compat_ioctl) {15811581+ error = f.file->f_op->compat_ioctl(f.file, cmd, arg);15791582 if (error != -ENOIOCTLCMD)15801583 goto out_fput;15811584 }1582158515831583- if (!filp->f_op || !filp->f_op->unlocked_ioctl)15861586+ if (!f.file->f_op || !f.file->f_op->unlocked_ioctl)15841587 goto do_ioctl;15851588 break;15861589 }···15881591 if (compat_ioctl_check_table(XFORM(cmd)))15891592 goto found_handler;1590159315911591- error = do_ioctl_trans(fd, cmd, arg, filp);15941594+ error = do_ioctl_trans(fd, cmd, arg, f.file);15921595 if (error == -ENOIOCTLCMD)15931596 error = -ENOTTY;15941597···15971600 found_handler:15981601 arg = (unsigned long)compat_ptr(arg);15991602 do_ioctl:16001600- error = do_vfs_ioctl(filp, fd, cmd, arg);16031603+ error = do_vfs_ioctl(f.file, fd, cmd, arg);16011604 out_fput:16021602- fput_light(filp, fput_needed);16051605+ fdput(f);16031606 out:16041607 return error;16051608}
+10-15
fs/eventpoll.c
···18091809SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,18101810 int, maxevents, int, timeout)18111811{18121812- int error, fput_needed;18131813- struct file *file;18121812+ int error;18131813+ struct fd f;18141814 struct eventpoll *ep;1815181518161816 /* The maximum number of event must be greater than zero */···18181818 return -EINVAL;1819181918201820 /* Verify that the area passed by the user is writeable */18211821- if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) {18221822- error = -EFAULT;18231823- goto error_return;18241824- }18211821+ if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event)))18221822+ return -EFAULT;1825182318261824 /* Get the "struct file *" for the eventpoll file */18271827- error = -EBADF;18281828- file = fget_light(epfd, &fput_needed);18291829- if (!file)18301830- goto error_return;18251825+ f = fdget(epfd);18261826+ if (!f.file)18271827+ return -EBADF;1831182818321829 /*18331830 * We have to check that the file structure underneath the fd18341831 * the user passed to us _is_ an eventpoll file.18351832 */18361833 error = -EINVAL;18371837- if (!is_file_epoll(file))18341834+ if (!is_file_epoll(f.file))18381835 goto error_fput;1839183618401837 /*18411838 * At this point it is safe to assume that the "private_data" contains18421839 * our own data structure.18431840 */18441844- ep = file->private_data;18411841+ ep = f.file->private_data;1845184218461843 /* Time to fish for events ... */18471844 error = ep_poll(ep, events, maxevents, timeout);1848184518491846error_fput:18501850- fput_light(file, fput_needed);18511851-error_return:18521852-18471847+ fdput(f);18531848 return error;18541849}18551850
+7-7
fs/ext4/ioctl.c
···233233234234 case EXT4_IOC_MOVE_EXT: {235235 struct move_extent me;236236- struct file *donor_filp;237237- int err, fput_needed;236236+ struct fd donor;237237+ int err;238238239239 if (!(filp->f_mode & FMODE_READ) ||240240 !(filp->f_mode & FMODE_WRITE))···245245 return -EFAULT;246246 me.moved_len = 0;247247248248- donor_filp = fget_light(me.donor_fd, &fput_needed);249249- if (!donor_filp)248248+ donor = fdget(me.donor_fd);249249+ if (!donor.file)250250 return -EBADF;251251252252- if (!(donor_filp->f_mode & FMODE_WRITE)) {252252+ if (!(donor.file->f_mode & FMODE_WRITE)) {253253 err = -EBADF;254254 goto mext_out;255255 }···266266 if (err)267267 goto mext_out;268268269269- err = ext4_move_extents(filp, donor_filp, me.orig_start,269269+ err = ext4_move_extents(filp, donor.file, me.orig_start,270270 me.donor_start, me.len, &me.moved_len);271271 mnt_drop_write_file(filp);272272···274274 &me, sizeof(me)))275275 err = -EFAULT;276276mext_out:277277- fput_light(donor_filp, fput_needed);277277+ fdput(donor);278278 return err;279279 }280280
+14-18
fs/fcntl.c
···348348349349SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)350350{ 351351- struct file *filp;352352- int fput_needed;351351+ struct fd f = fdget_raw(fd);353352 long err = -EBADF;354353355355- filp = fget_raw_light(fd, &fput_needed);356356- if (!filp)354354+ if (!f.file)357355 goto out;358356359359- if (unlikely(filp->f_mode & FMODE_PATH)) {357357+ if (unlikely(f.file->f_mode & FMODE_PATH)) {360358 if (!check_fcntl_cmd(cmd))361359 goto out1;362360 }363361364364- err = security_file_fcntl(filp, cmd, arg);362362+ err = security_file_fcntl(f.file, cmd, arg);365363 if (!err)366366- err = do_fcntl(fd, cmd, arg, filp);364364+ err = do_fcntl(fd, cmd, arg, f.file);367365368366out1:369369- fput_light(filp, fput_needed);367367+ fdput(f);370368out:371369 return err;372370}···373375SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,374376 unsigned long, arg)375377{ 376376- struct file * filp;378378+ struct fd f = fdget_raw(fd);377379 long err = -EBADF;378378- int fput_needed;379380380380- filp = fget_raw_light(fd, &fput_needed);381381- if (!filp)381381+ if (!f.file)382382 goto out;383383384384- if (unlikely(filp->f_mode & FMODE_PATH)) {384384+ if (unlikely(f.file->f_mode & FMODE_PATH)) {385385 if (!check_fcntl_cmd(cmd))386386 goto out1;387387 }388388389389- err = security_file_fcntl(filp, cmd, arg);389389+ err = security_file_fcntl(f.file, cmd, arg);390390 if (err)391391 goto out1;392392393393 switch (cmd) {394394 case F_GETLK64:395395- err = fcntl_getlk64(filp, (struct flock64 __user *) arg);395395+ err = fcntl_getlk64(f.file, (struct flock64 __user *) arg);396396 break;397397 case F_SETLK64:398398 case F_SETLKW64:399399- err = fcntl_setlk64(fd, filp, cmd,399399+ err = fcntl_setlk64(fd, f.file, cmd,400400 (struct flock64 __user *) arg);401401 break;402402 default:403403- err = do_fcntl(fd, cmd, arg, filp);403403+ err = do_fcntl(fd, cmd, arg, f.file);404404 break;405405 }406406out1:407407- fput_light(filp, fput_needed);407407+ fdput(f);408408out:409409 return err;410410}
···17971797 struct nameidata *nd, struct file **fp)17981798{17991799 int retval = 0;18001800- int fput_needed;18011801- struct file *file;1802180018031801 nd->last_type = LAST_ROOT; /* if there are only slashes... */18041802 nd->flags = flags | LOOKUP_JUMPED;···18481850 get_fs_pwd(current->fs, &nd->path);18491851 }18501852 } else {18531853+ struct fd f = fdget_raw(dfd);18511854 struct dentry *dentry;1852185518531853- file = fget_raw_light(dfd, &fput_needed);18541854- retval = -EBADF;18551855- if (!file)18561856- goto out_fail;18561856+ if (!f.file)18571857+ return -EBADF;1857185818581858- dentry = file->f_path.dentry;18591859+ dentry = f.file->f_path.dentry;1859186018601861 if (*name) {18611861- retval = -ENOTDIR;18621862- if (!S_ISDIR(dentry->d_inode->i_mode))18631863- goto fput_fail;18621862+ if (!S_ISDIR(dentry->d_inode->i_mode)) {18631863+ fdput(f);18641864+ return -ENOTDIR;18651865+ }1864186618651867 retval = inode_permission(dentry->d_inode, MAY_EXEC);18661866- if (retval)18671867- goto fput_fail;18681868+ if (retval) {18691869+ fdput(f);18701870+ return retval;18711871+ }18681872 }1869187318701870- nd->path = file->f_path;18741874+ nd->path = f.file->f_path;18711875 if (flags & LOOKUP_RCU) {18721872- if (fput_needed)18731873- *fp = file;18761876+ if (f.need_put)18771877+ *fp = f.file;18741878 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);18751879 lock_rcu_walk();18761880 } else {18771877- path_get(&file->f_path);18781878- fput_light(file, fput_needed);18811881+ path_get(&nd->path);18821882+ fdput(f);18791883 }18801884 }1881188518821886 nd->inode = nd->path.dentry->d_inode;18831887 return 0;18841884-18851885-fput_fail:18861886- fput_light(file, fput_needed);18871887-out_fail:18881888- return retval;18891888}1890188918911890static inline int lookup_last(struct nameidata *nd, struct path *path)
+13-15
fs/notify/fanotify/fanotify_user.c
···451451 dfd, filename, flags);452452453453 if (filename == NULL) {454454- struct file *file;455455- int fput_needed;454454+ struct fd f = fdget(dfd);456455457456 ret = -EBADF;458458- file = fget_light(dfd, &fput_needed);459459- if (!file)457457+ if (!f.file)460458 goto out;461459462460 ret = -ENOTDIR;463461 if ((flags & FAN_MARK_ONLYDIR) &&464464- !(S_ISDIR(file->f_path.dentry->d_inode->i_mode))) {465465- fput_light(file, fput_needed);462462+ !(S_ISDIR(f.file->f_path.dentry->d_inode->i_mode))) {463463+ fdput(f);466464 goto out;467465 }468466469469- *path = file->f_path;467467+ *path = f.file->f_path;470468 path_get(path);471471- fput_light(file, fput_needed);469469+ fdput(f);472470 } else {473471 unsigned int lookup_flags = 0;474472···746748 struct inode *inode = NULL;747749 struct vfsmount *mnt = NULL;748750 struct fsnotify_group *group;749749- struct file *filp;751751+ struct fd f;750752 struct path path;751751- int ret, fput_needed;753753+ int ret;752754753755 pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",754756 __func__, fanotify_fd, flags, dfd, pathname, mask);···782784#endif783785 return -EINVAL;784786785785- filp = fget_light(fanotify_fd, &fput_needed);786786- if (unlikely(!filp))787787+ f = fdget(fanotify_fd);788788+ if (unlikely(!f.file))787789 return -EBADF;788790789791 /* verify that this is indeed an fanotify instance */790792 ret = -EINVAL;791791- if (unlikely(filp->f_op != &fanotify_fops))793793+ if (unlikely(f.file->f_op != &fanotify_fops))792794 goto fput_and_out;793793- group = filp->private_data;795795+ group = f.file->private_data;794796795797 /*796798 * group->priority == FS_PRIO_0 == FAN_CLASS_NOTIF. These are not···837839838840 path_put(&path);839841fput_and_out:840840- fput_light(filp, fput_needed);842842+ fdput(f);841843 return ret;842844}843845
+14-14
fs/notify/inotify/inotify_user.c
···757757 struct fsnotify_group *group;758758 struct inode *inode;759759 struct path path;760760- struct file *filp;761761- int ret, fput_needed;760760+ struct fd f;761761+ int ret;762762 unsigned flags = 0;763763764764- filp = fget_light(fd, &fput_needed);765765- if (unlikely(!filp))764764+ f = fdget(fd);765765+ if (unlikely(!f.file))766766 return -EBADF;767767768768 /* verify that this is indeed an inotify instance */769769- if (unlikely(filp->f_op != &inotify_fops)) {769769+ if (unlikely(f.file->f_op != &inotify_fops)) {770770 ret = -EINVAL;771771 goto fput_and_out;772772 }···782782783783 /* inode held in place by reference to path; group by fget on fd */784784 inode = path.dentry->d_inode;785785- group = filp->private_data;785785+ group = f.file->private_data;786786787787 /* create/update an inode mark */788788 ret = inotify_update_watch(group, inode, mask);789789 path_put(&path);790790fput_and_out:791791- fput_light(filp, fput_needed);791791+ fdput(f);792792 return ret;793793}794794···796796{797797 struct fsnotify_group *group;798798 struct inotify_inode_mark *i_mark;799799- struct file *filp;800800- int ret = 0, fput_needed;799799+ struct fd f;800800+ int ret = 0;801801802802- filp = fget_light(fd, &fput_needed);803803- if (unlikely(!filp))802802+ f = fdget(fd);803803+ if (unlikely(!f.file))804804 return -EBADF;805805806806 /* verify that this is indeed an inotify instance */807807 ret = -EINVAL;808808- if (unlikely(filp->f_op != &inotify_fops))808808+ if (unlikely(f.file->f_op != &inotify_fops))809809 goto out;810810811811- group = filp->private_data;811811+ group = f.file->private_data;812812813813 ret = -EINVAL;814814 i_mark = inotify_idr_find(group, wd);···823823 fsnotify_put_mark(&i_mark->fsn_mark);824824825825out:826826- fput_light(filp, fput_needed);826826+ fdput(f);827827 return ret;828828}829829
+19-20
fs/ocfs2/cluster/heartbeat.c
···17461746 long fd;17471747 int sectsize;17481748 char *p = (char *)page;17491749- struct file *filp = NULL;17501750- struct inode *inode = NULL;17491749+ struct fd f;17501750+ struct inode *inode;17511751 ssize_t ret = -EINVAL;17521752 int live_threshold;17531753- int fput_needed;1754175317551754 if (reg->hr_bdev)17561755 goto out;···17661767 if (fd < 0 || fd >= INT_MAX)17671768 goto out;1768176917691769- filp = fget_light(fd, &fput_needed);17701770- if (filp == NULL)17701770+ f = fdget(fd);17711771+ if (f.file == NULL)17711772 goto out;1772177317731774 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||17741775 reg->hr_block_bytes == 0)17751775- goto out;17761776+ goto out2;1776177717771777- inode = igrab(filp->f_mapping->host);17781778+ inode = igrab(f.file->f_mapping->host);17781779 if (inode == NULL)17791779- goto out;17801780+ goto out2;1780178117811782 if (!S_ISBLK(inode->i_mode))17821782- goto out;17831783+ goto out3;1783178417841784- reg->hr_bdev = I_BDEV(filp->f_mapping->host);17851785+ reg->hr_bdev = I_BDEV(f.file->f_mapping->host);17851786 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, NULL);17861787 if (ret) {17871788 reg->hr_bdev = NULL;17881788- goto out;17891789+ goto out3;17891790 }17901791 inode = NULL;17911792···17971798 "blocksize %u incorrect for device, expected %d",17981799 reg->hr_block_bytes, sectsize);17991800 ret = -EINVAL;18001800- goto out;18011801+ goto out3;18011802 }1802180318031804 o2hb_init_region_params(reg);···18111812 ret = o2hb_map_slot_data(reg);18121813 if (ret) {18131814 mlog_errno(ret);18141814- goto out;18151815+ goto out3;18151816 }1816181718171818 ret = o2hb_populate_slot_data(reg);18181819 if (ret) {18191820 mlog_errno(ret);18201820- goto out;18211821+ goto out3;18211822 }1822182318231824 INIT_DELAYED_WORK(®->hr_write_timeout_work, o2hb_write_timeout);···18471848 if (IS_ERR(hb_task)) {18481849 ret = PTR_ERR(hb_task);18491850 mlog_errno(ret);18501850- goto out;18511851+ goto out3;18511852 }1852185318531854 spin_lock(&o2hb_live_lock);···1863186418641865 if (reg->hr_aborted_start) {18651866 ret = -EIO;18661866- goto out;18671867+ goto out3;18671868 }1868186918691870 /* Ok, we were woken. Make sure it wasn't by drop_item() */···18821883 printk(KERN_NOTICE "o2hb: Heartbeat started on region %s (%s)\n",18831884 config_item_name(®->hr_item), reg->hr_dev_name);1884188518861886+out3:18871887+ iput(inode);18881888+out2:18891889+ fdput(f);18851890out:18861886- if (filp)18871887- fput_light(filp, fput_needed);18881888- if (inode)18891889- iput(inode);18901891 if (ret < 0) {18911892 if (reg->hr_bdev) {18921893 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
+30-34
fs/open.c
···134134{135135 struct inode *inode;136136 struct dentry *dentry;137137- struct file *file;138138- int error, fput_needed;137137+ struct fd f;138138+ int error;139139140140 error = -EINVAL;141141 if (length < 0)142142 goto out;143143 error = -EBADF;144144- file = fget_light(fd, &fput_needed);145145- if (!file)144144+ f = fdget(fd);145145+ if (!f.file)146146 goto out;147147148148 /* explicitly opened as large or we are on 64-bit box */149149- if (file->f_flags & O_LARGEFILE)149149+ if (f.file->f_flags & O_LARGEFILE)150150 small = 0;151151152152- dentry = file->f_path.dentry;152152+ dentry = f.file->f_path.dentry;153153 inode = dentry->d_inode;154154 error = -EINVAL;155155- if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))155155+ if (!S_ISREG(inode->i_mode) || !(f.file->f_mode & FMODE_WRITE))156156 goto out_putf;157157158158 error = -EINVAL;···165165 goto out_putf;166166167167 sb_start_write(inode->i_sb);168168- error = locks_verify_truncate(inode, file, length);168168+ error = locks_verify_truncate(inode, f.file, length);169169 if (!error)170170- error = security_path_truncate(&file->f_path);170170+ error = security_path_truncate(&f.file->f_path);171171 if (!error)172172- error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);172172+ error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);173173 sb_end_write(inode->i_sb);174174out_putf:175175- fput_light(file, fput_needed);175175+ fdput(f);176176out:177177 return error;178178}···276276277277SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len)278278{279279- struct file *file;280280- int error = -EBADF, fput_needed;279279+ struct fd f = fdget(fd);280280+ int error = -EBADF;281281282282- file = fget_light(fd, &fput_needed);283283- if (file) {284284- error = do_fallocate(file, mode, offset, len);285285- fput_light(file, fput_needed);282282+ if (f.file) {283283+ error = do_fallocate(f.file, mode, offset, len);284284+ fdput(f);286285 }287287-288286 return error;289287}290288···398400399401SYSCALL_DEFINE1(fchdir, unsigned int, fd)400402{401401- struct file *file;403403+ struct fd f = fdget_raw(fd);402404 struct inode *inode;403403- int error, fput_needed;405405+ int error = -EBADF;404406405407 error = -EBADF;406406- file = fget_raw_light(fd, &fput_needed);407407- if (!file)408408+ if (!f.file)408409 goto out;409410410410- inode = file->f_path.dentry->d_inode;411411+ inode = f.file->f_path.dentry->d_inode;411412412413 error = -ENOTDIR;413414 if (!S_ISDIR(inode->i_mode))···414417415418 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);416419 if (!error)417417- set_fs_pwd(current->fs, &file->f_path);420420+ set_fs_pwd(current->fs, &f.file->f_path);418421out_putf:419419- fput_light(file, fput_needed);422422+ fdput(f);420423out:421424 return error;422425}···579582580583SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)581584{582582- struct file *file;583583- int error = -EBADF, fput_needed;585585+ struct fd f = fdget(fd);586586+ int error = -EBADF;584587585585- file = fget_light(fd, &fput_needed);586586- if (!file)588588+ if (!f.file)587589 goto out;588590589589- error = mnt_want_write_file(file);591591+ error = mnt_want_write_file(f.file);590592 if (error)591593 goto out_fput;592592- audit_inode(NULL, file->f_path.dentry);593593- error = chown_common(&file->f_path, user, group);594594- mnt_drop_write_file(file);594594+ audit_inode(NULL, f.file->f_path.dentry);595595+ error = chown_common(&f.file->f_path, user, group);596596+ mnt_drop_write_file(f.file);595597out_fput:596596- fput_light(file, fput_needed);598598+ fdput(f);597599out:598600 return error;599601}
+77-99
fs/read_write.c
···232232SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, origin)233233{234234 off_t retval;235235- struct file * file;236236- int fput_needed;237237-238238- retval = -EBADF;239239- file = fget_light(fd, &fput_needed);240240- if (!file)241241- goto bad;235235+ struct fd f = fdget(fd);236236+ if (!f.file)237237+ return -EBADF;242238243239 retval = -EINVAL;244240 if (origin <= SEEK_MAX) {245245- loff_t res = vfs_llseek(file, offset, origin);241241+ loff_t res = vfs_llseek(f.file, offset, origin);246242 retval = res;247243 if (res != (loff_t)retval)248244 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */249245 }250250- fput_light(file, fput_needed);251251-bad:246246+ fdput(f);252247 return retval;253248}254249···253258 unsigned int, origin)254259{255260 int retval;256256- struct file * file;261261+ struct fd f = fdget(fd);257262 loff_t offset;258258- int fput_needed;259263260260- retval = -EBADF;261261- file = fget_light(fd, &fput_needed);262262- if (!file)263263- goto bad;264264+ if (!f.file)265265+ return -EBADF;264266265267 retval = -EINVAL;266268 if (origin > SEEK_MAX)267269 goto out_putf;268270269269- offset = vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low,271271+ offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,270272 origin);271273272274 retval = (int)offset;···273281 retval = 0;274282 }275283out_putf:276276- fput_light(file, fput_needed);277277-bad:284284+ fdput(f);278285 return retval;279286}280287#endif···452461453462SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)454463{455455- struct file *file;464464+ struct fd f = fdget(fd);456465 ssize_t ret = -EBADF;457457- int fput_needed;458466459459- file = fget_light(fd, &fput_needed);460460- if (file) {461461- loff_t pos = file_pos_read(file);462462- ret = vfs_read(file, buf, count, &pos);463463- file_pos_write(file, pos);464464- fput_light(file, fput_needed);467467+ if (f.file) {468468+ loff_t pos = file_pos_read(f.file);469469+ ret = vfs_read(f.file, buf, count, &pos);470470+ file_pos_write(f.file, pos);471471+ fdput(f);465472 }466466-467473 return ret;468474}469475470476SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,471477 size_t, count)472478{473473- struct file *file;479479+ struct fd f = fdget(fd);474480 ssize_t ret = -EBADF;475475- int fput_needed;476481477477- file = fget_light(fd, &fput_needed);478478- if (file) {479479- loff_t pos = file_pos_read(file);480480- ret = vfs_write(file, buf, count, &pos);481481- file_pos_write(file, pos);482482- fput_light(file, fput_needed);482482+ if (f.file) {483483+ loff_t pos = file_pos_read(f.file);484484+ ret = vfs_write(f.file, buf, count, &pos);485485+ file_pos_write(f.file, pos);486486+ fdput(f);483487 }484488485489 return ret;···483497SYSCALL_DEFINE(pread64)(unsigned int fd, char __user *buf,484498 size_t count, loff_t pos)485499{486486- struct file *file;500500+ struct fd f;487501 ssize_t ret = -EBADF;488488- int fput_needed;489502490503 if (pos < 0)491504 return -EINVAL;492505493493- file = fget_light(fd, &fput_needed);494494- if (file) {506506+ f = fdget(fd);507507+ if (f.file) {495508 ret = -ESPIPE;496496- if (file->f_mode & FMODE_PREAD)497497- ret = vfs_read(file, buf, count, &pos);498498- fput_light(file, fput_needed);509509+ if (f.file->f_mode & FMODE_PREAD)510510+ ret = vfs_read(f.file, buf, count, &pos);511511+ fdput(f);499512 }500513501514 return ret;···511526SYSCALL_DEFINE(pwrite64)(unsigned int fd, const char __user *buf,512527 size_t count, loff_t pos)513528{514514- struct file *file;529529+ struct fd f;515530 ssize_t ret = -EBADF;516516- int fput_needed;517531518532 if (pos < 0)519533 return -EINVAL;520534521521- file = fget_light(fd, &fput_needed);522522- if (file) {535535+ f = fdget(fd);536536+ if (f.file) {523537 ret = -ESPIPE;524524- if (file->f_mode & FMODE_PWRITE) 525525- ret = vfs_write(file, buf, count, &pos);526526- fput_light(file, fput_needed);538538+ if (f.file->f_mode & FMODE_PWRITE) 539539+ ret = vfs_write(f.file, buf, count, &pos);540540+ fdput(f);527541 }528542529543 return ret;···773789SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,774790 unsigned long, vlen)775791{776776- struct file *file;792792+ struct fd f = fdget(fd);777793 ssize_t ret = -EBADF;778778- int fput_needed;779794780780- file = fget_light(fd, &fput_needed);781781- if (file) {782782- loff_t pos = file_pos_read(file);783783- ret = vfs_readv(file, vec, vlen, &pos);784784- file_pos_write(file, pos);785785- fput_light(file, fput_needed);795795+ if (f.file) {796796+ loff_t pos = file_pos_read(f.file);797797+ ret = vfs_readv(f.file, vec, vlen, &pos);798798+ file_pos_write(f.file, pos);799799+ fdput(f);786800 }787801788802 if (ret > 0)···792810SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,793811 unsigned long, vlen)794812{795795- struct file *file;813813+ struct fd f = fdget(fd);796814 ssize_t ret = -EBADF;797797- int fput_needed;798815799799- file = fget_light(fd, &fput_needed);800800- if (file) {801801- loff_t pos = file_pos_read(file);802802- ret = vfs_writev(file, vec, vlen, &pos);803803- file_pos_write(file, pos);804804- fput_light(file, fput_needed);816816+ if (f.file) {817817+ loff_t pos = file_pos_read(f.file);818818+ ret = vfs_writev(f.file, vec, vlen, &pos);819819+ file_pos_write(f.file, pos);820820+ fdput(f);805821 }806822807823 if (ret > 0)···818838 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)819839{820840 loff_t pos = pos_from_hilo(pos_h, pos_l);821821- struct file *file;841841+ struct fd f;822842 ssize_t ret = -EBADF;823823- int fput_needed;824843825844 if (pos < 0)826845 return -EINVAL;827846828828- file = fget_light(fd, &fput_needed);829829- if (file) {847847+ f = fdget(fd);848848+ if (f.file) {830849 ret = -ESPIPE;831831- if (file->f_mode & FMODE_PREAD)832832- ret = vfs_readv(file, vec, vlen, &pos);833833- fput_light(file, fput_needed);850850+ if (f.file->f_mode & FMODE_PREAD)851851+ ret = vfs_readv(f.file, vec, vlen, &pos);852852+ fdput(f);834853 }835854836855 if (ret > 0)···842863 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)843864{844865 loff_t pos = pos_from_hilo(pos_h, pos_l);845845- struct file *file;866866+ struct fd f;846867 ssize_t ret = -EBADF;847847- int fput_needed;848868849869 if (pos < 0)850870 return -EINVAL;851871852852- file = fget_light(fd, &fput_needed);853853- if (file) {872872+ f = fdget(fd);873873+ if (f.file) {854874 ret = -ESPIPE;855855- if (file->f_mode & FMODE_PWRITE)856856- ret = vfs_writev(file, vec, vlen, &pos);857857- fput_light(file, fput_needed);875875+ if (f.file->f_mode & FMODE_PWRITE)876876+ ret = vfs_writev(f.file, vec, vlen, &pos);877877+ fdput(f);858878 }859879860880 if (ret > 0)···865887static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,866888 size_t count, loff_t max)867889{868868- struct file * in_file, * out_file;869869- struct inode * in_inode, * out_inode;890890+ struct fd in, out;891891+ struct inode *in_inode, *out_inode;870892 loff_t pos;871893 ssize_t retval;872872- int fput_needed_in, fput_needed_out, fl;894894+ int fl;873895874896 /*875897 * Get input file, and verify that it is ok..876898 */877899 retval = -EBADF;878878- in_file = fget_light(in_fd, &fput_needed_in);879879- if (!in_file)900900+ in = fdget(in_fd);901901+ if (!in.file)880902 goto out;881881- if (!(in_file->f_mode & FMODE_READ))903903+ if (!(in.file->f_mode & FMODE_READ))882904 goto fput_in;883905 retval = -ESPIPE;884906 if (!ppos)885885- ppos = &in_file->f_pos;907907+ ppos = &in.file->f_pos;886908 else887887- if (!(in_file->f_mode & FMODE_PREAD))909909+ if (!(in.file->f_mode & FMODE_PREAD))888910 goto fput_in;889889- retval = rw_verify_area(READ, in_file, ppos, count);911911+ retval = rw_verify_area(READ, in.file, ppos, count);890912 if (retval < 0)891913 goto fput_in;892914 count = retval;···895917 * Get output file, and verify that it is ok..896918 */897919 retval = -EBADF;898898- out_file = fget_light(out_fd, &fput_needed_out);899899- if (!out_file)920920+ out = fdget(out_fd);921921+ if (!out.file)900922 goto fput_in;901901- if (!(out_file->f_mode & FMODE_WRITE))923923+ if (!(out.file->f_mode & FMODE_WRITE))902924 goto fput_out;903925 retval = -EINVAL;904904- in_inode = in_file->f_path.dentry->d_inode;905905- out_inode = out_file->f_path.dentry->d_inode;906906- retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count);926926+ in_inode = in.file->f_path.dentry->d_inode;927927+ out_inode = out.file->f_path.dentry->d_inode;928928+ retval = rw_verify_area(WRITE, out.file, &out.file->f_pos, count);907929 if (retval < 0)908930 goto fput_out;909931 count = retval;···927949 * and the application is arguably buggy if it doesn't expect928950 * EAGAIN on a non-blocking file descriptor.929951 */930930- if (in_file->f_flags & O_NONBLOCK)952952+ if (in.file->f_flags & O_NONBLOCK)931953 fl = SPLICE_F_NONBLOCK;932954#endif933933- retval = do_splice_direct(in_file, ppos, out_file, count, fl);955955+ retval = do_splice_direct(in.file, ppos, out.file, count, fl);934956935957 if (retval > 0) {936958 add_rchar(current, retval);···943965 retval = -EOVERFLOW;944966945967fput_out:946946- fput_light(out_file, fput_needed_out);968968+ fdput(out);947969fput_in:948948- fput_light(in_file, fput_needed_in);970970+ fdput(in);949971out:950972 return retval;951973}
···4848 xfs_swapext_t *sxp)4949{5050 xfs_inode_t *ip, *tip;5151- struct file *file, *tmp_file;5252- int error = 0, fput_needed, fput_needed_tmp;5151+ struct fd f, tmp;5252+ int error = 0;53535454 /* Pull information for the target fd */5555- file = fget_light((int)sxp->sx_fdtarget, &fput_needed);5656- if (!file) {5555+ f = fdget((int)sxp->sx_fdtarget);5656+ if (!f.file) {5757 error = XFS_ERROR(EINVAL);5858 goto out;5959 }60606161- if (!(file->f_mode & FMODE_WRITE) ||6262- !(file->f_mode & FMODE_READ) ||6363- (file->f_flags & O_APPEND)) {6161+ if (!(f.file->f_mode & FMODE_WRITE) ||6262+ !(f.file->f_mode & FMODE_READ) ||6363+ (f.file->f_flags & O_APPEND)) {6464 error = XFS_ERROR(EBADF);6565 goto out_put_file;6666 }67676868- tmp_file = fget_light((int)sxp->sx_fdtmp, &fput_needed_tmp);6969- if (!tmp_file) {6868+ tmp = fdget((int)sxp->sx_fdtmp);6969+ if (!tmp.file) {7070 error = XFS_ERROR(EINVAL);7171 goto out_put_file;7272 }73737474- if (!(tmp_file->f_mode & FMODE_WRITE) ||7575- !(tmp_file->f_mode & FMODE_READ) ||7676- (tmp_file->f_flags & O_APPEND)) {7474+ if (!(tmp.file->f_mode & FMODE_WRITE) ||7575+ !(tmp.file->f_mode & FMODE_READ) ||7676+ (tmp.file->f_flags & O_APPEND)) {7777 error = XFS_ERROR(EBADF);7878 goto out_put_tmp_file;7979 }80808181- if (IS_SWAPFILE(file->f_path.dentry->d_inode) ||8282- IS_SWAPFILE(tmp_file->f_path.dentry->d_inode)) {8181+ if (IS_SWAPFILE(f.file->f_path.dentry->d_inode) ||8282+ IS_SWAPFILE(tmp.file->f_path.dentry->d_inode)) {8383 error = XFS_ERROR(EINVAL);8484 goto out_put_tmp_file;8585 }86868787- ip = XFS_I(file->f_path.dentry->d_inode);8888- tip = XFS_I(tmp_file->f_path.dentry->d_inode);8787+ ip = XFS_I(f.file->f_path.dentry->d_inode);8888+ tip = XFS_I(tmp.file->f_path.dentry->d_inode);89899090 if (ip->i_mount != tip->i_mount) {9191 error = XFS_ERROR(EINVAL);···105105 error = xfs_swap_extents(ip, tip, sxp);106106107107 out_put_tmp_file:108108- fput_light(tmp_file, fput_needed_tmp);108108+ fdput(tmp);109109 out_put_file:110110- fput_light(file, fput_needed);110110+ fdput(f);111111 out:112112 return error;113113}
+6-6
fs/xfs/xfs_ioctl.c
···7070 int hsize;7171 xfs_handle_t handle;7272 struct inode *inode;7373- struct file *file = NULL;7373+ struct fd f;7474 struct path path;7575- int error, fput_needed;7575+ int error;7676 struct xfs_inode *ip;77777878 if (cmd == XFS_IOC_FD_TO_HANDLE) {7979- file = fget_light(hreq->fd, &fput_needed);8080- if (!file)7979+ f = fdget(hreq->fd);8080+ if (!f.file)8181 return -EBADF;8282- inode = file->f_path.dentry->d_inode;8282+ inode = f.file->f_path.dentry->d_inode;8383 } else {8484 error = user_lpath((const char __user *)hreq->path, &path);8585 if (error)···134134135135 out_put:136136 if (cmd == XFS_IOC_FD_TO_HANDLE)137137- fput_light(file, fput_needed);137137+ fdput(f);138138 else139139 path_put(&path);140140 return error;
+3-2
include/linux/file.h
···4747 return (struct fd){f,b};4848}49495050+extern struct file *fget_raw(unsigned int fd);5151+extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);5252+5053static inline struct fd fdget_raw(unsigned int fd)5154{5255 int b;···5754 return (struct fd){f,b};5855}59566060-extern struct file *fget_raw(unsigned int fd);6161-extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);6257extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);6358extern int replace_fd(unsigned fd, struct file *file, unsigned flags);6459extern void set_close_on_exec(unsigned int fd, int flag);
+41-43
ipc/mqueue.c
···944944 size_t, msg_len, unsigned int, msg_prio,945945 const struct timespec __user *, u_abs_timeout)946946{947947- struct file *filp;947947+ struct fd f;948948 struct inode *inode;949949 struct ext_wait_queue wait;950950 struct ext_wait_queue *receiver;···953953 ktime_t expires, *timeout = NULL;954954 struct timespec ts;955955 struct posix_msg_tree_node *new_leaf = NULL;956956- int ret = 0, fput_needed;956956+ int ret = 0;957957958958 if (u_abs_timeout) {959959 int res = prepare_timeout(u_abs_timeout, &expires, &ts);···967967968968 audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL);969969970970- filp = fget_light(mqdes, &fput_needed);971971- if (unlikely(!filp)) {970970+ f = fdget(mqdes);971971+ if (unlikely(!f.file)) {972972 ret = -EBADF;973973 goto out;974974 }975975976976- inode = filp->f_path.dentry->d_inode;977977- if (unlikely(filp->f_op != &mqueue_file_operations)) {976976+ inode = f.file->f_path.dentry->d_inode;977977+ if (unlikely(f.file->f_op != &mqueue_file_operations)) {978978 ret = -EBADF;979979 goto out_fput;980980 }981981 info = MQUEUE_I(inode);982982- audit_inode(NULL, filp->f_path.dentry);982982+ audit_inode(NULL, f.file->f_path.dentry);983983984984- if (unlikely(!(filp->f_mode & FMODE_WRITE))) {984984+ if (unlikely(!(f.file->f_mode & FMODE_WRITE))) {985985 ret = -EBADF;986986 goto out_fput;987987 }···10231023 }1024102410251025 if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {10261026- if (filp->f_flags & O_NONBLOCK) {10261026+ if (f.file->f_flags & O_NONBLOCK) {10271027 ret = -EAGAIN;10281028 } else {10291029 wait.task = current;···10561056 if (ret)10571057 free_msg(msg_ptr);10581058out_fput:10591059- fput_light(filp, fput_needed);10591059+ fdput(f);10601060out:10611061 return ret;10621062}···10671067{10681068 ssize_t ret;10691069 struct msg_msg *msg_ptr;10701070- struct file *filp;10701070+ struct fd f;10711071 struct inode *inode;10721072 struct mqueue_inode_info *info;10731073 struct ext_wait_queue wait;10741074 ktime_t expires, *timeout = NULL;10751075 struct timespec ts;10761076 struct posix_msg_tree_node *new_leaf = NULL;10771077- int fput_needed;1078107710791078 if (u_abs_timeout) {10801079 int res = prepare_timeout(u_abs_timeout, &expires, &ts);···1084108510851086 audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL);1086108710871087- filp = fget_light(mqdes, &fput_needed);10881088- if (unlikely(!filp)) {10881088+ f = fdget(mqdes);10891089+ if (unlikely(!f.file)) {10891090 ret = -EBADF;10901091 goto out;10911092 }1092109310931093- inode = filp->f_path.dentry->d_inode;10941094- if (unlikely(filp->f_op != &mqueue_file_operations)) {10941094+ inode = f.file->f_path.dentry->d_inode;10951095+ if (unlikely(f.file->f_op != &mqueue_file_operations)) {10951096 ret = -EBADF;10961097 goto out_fput;10971098 }10981099 info = MQUEUE_I(inode);10991099- audit_inode(NULL, filp->f_path.dentry);11001100+ audit_inode(NULL, f.file->f_path.dentry);1100110111011101- if (unlikely(!(filp->f_mode & FMODE_READ))) {11021102+ if (unlikely(!(f.file->f_mode & FMODE_READ))) {11021103 ret = -EBADF;11031104 goto out_fput;11041105 }···11301131 }1131113211321133 if (info->attr.mq_curmsgs == 0) {11331133- if (filp->f_flags & O_NONBLOCK) {11341134+ if (f.file->f_flags & O_NONBLOCK) {11341135 spin_unlock(&info->lock);11351136 ret = -EAGAIN;11361137 } else {···11601161 free_msg(msg_ptr);11611162 }11621163out_fput:11631163- fput_light(filp, fput_needed);11641164+ fdput(f);11641165out:11651166 return ret;11661167}···11731174SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,11741175 const struct sigevent __user *, u_notification)11751176{11761176- int ret, fput_needed;11771177- struct file *filp;11771177+ int ret;11781178+ struct fd f;11781179 struct sock *sock;11791180 struct inode *inode;11801181 struct sigevent notification;···12201221 skb_put(nc, NOTIFY_COOKIE_LEN);12211222 /* and attach it to the socket */12221223retry:12231223- filp = fget_light(notification.sigev_signo, &fput_needed);12241224- if (!filp) {12241224+ f = fdget(notification.sigev_signo);12251225+ if (!f.file) {12251226 ret = -EBADF;12261227 goto out;12271228 }12281228- sock = netlink_getsockbyfilp(filp);12291229- fput_light(filp, fput_needed);12291229+ sock = netlink_getsockbyfilp(f.file);12301230+ fdput(f);12301231 if (IS_ERR(sock)) {12311232 ret = PTR_ERR(sock);12321233 sock = NULL;···12451246 }12461247 }1247124812481248- filp = fget_light(mqdes, &fput_needed);12491249- if (!filp) {12491249+ f = fdget(mqdes);12501250+ if (!f.file) {12501251 ret = -EBADF;12511252 goto out;12521253 }1253125412541254- inode = filp->f_path.dentry->d_inode;12551255- if (unlikely(filp->f_op != &mqueue_file_operations)) {12551255+ inode = f.file->f_path.dentry->d_inode;12561256+ if (unlikely(f.file->f_op != &mqueue_file_operations)) {12561257 ret = -EBADF;12571258 goto out_fput;12581259 }···12921293 }12931294 spin_unlock(&info->lock);12941295out_fput:12951295- fput_light(filp, fput_needed);12961296+ fdput(f);12961297out:12971298 if (sock) {12981299 netlink_detachskb(sock, nc);···13081309{13091310 int ret;13101311 struct mq_attr mqstat, omqstat;13111311- int fput_needed;13121312- struct file *filp;13121312+ struct fd f;13131313 struct inode *inode;13141314 struct mqueue_inode_info *info;13151315···13191321 return -EINVAL;13201322 }1321132313221322- filp = fget_light(mqdes, &fput_needed);13231323- if (!filp) {13241324+ f = fdget(mqdes);13251325+ if (!f.file) {13241326 ret = -EBADF;13251327 goto out;13261328 }1327132913281328- inode = filp->f_path.dentry->d_inode;13291329- if (unlikely(filp->f_op != &mqueue_file_operations)) {13301330+ inode = f.file->f_path.dentry->d_inode;13311331+ if (unlikely(f.file->f_op != &mqueue_file_operations)) {13301332 ret = -EBADF;13311333 goto out_fput;13321334 }···13351337 spin_lock(&info->lock);1336133813371339 omqstat = info->attr;13381338- omqstat.mq_flags = filp->f_flags & O_NONBLOCK;13401340+ omqstat.mq_flags = f.file->f_flags & O_NONBLOCK;13391341 if (u_mqstat) {13401342 audit_mq_getsetattr(mqdes, &mqstat);13411341- spin_lock(&filp->f_lock);13431343+ spin_lock(&f.file->f_lock);13421344 if (mqstat.mq_flags & O_NONBLOCK)13431343- filp->f_flags |= O_NONBLOCK;13451345+ f.file->f_flags |= O_NONBLOCK;13441346 else13451345- filp->f_flags &= ~O_NONBLOCK;13461346- spin_unlock(&filp->f_lock);13471347+ f.file->f_flags &= ~O_NONBLOCK;13481348+ spin_unlock(&f.file->f_lock);1347134913481350 inode->i_atime = inode->i_ctime = CURRENT_TIME;13491351 }···13561358 ret = -EFAULT;1357135913581360out_fput:13591359- fput_light(filp, fput_needed);13611361+ fdput(f);13601362out:13611363 return ret;13621364}
+30-40
kernel/events/core.c
···467467{468468 struct perf_cgroup *cgrp;469469 struct cgroup_subsys_state *css;470470- struct file *file;471471- int ret = 0, fput_needed;470470+ struct fd f = fdget(fd);471471+ int ret = 0;472472473473- file = fget_light(fd, &fput_needed);474474- if (!file)473473+ if (!f.file)475474 return -EBADF;476475477477- css = cgroup_css_from_dir(file, perf_subsys_id);476476+ css = cgroup_css_from_dir(f.file, perf_subsys_id);478477 if (IS_ERR(css)) {479478 ret = PTR_ERR(css);480479 goto out;···499500 ret = -EINVAL;500501 }501502out:502502- fput_light(file, fput_needed);503503+ fdput(f);503504 return ret;504505}505506···3232323332333234static const struct file_operations perf_fops;3234323532353235-static struct file *perf_fget_light(int fd, int *fput_needed)32363236+static inline int perf_fget_light(int fd, struct fd *p)32363237{32373237- struct file *file;32383238+ struct fd f = fdget(fd);32393239+ if (!f.file)32403240+ return -EBADF;3238324132393239- file = fget_light(fd, fput_needed);32403240- if (!file)32413241- return ERR_PTR(-EBADF);32423242-32433243- if (file->f_op != &perf_fops) {32443244- fput_light(file, *fput_needed);32453245- *fput_needed = 0;32463246- return ERR_PTR(-EBADF);32423242+ if (f.file->f_op != &perf_fops) {32433243+ fdput(f);32443244+ return -EBADF;32473245 }32483248-32493249- return file;32463246+ *p = f;32473247+ return 0;32503248}3251324932523250static int perf_event_set_output(struct perf_event *event,···3275327932763280 case PERF_EVENT_IOC_SET_OUTPUT:32773281 {32783278- struct file *output_file = NULL;32793279- struct perf_event *output_event = NULL;32803280- int fput_needed = 0;32813282 int ret;32823282-32833283 if (arg != -1) {32843284- output_file = perf_fget_light(arg, &fput_needed);32853285- if (IS_ERR(output_file))32863286- return PTR_ERR(output_file);32873287- output_event = output_file->private_data;32843284+ struct perf_event *output_event;32853285+ struct fd output;32863286+ ret = perf_fget_light(arg, &output);32873287+ if (ret)32883288+ return ret;32893289+ output_event = output.file->private_data;32903290+ ret = perf_event_set_output(event, output_event);32913291+ fdput(output);32923292+ } else {32933293+ ret = perf_event_set_output(event, NULL);32883294 }32893289-32903290- ret = perf_event_set_output(event, output_event);32913291- if (output_event)32923292- fput_light(output_file, fput_needed);32933293-32943295 return ret;32953296 }32963297···62226229 struct perf_event_attr attr;62236230 struct perf_event_context *ctx;62246231 struct file *event_file = NULL;62256225- struct file *group_file = NULL;62326232+ struct fd group = {NULL, 0};62266233 struct task_struct *task = NULL;62276234 struct pmu *pmu;62286235 int event_fd;62296236 int move_group = 0;62306230- int fput_needed = 0;62316237 int err;6232623862336239 /* for future expandability... */···62616269 return event_fd;6262627062636271 if (group_fd != -1) {62646264- group_file = perf_fget_light(group_fd, &fput_needed);62656265- if (IS_ERR(group_file)) {62666266- err = PTR_ERR(group_file);62726272+ err = perf_fget_light(group_fd, &group);62736273+ if (err)62676274 goto err_fd;62686268- }62696269- group_leader = group_file->private_data;62756275+ group_leader = group.file->private_data;62706276 if (flags & PERF_FLAG_FD_OUTPUT)62716277 output_event = group_leader;62726278 if (flags & PERF_FLAG_FD_NO_GROUP)···64406450 * of the group leader will find the pointer to itself in64416451 * perf_group_detach().64426452 */64436443- fput_light(group_file, fput_needed);64536453+ fdput(group);64446454 fd_install(event_fd, event_file);64456455 return event_fd;64466456···64546464 if (task)64556465 put_task_struct(task);64566466err_group_fd:64576457- fput_light(group_file, fput_needed);64676467+ fdput(group);64586468err_fd:64596469 put_unused_fd(event_fd);64606470 return err;
+8-8
kernel/sys.c
···17881788#ifdef CONFIG_CHECKPOINT_RESTORE17891789static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)17901790{17911791- struct file *exe_file;17911791+ struct fd exe;17921792 struct dentry *dentry;17931793- int err, fput_needed;17931793+ int err;1794179417951795- exe_file = fget_light(fd, &fput_needed);17961796- if (!exe_file)17951795+ exe = fdget(fd);17961796+ if (!exe.file)17971797 return -EBADF;1798179817991799- dentry = exe_file->f_path.dentry;17991799+ dentry = exe.file->f_path.dentry;1800180018011801 /*18021802 * Because the original mm->exe_file points to executable file, make···18051805 */18061806 err = -EACCES;18071807 if (!S_ISREG(dentry->d_inode->i_mode) ||18081808- exe_file->f_path.mnt->mnt_flags & MNT_NOEXEC)18081808+ exe.file->f_path.mnt->mnt_flags & MNT_NOEXEC)18091809 goto exit;1810181018111811 err = inode_permission(dentry->d_inode, MAY_EXEC);···18391839 goto exit_unlock;1840184018411841 err = 0;18421842- set_mm_exe_file(mm, exe_file); /* this grabs a reference to exe_file */18421842+ set_mm_exe_file(mm, exe.file); /* this grabs a reference to exe.file */18431843exit_unlock:18441844 up_write(&mm->mmap_sem);1845184518461846exit:18471847- fput_light(exe_file, fput_needed);18471847+ fdput(exe);18481848 return err;18491849}18501850