Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fdget(), more trivial conversions

all failure exits prior to fdget() leave the scope, all matching fdput()
are immediately followed by leaving the scope.

[xfs_ioc_commit_range() chunk moved here as well]

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

+202 -418
+6 -13
drivers/infiniband/core/ucma.c
··· 1615 1615 struct ucma_event *uevent, *tmp; 1616 1616 struct ucma_context *ctx; 1617 1617 LIST_HEAD(event_list); 1618 - struct fd f; 1619 1618 struct ucma_file *cur_file; 1620 1619 int ret = 0; 1621 1620 ··· 1622 1623 return -EFAULT; 1623 1624 1624 1625 /* Get current fd to protect against it being closed */ 1625 - f = fdget(cmd.fd); 1626 - if (!fd_file(f)) 1626 + CLASS(fd, f)(cmd.fd); 1627 + if (fd_empty(f)) 1627 1628 return -ENOENT; 1628 - if (fd_file(f)->f_op != &ucma_fops) { 1629 - ret = -EINVAL; 1630 - goto file_put; 1631 - } 1629 + if (fd_file(f)->f_op != &ucma_fops) 1630 + return -EINVAL; 1632 1631 cur_file = fd_file(f)->private_data; 1633 1632 1634 1633 /* Validate current fd and prevent destruction of id. */ 1635 1634 ctx = ucma_get_ctx(cur_file, cmd.id); 1636 - if (IS_ERR(ctx)) { 1637 - ret = PTR_ERR(ctx); 1638 - goto file_put; 1639 - } 1635 + if (IS_ERR(ctx)) 1636 + return PTR_ERR(ctx); 1640 1637 1641 1638 rdma_lock_handler(ctx->cm_id); 1642 1639 /* ··· 1673 1678 err_unlock: 1674 1679 rdma_unlock_handler(ctx->cm_id); 1675 1680 ucma_put_ctx(ctx); 1676 - file_put: 1677 - fdput(f); 1678 1681 return ret; 1679 1682 } 1680 1683
+2 -4
drivers/vfio/group.c
··· 104 104 { 105 105 struct vfio_container *container; 106 106 struct iommufd_ctx *iommufd; 107 - struct fd f; 108 107 int ret; 109 108 int fd; 110 109 111 110 if (get_user(fd, arg)) 112 111 return -EFAULT; 113 112 114 - f = fdget(fd); 115 - if (!fd_file(f)) 113 + CLASS(fd, f)(fd); 114 + if (fd_empty(f)) 116 115 return -EBADF; 117 116 118 117 mutex_lock(&group->group_lock); ··· 152 153 153 154 out_unlock: 154 155 mutex_unlock(&group->group_lock); 155 - fdput(f); 156 156 return ret; 157 157 } 158 158
+4 -11
fs/eventpoll.c
··· 2415 2415 static int do_epoll_wait(int epfd, struct epoll_event __user *events, 2416 2416 int maxevents, struct timespec64 *to) 2417 2417 { 2418 - int error; 2419 - struct fd f; 2420 2418 struct eventpoll *ep; 2421 2419 2422 2420 /* The maximum number of event must be greater than zero */ ··· 2426 2428 return -EFAULT; 2427 2429 2428 2430 /* Get the "struct file *" for the eventpoll file */ 2429 - f = fdget(epfd); 2430 - if (!fd_file(f)) 2431 + CLASS(fd, f)(epfd); 2432 + if (fd_empty(f)) 2431 2433 return -EBADF; 2432 2434 2433 2435 /* 2434 2436 * We have to check that the file structure underneath the fd 2435 2437 * the user passed to us _is_ an eventpoll file. 2436 2438 */ 2437 - error = -EINVAL; 2438 2439 if (!is_file_epoll(fd_file(f))) 2439 - goto error_fput; 2440 + return -EINVAL; 2440 2441 2441 2442 /* 2442 2443 * At this point it is safe to assume that the "private_data" contains ··· 2444 2447 ep = fd_file(f)->private_data; 2445 2448 2446 2449 /* Time to fish for events ... */ 2447 - error = ep_poll(ep, events, maxevents, to); 2448 - 2449 - error_fput: 2450 - fdput(f); 2451 - return error; 2450 + return ep_poll(ep, events, maxevents, to); 2452 2451 } 2453 2452 2454 2453 SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
+7 -14
fs/ext4/ioctl.c
··· 1330 1330 1331 1331 case EXT4_IOC_MOVE_EXT: { 1332 1332 struct move_extent me; 1333 - struct fd donor; 1334 1333 int err; 1335 1334 1336 1335 if (!(filp->f_mode & FMODE_READ) || ··· 1341 1342 return -EFAULT; 1342 1343 me.moved_len = 0; 1343 1344 1344 - donor = fdget(me.donor_fd); 1345 - if (!fd_file(donor)) 1345 + CLASS(fd, donor)(me.donor_fd); 1346 + if (fd_empty(donor)) 1346 1347 return -EBADF; 1347 1348 1348 - if (!(fd_file(donor)->f_mode & FMODE_WRITE)) { 1349 - err = -EBADF; 1350 - goto mext_out; 1351 - } 1349 + if (!(fd_file(donor)->f_mode & FMODE_WRITE)) 1350 + return -EBADF; 1352 1351 1353 1352 if (ext4_has_feature_bigalloc(sb)) { 1354 1353 ext4_msg(sb, KERN_ERR, 1355 1354 "Online defrag not supported with bigalloc"); 1356 - err = -EOPNOTSUPP; 1357 - goto mext_out; 1355 + return -EOPNOTSUPP; 1358 1356 } else if (IS_DAX(inode)) { 1359 1357 ext4_msg(sb, KERN_ERR, 1360 1358 "Online defrag not supported with DAX"); 1361 - err = -EOPNOTSUPP; 1362 - goto mext_out; 1359 + return -EOPNOTSUPP; 1363 1360 } 1364 1361 1365 1362 err = mnt_want_write_file(filp); 1366 1363 if (err) 1367 - goto mext_out; 1364 + return err; 1368 1365 1369 1366 err = ext4_move_extents(filp, fd_file(donor), me.orig_start, 1370 1367 me.donor_start, me.len, &me.moved_len); ··· 1369 1374 if (copy_to_user((struct move_extent __user *)arg, 1370 1375 &me, sizeof(me))) 1371 1376 err = -EFAULT; 1372 - mext_out: 1373 - fdput(donor); 1374 1377 return err; 1375 1378 } 1376 1379
+5 -10
fs/f2fs/file.c
··· 3038 3038 static int __f2fs_ioc_move_range(struct file *filp, 3039 3039 struct f2fs_move_range *range) 3040 3040 { 3041 - struct fd dst; 3042 3041 int err; 3043 3042 3044 3043 if (!(filp->f_mode & FMODE_READ) || 3045 3044 !(filp->f_mode & FMODE_WRITE)) 3046 3045 return -EBADF; 3047 3046 3048 - dst = fdget(range->dst_fd); 3049 - if (!fd_file(dst)) 3047 + CLASS(fd, dst)(range->dst_fd); 3048 + if (fd_empty(dst)) 3050 3049 return -EBADF; 3051 3050 3052 - if (!(fd_file(dst)->f_mode & FMODE_WRITE)) { 3053 - err = -EBADF; 3054 - goto err_out; 3055 - } 3051 + if (!(fd_file(dst)->f_mode & FMODE_WRITE)) 3052 + return -EBADF; 3056 3053 3057 3054 err = mnt_want_write_file(filp); 3058 3055 if (err) 3059 - goto err_out; 3056 + return err; 3060 3057 3061 3058 err = f2fs_move_file_range(filp, range->pos_in, fd_file(dst), 3062 3059 range->pos_out, range->len); 3063 3060 3064 3061 mnt_drop_write_file(filp); 3065 - err_out: 3066 - fdput(dst); 3067 3062 return err; 3068 3063 } 3069 3064
+6 -13
fs/fsopen.c
··· 349 349 int, aux) 350 350 { 351 351 struct fs_context *fc; 352 - struct fd f; 353 352 int ret; 354 353 int lookup_flags = 0; 355 354 ··· 391 392 return -EOPNOTSUPP; 392 393 } 393 394 394 - f = fdget(fd); 395 - if (!fd_file(f)) 395 + CLASS(fd, f)(fd); 396 + if (fd_empty(f)) 396 397 return -EBADF; 397 - ret = -EINVAL; 398 398 if (fd_file(f)->f_op != &fscontext_fops) 399 - goto out_f; 399 + return -EINVAL; 400 400 401 401 fc = fd_file(f)->private_data; 402 402 if (fc->ops == &legacy_fs_context_ops) { ··· 405 407 case FSCONFIG_SET_PATH_EMPTY: 406 408 case FSCONFIG_SET_FD: 407 409 case FSCONFIG_CMD_CREATE_EXCL: 408 - ret = -EOPNOTSUPP; 409 - goto out_f; 410 + return -EOPNOTSUPP; 410 411 } 411 412 } 412 413 413 414 if (_key) { 414 415 param.key = strndup_user(_key, 256); 415 - if (IS_ERR(param.key)) { 416 - ret = PTR_ERR(param.key); 417 - goto out_f; 418 - } 416 + if (IS_ERR(param.key)) 417 + return PTR_ERR(param.key); 419 418 } 420 419 421 420 switch (cmd) { ··· 491 496 } 492 497 out_key: 493 498 kfree(param.key); 494 - out_f: 495 - fdput(f); 496 499 return ret; 497 500 }
+2 -4
fs/fuse/dev.c
··· 2371 2371 int res; 2372 2372 int oldfd; 2373 2373 struct fuse_dev *fud = NULL; 2374 - struct fd f; 2375 2374 2376 2375 if (get_user(oldfd, argp)) 2377 2376 return -EFAULT; 2378 2377 2379 - f = fdget(oldfd); 2380 - if (!fd_file(f)) 2378 + CLASS(fd, f)(oldfd); 2379 + if (fd_empty(f)) 2381 2380 return -EINVAL; 2382 2381 2383 2382 /* ··· 2393 2394 mutex_unlock(&fuse_mutex); 2394 2395 } 2395 2396 2396 - fdput(f); 2397 2397 return res; 2398 2398 } 2399 2399
+5 -10
fs/locks.c
··· 2136 2136 { 2137 2137 int can_sleep, error, type; 2138 2138 struct file_lock fl; 2139 - struct fd f; 2140 2139 2141 2140 /* 2142 2141 * LOCK_MAND locks were broken for a long time in that they never ··· 2154 2155 if (type < 0) 2155 2156 return type; 2156 2157 2157 - error = -EBADF; 2158 - f = fdget(fd); 2159 - if (!fd_file(f)) 2160 - return error; 2158 + CLASS(fd, f)(fd); 2159 + if (fd_empty(f)) 2160 + return -EBADF; 2161 2161 2162 2162 if (type != F_UNLCK && !(fd_file(f)->f_mode & (FMODE_READ | FMODE_WRITE))) 2163 - goto out_putf; 2163 + return -EBADF; 2164 2164 2165 2165 flock_make_lock(fd_file(f), &fl, type); 2166 2166 2167 2167 error = security_file_lock(fd_file(f), fl.c.flc_type); 2168 2168 if (error) 2169 - goto out_putf; 2169 + return error; 2170 2170 2171 2171 can_sleep = !(cmd & LOCK_NB); 2172 2172 if (can_sleep) ··· 2179 2181 error = locks_lock_file_wait(fd_file(f), &fl); 2180 2182 2181 2183 locks_release_private(&fl); 2182 - out_putf: 2183 - fdput(f); 2184 - 2185 2184 return error; 2186 2185 } 2187 2186
+15 -32
fs/namespace.c
··· 4105 4105 struct file *file; 4106 4106 struct path newmount; 4107 4107 struct mount *mnt; 4108 - struct fd f; 4109 4108 unsigned int mnt_flags = 0; 4110 4109 long ret; 4111 4110 ··· 4132 4133 return -EINVAL; 4133 4134 } 4134 4135 4135 - f = fdget(fs_fd); 4136 - if (!fd_file(f)) 4136 + CLASS(fd, f)(fs_fd); 4137 + if (fd_empty(f)) 4137 4138 return -EBADF; 4138 4139 4139 - ret = -EINVAL; 4140 4140 if (fd_file(f)->f_op != &fscontext_fops) 4141 - goto err_fsfd; 4141 + return -EINVAL; 4142 4142 4143 4143 fc = fd_file(f)->private_data; 4144 4144 4145 4145 ret = mutex_lock_interruptible(&fc->uapi_mutex); 4146 4146 if (ret < 0) 4147 - goto err_fsfd; 4147 + return ret; 4148 4148 4149 4149 /* There must be a valid superblock or we can't mount it */ 4150 4150 ret = -EINVAL; ··· 4210 4212 path_put(&newmount); 4211 4213 err_unlock: 4212 4214 mutex_unlock(&fc->uapi_mutex); 4213 - err_fsfd: 4214 - fdput(f); 4215 4215 return ret; 4216 4216 } 4217 4217 ··· 4664 4668 static int build_mount_idmapped(const struct mount_attr *attr, size_t usize, 4665 4669 struct mount_kattr *kattr, unsigned int flags) 4666 4670 { 4667 - int err = 0; 4668 4671 struct ns_common *ns; 4669 4672 struct user_namespace *mnt_userns; 4670 - struct fd f; 4671 4673 4672 4674 if (!((attr->attr_set | attr->attr_clr) & MOUNT_ATTR_IDMAP)) 4673 4675 return 0; ··· 4681 4687 if (attr->userns_fd > INT_MAX) 4682 4688 return -EINVAL; 4683 4689 4684 - f = fdget(attr->userns_fd); 4685 - if (!fd_file(f)) 4690 + CLASS(fd, f)(attr->userns_fd); 4691 + if (fd_empty(f)) 4686 4692 return -EBADF; 4687 4693 4688 - if (!proc_ns_file(fd_file(f))) { 4689 - err = -EINVAL; 4690 - goto out_fput; 4691 - } 4694 + if (!proc_ns_file(fd_file(f))) 4695 + return -EINVAL; 4692 4696 4693 4697 ns = get_proc_ns(file_inode(fd_file(f))); 4694 - if (ns->ops->type != CLONE_NEWUSER) { 4695 - err = -EINVAL; 4696 - goto out_fput; 4697 - } 4698 + if (ns->ops->type != CLONE_NEWUSER) 4699 + return -EINVAL; 4698 4700 4699 4701 /* 4700 4702 * The initial idmapping cannot be used to create an idmapped ··· 4701 4711 * result. 4702 4712 */ 4703 4713 mnt_userns = container_of(ns, struct user_namespace, ns); 4704 - if (mnt_userns == &init_user_ns) { 4705 - err = -EPERM; 4706 - goto out_fput; 4707 - } 4714 + if (mnt_userns == &init_user_ns) 4715 + return -EPERM; 4708 4716 4709 4717 /* We're not controlling the target namespace. */ 4710 - if (!ns_capable(mnt_userns, CAP_SYS_ADMIN)) { 4711 - err = -EPERM; 4712 - goto out_fput; 4713 - } 4718 + if (!ns_capable(mnt_userns, CAP_SYS_ADMIN)) 4719 + return -EPERM; 4714 4720 4715 4721 kattr->mnt_userns = get_user_ns(mnt_userns); 4716 - 4717 - out_fput: 4718 - fdput(f); 4719 - return err; 4722 + return 0; 4720 4723 } 4721 4724 4722 4725 static int build_mount_kattr(const struct mount_attr *attr, size_t usize,
+11 -18
fs/notify/fanotify/fanotify_user.c
··· 1677 1677 struct inode *inode = NULL; 1678 1678 struct vfsmount *mnt = NULL; 1679 1679 struct fsnotify_group *group; 1680 - struct fd f; 1681 1680 struct path path; 1682 1681 struct fan_fsid __fsid, *fsid = NULL; 1683 1682 u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS; ··· 1746 1747 umask = FANOTIFY_EVENT_FLAGS; 1747 1748 } 1748 1749 1749 - f = fdget(fanotify_fd); 1750 - if (unlikely(!fd_file(f))) 1750 + CLASS(fd, f)(fanotify_fd); 1751 + if (fd_empty(f)) 1751 1752 return -EBADF; 1752 1753 1753 1754 /* verify that this is indeed an fanotify instance */ 1754 - ret = -EINVAL; 1755 1755 if (unlikely(fd_file(f)->f_op != &fanotify_fops)) 1756 - goto fput_and_out; 1756 + return -EINVAL; 1757 1757 group = fd_file(f)->private_data; 1758 1758 1759 1759 /* ··· 1760 1762 * marks. This also includes setting up such marks by a group that 1761 1763 * was initialized by an unprivileged user. 1762 1764 */ 1763 - ret = -EPERM; 1764 1765 if ((!capable(CAP_SYS_ADMIN) || 1765 1766 FAN_GROUP_FLAG(group, FANOTIFY_UNPRIV)) && 1766 1767 mark_type != FAN_MARK_INODE) 1767 - goto fput_and_out; 1768 + return -EPERM; 1768 1769 1769 1770 /* 1770 1771 * Permission events require minimum priority FAN_CLASS_CONTENT. 1771 1772 */ 1772 - ret = -EINVAL; 1773 1773 if (mask & FANOTIFY_PERM_EVENTS && 1774 1774 group->priority < FSNOTIFY_PRIO_CONTENT) 1775 - goto fput_and_out; 1775 + return -EINVAL; 1776 1776 1777 1777 if (mask & FAN_FS_ERROR && 1778 1778 mark_type != FAN_MARK_FILESYSTEM) 1779 - goto fput_and_out; 1779 + return -EINVAL; 1780 1780 1781 1781 /* 1782 1782 * Evictable is only relevant for inode marks, because only inode object ··· 1782 1786 */ 1783 1787 if (flags & FAN_MARK_EVICTABLE && 1784 1788 mark_type != FAN_MARK_INODE) 1785 - goto fput_and_out; 1789 + return -EINVAL; 1786 1790 1787 1791 /* 1788 1792 * Events that do not carry enough information to report ··· 1794 1798 fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); 1795 1799 if (mask & ~(FANOTIFY_FD_EVENTS|FANOTIFY_EVENT_FLAGS) && 1796 1800 (!fid_mode || mark_type == FAN_MARK_MOUNT)) 1797 - goto fput_and_out; 1801 + return -EINVAL; 1798 1802 1799 1803 /* 1800 1804 * FAN_RENAME uses special info type records to report the old and ··· 1802 1806 * useful and was not implemented. 1803 1807 */ 1804 1808 if (mask & FAN_RENAME && !(fid_mode & FAN_REPORT_NAME)) 1805 - goto fput_and_out; 1809 + return -EINVAL; 1806 1810 1807 1811 if (mark_cmd == FAN_MARK_FLUSH) { 1808 - ret = 0; 1809 1812 if (mark_type == FAN_MARK_MOUNT) 1810 1813 fsnotify_clear_vfsmount_marks_by_group(group); 1811 1814 else if (mark_type == FAN_MARK_FILESYSTEM) 1812 1815 fsnotify_clear_sb_marks_by_group(group); 1813 1816 else 1814 1817 fsnotify_clear_inode_marks_by_group(group); 1815 - goto fput_and_out; 1818 + return 0; 1816 1819 } 1817 1820 1818 1821 ret = fanotify_find_path(dfd, pathname, &path, flags, 1819 1822 (mask & ALL_FSNOTIFY_EVENTS), obj_type); 1820 1823 if (ret) 1821 - goto fput_and_out; 1824 + return ret; 1822 1825 1823 1826 if (mark_cmd == FAN_MARK_ADD) { 1824 1827 ret = fanotify_events_supported(group, &path, mask, flags); ··· 1896 1901 1897 1902 path_put_and_out: 1898 1903 path_put(&path); 1899 - fput_and_out: 1900 - fdput(f); 1901 1904 return ret; 1902 1905 } 1903 1906
+7 -14
fs/notify/inotify/inotify_user.c
··· 732 732 struct fsnotify_group *group; 733 733 struct inode *inode; 734 734 struct path path; 735 - struct fd f; 736 735 int ret; 737 736 unsigned flags = 0; 738 737 ··· 751 752 if (unlikely(!(mask & ALL_INOTIFY_BITS))) 752 753 return -EINVAL; 753 754 754 - f = fdget(fd); 755 - if (unlikely(!fd_file(f))) 755 + CLASS(fd, f)(fd); 756 + if (fd_empty(f)) 756 757 return -EBADF; 757 758 758 759 /* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */ 759 - if (unlikely((mask & IN_MASK_ADD) && (mask & IN_MASK_CREATE))) { 760 - ret = -EINVAL; 761 - goto fput_and_out; 762 - } 760 + if (unlikely((mask & IN_MASK_ADD) && (mask & IN_MASK_CREATE))) 761 + return -EINVAL; 763 762 764 763 /* verify that this is indeed an inotify instance */ 765 - if (unlikely(fd_file(f)->f_op != &inotify_fops)) { 766 - ret = -EINVAL; 767 - goto fput_and_out; 768 - } 764 + if (unlikely(fd_file(f)->f_op != &inotify_fops)) 765 + return -EINVAL; 769 766 770 767 if (!(mask & IN_DONT_FOLLOW)) 771 768 flags |= LOOKUP_FOLLOW; ··· 771 776 ret = inotify_find_inode(pathname, &path, flags, 772 777 (mask & IN_ALL_EVENTS)); 773 778 if (ret) 774 - goto fput_and_out; 779 + return ret; 775 780 776 781 /* inode held in place by reference to path; group by fget on fd */ 777 782 inode = path.dentry->d_inode; ··· 780 785 /* create/update an inode mark */ 781 786 ret = inotify_update_watch(group, inode, mask); 782 787 path_put(&path); 783 - fput_and_out: 784 - fdput(f); 785 788 return ret; 786 789 } 787 790
+5 -8
fs/ocfs2/cluster/heartbeat.c
··· 1765 1765 long fd; 1766 1766 int sectsize; 1767 1767 char *p = (char *)page; 1768 - struct fd f; 1769 1768 ssize_t ret = -EINVAL; 1770 1769 int live_threshold; 1771 1770 ··· 1783 1784 if (fd < 0 || fd >= INT_MAX) 1784 1785 return -EINVAL; 1785 1786 1786 - f = fdget(fd); 1787 - if (fd_file(f) == NULL) 1787 + CLASS(fd, f)(fd); 1788 + if (fd_empty(f)) 1788 1789 return -EINVAL; 1789 1790 1790 1791 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 || 1791 1792 reg->hr_block_bytes == 0) 1792 - goto out2; 1793 + return -EINVAL; 1793 1794 1794 1795 if (!S_ISBLK(fd_file(f)->f_mapping->host->i_mode)) 1795 - goto out2; 1796 + return -EINVAL; 1796 1797 1797 1798 reg->hr_bdev_file = bdev_file_open_by_dev(fd_file(f)->f_mapping->host->i_rdev, 1798 1799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL); 1799 1800 if (IS_ERR(reg->hr_bdev_file)) { 1800 1801 ret = PTR_ERR(reg->hr_bdev_file); 1801 1802 reg->hr_bdev_file = NULL; 1802 - goto out2; 1803 + return ret; 1803 1804 } 1804 1805 1805 1806 sectsize = bdev_logical_block_size(reg_bdev(reg)); ··· 1905 1906 fput(reg->hr_bdev_file); 1906 1907 reg->hr_bdev_file = NULL; 1907 1908 } 1908 - out2: 1909 - fdput(f); 1910 1909 return ret; 1911 1910 } 1912 1911
+3 -9
fs/open.c
··· 187 187 188 188 long do_sys_ftruncate(unsigned int fd, loff_t length, int small) 189 189 { 190 - struct fd f; 191 - int error; 192 - 193 190 if (length < 0) 194 191 return -EINVAL; 195 - f = fdget(fd); 196 - if (!fd_file(f)) 192 + CLASS(fd, f)(fd); 193 + if (fd_empty(f)) 197 194 return -EBADF; 198 195 199 - error = do_ftruncate(fd_file(f), length, small); 200 - 201 - fdput(f); 202 - return error; 196 + return do_ftruncate(fd_file(f), length, small); 203 197 } 204 198 205 199 SYSCALL_DEFINE2(ftruncate, unsigned int, fd, off_t, length)
+26 -45
fs/read_write.c
··· 745 745 ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count, 746 746 loff_t pos) 747 747 { 748 - struct fd f; 749 - ssize_t ret = -EBADF; 750 - 751 748 if (pos < 0) 752 749 return -EINVAL; 753 750 754 - f = fdget(fd); 755 - if (fd_file(f)) { 756 - ret = -ESPIPE; 757 - if (fd_file(f)->f_mode & FMODE_PREAD) 758 - ret = vfs_read(fd_file(f), buf, count, &pos); 759 - fdput(f); 760 - } 751 + CLASS(fd, f)(fd); 752 + if (fd_empty(f)) 753 + return -EBADF; 761 754 762 - return ret; 755 + if (fd_file(f)->f_mode & FMODE_PREAD) 756 + return vfs_read(fd_file(f), buf, count, &pos); 757 + 758 + return -ESPIPE; 763 759 } 764 760 765 761 SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf, ··· 775 779 ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf, 776 780 size_t count, loff_t pos) 777 781 { 778 - struct fd f; 779 - ssize_t ret = -EBADF; 780 - 781 782 if (pos < 0) 782 783 return -EINVAL; 783 784 784 - f = fdget(fd); 785 - if (fd_file(f)) { 786 - ret = -ESPIPE; 787 - if (fd_file(f)->f_mode & FMODE_PWRITE) 788 - ret = vfs_write(fd_file(f), buf, count, &pos); 789 - fdput(f); 790 - } 785 + CLASS(fd, f)(fd); 786 + if (fd_empty(f)) 787 + return -EBADF; 791 788 792 - return ret; 789 + if (fd_file(f)->f_mode & FMODE_PWRITE) 790 + return vfs_write(fd_file(f), buf, count, &pos); 791 + 792 + return -ESPIPE; 793 793 } 794 794 795 795 SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf, ··· 1299 1307 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, 1300 1308 size_t count, loff_t max) 1301 1309 { 1302 - struct fd in, out; 1303 1310 struct inode *in_inode, *out_inode; 1304 1311 struct pipe_inode_info *opipe; 1305 1312 loff_t pos; ··· 1309 1318 /* 1310 1319 * Get input file, and verify that it is ok.. 1311 1320 */ 1312 - retval = -EBADF; 1313 - in = fdget(in_fd); 1314 - if (!fd_file(in)) 1315 - goto out; 1321 + CLASS(fd, in)(in_fd); 1322 + if (fd_empty(in)) 1323 + return -EBADF; 1316 1324 if (!(fd_file(in)->f_mode & FMODE_READ)) 1317 - goto fput_in; 1318 - retval = -ESPIPE; 1325 + return -EBADF; 1319 1326 if (!ppos) { 1320 1327 pos = fd_file(in)->f_pos; 1321 1328 } else { 1322 1329 pos = *ppos; 1323 1330 if (!(fd_file(in)->f_mode & FMODE_PREAD)) 1324 - goto fput_in; 1331 + return -ESPIPE; 1325 1332 } 1326 1333 retval = rw_verify_area(READ, fd_file(in), &pos, count); 1327 1334 if (retval < 0) 1328 - goto fput_in; 1335 + return retval; 1329 1336 if (count > MAX_RW_COUNT) 1330 1337 count = MAX_RW_COUNT; 1331 1338 1332 1339 /* 1333 1340 * Get output file, and verify that it is ok.. 1334 1341 */ 1335 - retval = -EBADF; 1336 - out = fdget(out_fd); 1337 - if (!fd_file(out)) 1338 - goto fput_in; 1342 + CLASS(fd, out)(out_fd); 1343 + if (fd_empty(out)) 1344 + return -EBADF; 1339 1345 if (!(fd_file(out)->f_mode & FMODE_WRITE)) 1340 - goto fput_out; 1346 + return -EBADF; 1341 1347 in_inode = file_inode(fd_file(in)); 1342 1348 out_inode = file_inode(fd_file(out)); 1343 1349 out_pos = fd_file(out)->f_pos; ··· 1343 1355 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes); 1344 1356 1345 1357 if (unlikely(pos + count > max)) { 1346 - retval = -EOVERFLOW; 1347 1358 if (pos >= max) 1348 - goto fput_out; 1359 + return -EOVERFLOW; 1349 1360 count = max - pos; 1350 1361 } 1351 1362 ··· 1363 1376 if (!opipe) { 1364 1377 retval = rw_verify_area(WRITE, fd_file(out), &out_pos, count); 1365 1378 if (retval < 0) 1366 - goto fput_out; 1379 + return retval; 1367 1380 retval = do_splice_direct(fd_file(in), &pos, fd_file(out), &out_pos, 1368 1381 count, fl); 1369 1382 } else { ··· 1389 1402 inc_syscw(current); 1390 1403 if (pos > max) 1391 1404 retval = -EOVERFLOW; 1392 - 1393 - fput_out: 1394 - fdput(out); 1395 - fput_in: 1396 - fdput(in); 1397 - out: 1398 1405 return retval; 1399 1406 } 1400 1407
+17 -28
fs/splice.c
··· 1622 1622 int, fd_out, loff_t __user *, off_out, 1623 1623 size_t, len, unsigned int, flags) 1624 1624 { 1625 - struct fd in, out; 1626 - ssize_t error; 1627 - 1628 1625 if (unlikely(!len)) 1629 1626 return 0; 1630 1627 1631 1628 if (unlikely(flags & ~SPLICE_F_ALL)) 1632 1629 return -EINVAL; 1633 1630 1634 - error = -EBADF; 1635 - in = fdget(fd_in); 1636 - if (fd_file(in)) { 1637 - out = fdget(fd_out); 1638 - if (fd_file(out)) { 1639 - error = __do_splice(fd_file(in), off_in, fd_file(out), off_out, 1631 + CLASS(fd, in)(fd_in); 1632 + if (fd_empty(in)) 1633 + return -EBADF; 1634 + 1635 + CLASS(fd, out)(fd_out); 1636 + if (fd_empty(out)) 1637 + return -EBADF; 1638 + 1639 + return __do_splice(fd_file(in), off_in, fd_file(out), off_out, 1640 1640 len, flags); 1641 - fdput(out); 1642 - } 1643 - fdput(in); 1644 - } 1645 - return error; 1646 1641 } 1647 1642 1648 1643 /* ··· 1987 1992 1988 1993 SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags) 1989 1994 { 1990 - struct fd in, out; 1991 - ssize_t error; 1992 - 1993 1995 if (unlikely(flags & ~SPLICE_F_ALL)) 1994 1996 return -EINVAL; 1995 1997 1996 1998 if (unlikely(!len)) 1997 1999 return 0; 1998 2000 1999 - error = -EBADF; 2000 - in = fdget(fdin); 2001 - if (fd_file(in)) { 2002 - out = fdget(fdout); 2003 - if (fd_file(out)) { 2004 - error = do_tee(fd_file(in), fd_file(out), len, flags); 2005 - fdput(out); 2006 - } 2007 - fdput(in); 2008 - } 2001 + CLASS(fd, in)(fdin); 2002 + if (fd_empty(in)) 2003 + return -EBADF; 2009 2004 2010 - return error; 2005 + CLASS(fd, out)(fdout); 2006 + if (fd_empty(out)) 2007 + return -EBADF; 2008 + 2009 + return do_tee(fd_file(in), fd_file(out), len, flags); 2011 2010 }
+3 -8
fs/utimes.c
··· 108 108 109 109 static int do_utimes_fd(int fd, struct timespec64 *times, int flags) 110 110 { 111 - struct fd f; 112 - int error; 113 - 114 111 if (flags) 115 112 return -EINVAL; 116 113 117 - f = fdget(fd); 118 - if (!fd_file(f)) 114 + CLASS(fd, f)(fd); 115 + if (fd_empty(f)) 119 116 return -EBADF; 120 - error = vfs_utimes(&fd_file(f)->f_path, times); 121 - fdput(f); 122 - return error; 117 + return vfs_utimes(&fd_file(f)->f_path, times); 123 118 } 124 119 125 120 /*
+5 -13
fs/xfs/xfs_exchrange.c
··· 813 813 .file2 = file, 814 814 }; 815 815 struct xfs_exchange_range args; 816 - struct fd file1; 817 - int error; 818 816 819 817 if (copy_from_user(&args, argp, sizeof(args))) 820 818 return -EFAULT; ··· 826 828 fxr.length = args.length; 827 829 fxr.flags = args.flags; 828 830 829 - file1 = fdget(args.file1_fd); 830 - if (!fd_file(file1)) 831 + CLASS(fd, file1)(args.file1_fd); 832 + if (fd_empty(file1)) 831 833 return -EBADF; 832 834 fxr.file1 = fd_file(file1); 833 835 834 - error = xfs_exchange_range(&fxr); 835 - fdput(file1); 836 - return error; 836 + return xfs_exchange_range(&fxr); 837 837 } 838 838 839 839 /* Opaque freshness blob for XFS_IOC_COMMIT_RANGE */ ··· 905 909 struct xfs_commit_range_fresh *kern_f; 906 910 struct xfs_inode *ip2 = XFS_I(file_inode(file)); 907 911 struct xfs_mount *mp = ip2->i_mount; 908 - struct fd file1; 909 - int error; 910 912 911 913 kern_f = (struct xfs_commit_range_fresh *)&args.file2_freshness; 912 914 ··· 928 934 fxr.file2_ctime.tv_sec = kern_f->file2_ctime; 929 935 fxr.file2_ctime.tv_nsec = kern_f->file2_ctime_nsec; 930 936 931 - file1 = fdget(args.file1_fd); 937 + CLASS(fd, file1)(args.file1_fd); 932 938 if (fd_empty(file1)) 933 939 return -EBADF; 934 940 fxr.file1 = fd_file(file1); 935 941 936 - error = xfs_exchange_range(&fxr); 937 - fdput(file1); 938 - return error; 942 + return xfs_exchange_range(&fxr); 939 943 }
+21 -48
fs/xfs/xfs_ioctl.c
··· 881 881 xfs_swapext_t *sxp) 882 882 { 883 883 xfs_inode_t *ip, *tip; 884 - struct fd f, tmp; 885 - int error = 0; 886 884 887 885 /* Pull information for the target fd */ 888 - f = fdget((int)sxp->sx_fdtarget); 889 - if (!fd_file(f)) { 890 - error = -EINVAL; 891 - goto out; 892 - } 886 + CLASS(fd, f)((int)sxp->sx_fdtarget); 887 + if (fd_empty(f)) 888 + return -EINVAL; 893 889 894 890 if (!(fd_file(f)->f_mode & FMODE_WRITE) || 895 891 !(fd_file(f)->f_mode & FMODE_READ) || 896 - (fd_file(f)->f_flags & O_APPEND)) { 897 - error = -EBADF; 898 - goto out_put_file; 899 - } 892 + (fd_file(f)->f_flags & O_APPEND)) 893 + return -EBADF; 900 894 901 - tmp = fdget((int)sxp->sx_fdtmp); 902 - if (!fd_file(tmp)) { 903 - error = -EINVAL; 904 - goto out_put_file; 905 - } 895 + CLASS(fd, tmp)((int)sxp->sx_fdtmp); 896 + if (fd_empty(tmp)) 897 + return -EINVAL; 906 898 907 899 if (!(fd_file(tmp)->f_mode & FMODE_WRITE) || 908 900 !(fd_file(tmp)->f_mode & FMODE_READ) || 909 - (fd_file(tmp)->f_flags & O_APPEND)) { 910 - error = -EBADF; 911 - goto out_put_tmp_file; 912 - } 901 + (fd_file(tmp)->f_flags & O_APPEND)) 902 + return -EBADF; 913 903 914 904 if (IS_SWAPFILE(file_inode(fd_file(f))) || 915 - IS_SWAPFILE(file_inode(fd_file(tmp)))) { 916 - error = -EINVAL; 917 - goto out_put_tmp_file; 918 - } 905 + IS_SWAPFILE(file_inode(fd_file(tmp)))) 906 + return -EINVAL; 919 907 920 908 /* 921 909 * We need to ensure that the fds passed in point to XFS inodes ··· 911 923 * control over what the user passes us here. 912 924 */ 913 925 if (fd_file(f)->f_op != &xfs_file_operations || 914 - fd_file(tmp)->f_op != &xfs_file_operations) { 915 - error = -EINVAL; 916 - goto out_put_tmp_file; 917 - } 926 + fd_file(tmp)->f_op != &xfs_file_operations) 927 + return -EINVAL; 918 928 919 929 ip = XFS_I(file_inode(fd_file(f))); 920 930 tip = XFS_I(file_inode(fd_file(tmp))); 921 931 922 - if (ip->i_mount != tip->i_mount) { 923 - error = -EINVAL; 924 - goto out_put_tmp_file; 925 - } 932 + if (ip->i_mount != tip->i_mount) 933 + return -EINVAL; 926 934 927 - if (ip->i_ino == tip->i_ino) { 928 - error = -EINVAL; 929 - goto out_put_tmp_file; 930 - } 935 + if (ip->i_ino == tip->i_ino) 936 + return -EINVAL; 931 937 932 - if (xfs_is_shutdown(ip->i_mount)) { 933 - error = -EIO; 934 - goto out_put_tmp_file; 935 - } 938 + if (xfs_is_shutdown(ip->i_mount)) 939 + return -EIO; 936 940 937 - error = xfs_swap_extents(ip, tip, sxp); 938 - 939 - out_put_tmp_file: 940 - fdput(tmp); 941 - out_put_file: 942 - fdput(f); 943 - out: 944 - return error; 941 + return xfs_swap_extents(ip, tip, sxp); 945 942 } 946 943 947 944 static int
+23 -53
ipc/mqueue.c
··· 1063 1063 size_t msg_len, unsigned int msg_prio, 1064 1064 struct timespec64 *ts) 1065 1065 { 1066 - struct fd f; 1067 1066 struct inode *inode; 1068 1067 struct ext_wait_queue wait; 1069 1068 struct ext_wait_queue *receiver; ··· 1083 1084 1084 1085 audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts); 1085 1086 1086 - f = fdget(mqdes); 1087 - if (unlikely(!fd_file(f))) { 1088 - ret = -EBADF; 1089 - goto out; 1090 - } 1087 + CLASS(fd, f)(mqdes); 1088 + if (fd_empty(f)) 1089 + return -EBADF; 1091 1090 1092 1091 inode = file_inode(fd_file(f)); 1093 - if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) { 1094 - ret = -EBADF; 1095 - goto out_fput; 1096 - } 1092 + if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) 1093 + return -EBADF; 1097 1094 info = MQUEUE_I(inode); 1098 1095 audit_file(fd_file(f)); 1099 1096 1100 - if (unlikely(!(fd_file(f)->f_mode & FMODE_WRITE))) { 1101 - ret = -EBADF; 1102 - goto out_fput; 1103 - } 1097 + if (unlikely(!(fd_file(f)->f_mode & FMODE_WRITE))) 1098 + return -EBADF; 1104 1099 1105 - if (unlikely(msg_len > info->attr.mq_msgsize)) { 1106 - ret = -EMSGSIZE; 1107 - goto out_fput; 1108 - } 1100 + if (unlikely(msg_len > info->attr.mq_msgsize)) 1101 + return -EMSGSIZE; 1109 1102 1110 1103 /* First try to allocate memory, before doing anything with 1111 1104 * existing queues. */ 1112 1105 msg_ptr = load_msg(u_msg_ptr, msg_len); 1113 - if (IS_ERR(msg_ptr)) { 1114 - ret = PTR_ERR(msg_ptr); 1115 - goto out_fput; 1116 - } 1106 + if (IS_ERR(msg_ptr)) 1107 + return PTR_ERR(msg_ptr); 1117 1108 msg_ptr->m_ts = msg_len; 1118 1109 msg_ptr->m_type = msg_prio; 1119 1110 ··· 1161 1172 out_free: 1162 1173 if (ret) 1163 1174 free_msg(msg_ptr); 1164 - out_fput: 1165 - fdput(f); 1166 - out: 1167 1175 return ret; 1168 1176 } 1169 1177 ··· 1170 1184 { 1171 1185 ssize_t ret; 1172 1186 struct msg_msg *msg_ptr; 1173 - struct fd f; 1174 1187 struct inode *inode; 1175 1188 struct mqueue_inode_info *info; 1176 1189 struct ext_wait_queue wait; ··· 1183 1198 1184 1199 audit_mq_sendrecv(mqdes, msg_len, 0, ts); 1185 1200 1186 - f = fdget(mqdes); 1187 - if (unlikely(!fd_file(f))) { 1188 - ret = -EBADF; 1189 - goto out; 1190 - } 1201 + CLASS(fd, f)(mqdes); 1202 + if (fd_empty(f)) 1203 + return -EBADF; 1191 1204 1192 1205 inode = file_inode(fd_file(f)); 1193 - if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) { 1194 - ret = -EBADF; 1195 - goto out_fput; 1196 - } 1206 + if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) 1207 + return -EBADF; 1197 1208 info = MQUEUE_I(inode); 1198 1209 audit_file(fd_file(f)); 1199 1210 1200 - if (unlikely(!(fd_file(f)->f_mode & FMODE_READ))) { 1201 - ret = -EBADF; 1202 - goto out_fput; 1203 - } 1211 + if (unlikely(!(fd_file(f)->f_mode & FMODE_READ))) 1212 + return -EBADF; 1204 1213 1205 1214 /* checks if buffer is big enough */ 1206 - if (unlikely(msg_len < info->attr.mq_msgsize)) { 1207 - ret = -EMSGSIZE; 1208 - goto out_fput; 1209 - } 1215 + if (unlikely(msg_len < info->attr.mq_msgsize)) 1216 + return -EMSGSIZE; 1210 1217 1211 1218 /* 1212 1219 * msg_insert really wants us to have a valid, spare node struct so ··· 1252 1275 } 1253 1276 free_msg(msg_ptr); 1254 1277 } 1255 - out_fput: 1256 - fdput(f); 1257 - out: 1258 1278 return ret; 1259 1279 } 1260 1280 ··· 1411 1437 1412 1438 static int do_mq_getsetattr(int mqdes, struct mq_attr *new, struct mq_attr *old) 1413 1439 { 1414 - struct fd f; 1415 1440 struct inode *inode; 1416 1441 struct mqueue_inode_info *info; 1417 1442 1418 1443 if (new && (new->mq_flags & (~O_NONBLOCK))) 1419 1444 return -EINVAL; 1420 1445 1421 - f = fdget(mqdes); 1422 - if (!fd_file(f)) 1446 + CLASS(fd, f)(mqdes); 1447 + if (fd_empty(f)) 1423 1448 return -EBADF; 1424 1449 1425 - if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) { 1426 - fdput(f); 1450 + if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) 1427 1451 return -EBADF; 1428 - } 1429 1452 1430 1453 inode = file_inode(fd_file(f)); 1431 1454 info = MQUEUE_I(inode); ··· 1446 1475 } 1447 1476 1448 1477 spin_unlock(&info->lock); 1449 - fdput(f); 1450 1478 return 0; 1451 1479 } 1452 1480
+3 -8
kernel/module/main.c
··· 3219 3219 3220 3220 SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) 3221 3221 { 3222 - int err; 3223 - struct fd f; 3224 - 3225 - err = may_init_module(); 3222 + int err = may_init_module(); 3226 3223 if (err) 3227 3224 return err; 3228 3225 ··· 3230 3233 |MODULE_INIT_COMPRESSED_FILE)) 3231 3234 return -EINVAL; 3232 3235 3233 - f = fdget(fd); 3236 + CLASS(fd, f)(fd); 3234 3237 if (fd_empty(f)) 3235 3238 return -EBADF; 3236 - err = idempotent_init_module(fd_file(f), uargs, flags); 3237 - fdput(f); 3238 - return err; 3239 + return idempotent_init_module(fd_file(f), uargs, flags); 3239 3240 } 3240 3241 3241 3242 /* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */
+4 -9
kernel/pid.c
··· 744 744 unsigned int, flags) 745 745 { 746 746 struct pid *pid; 747 - struct fd f; 748 - int ret; 749 747 750 748 /* flags is currently unused - make sure it's unset */ 751 749 if (flags) 752 750 return -EINVAL; 753 751 754 - f = fdget(pidfd); 755 - if (!fd_file(f)) 752 + CLASS(fd, f)(pidfd); 753 + if (fd_empty(f)) 756 754 return -EBADF; 757 755 758 756 pid = pidfd_pid(fd_file(f)); 759 757 if (IS_ERR(pid)) 760 - ret = PTR_ERR(pid); 761 - else 762 - ret = pidfd_getfd(pid, fd); 758 + return PTR_ERR(pid); 763 759 764 - fdput(f); 765 - return ret; 760 + return pidfd_getfd(pid, fd); 766 761 }
+10 -19
kernel/signal.c
··· 3908 3908 siginfo_t __user *, info, unsigned int, flags) 3909 3909 { 3910 3910 int ret; 3911 - struct fd f; 3912 3911 struct pid *pid; 3913 3912 kernel_siginfo_t kinfo; 3914 3913 enum pid_type type; ··· 3920 3921 if (hweight32(flags & PIDFD_SEND_SIGNAL_FLAGS) > 1) 3921 3922 return -EINVAL; 3922 3923 3923 - f = fdget(pidfd); 3924 - if (!fd_file(f)) 3924 + CLASS(fd, f)(pidfd); 3925 + if (fd_empty(f)) 3925 3926 return -EBADF; 3926 3927 3927 3928 /* Is this a pidfd? */ 3928 3929 pid = pidfd_to_pid(fd_file(f)); 3929 - if (IS_ERR(pid)) { 3930 - ret = PTR_ERR(pid); 3931 - goto err; 3932 - } 3930 + if (IS_ERR(pid)) 3931 + return PTR_ERR(pid); 3933 3932 3934 - ret = -EINVAL; 3935 3933 if (!access_pidfd_pidns(pid)) 3936 - goto err; 3934 + return -EINVAL; 3937 3935 3938 3936 switch (flags) { 3939 3937 case 0: ··· 3954 3958 if (info) { 3955 3959 ret = copy_siginfo_from_user_any(&kinfo, info); 3956 3960 if (unlikely(ret)) 3957 - goto err; 3961 + return ret; 3958 3962 3959 - ret = -EINVAL; 3960 3963 if (unlikely(sig != kinfo.si_signo)) 3961 - goto err; 3964 + return -EINVAL; 3962 3965 3963 3966 /* Only allow sending arbitrary signals to yourself. */ 3964 - ret = -EPERM; 3965 3967 if ((task_pid(current) != pid || type > PIDTYPE_TGID) && 3966 3968 (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) 3967 - goto err; 3969 + return -EPERM; 3968 3970 } else { 3969 3971 prepare_kill_siginfo(sig, &kinfo, type); 3970 3972 } 3971 3973 3972 3974 if (type == PIDTYPE_PGID) 3973 - ret = kill_pgrp_info(sig, &kinfo, pid); 3975 + return kill_pgrp_info(sig, &kinfo, pid); 3974 3976 else 3975 - ret = kill_pid_info_type(sig, &kinfo, pid, type); 3976 - err: 3977 - fdput(f); 3978 - return ret; 3977 + return kill_pid_info_type(sig, &kinfo, pid, type); 3979 3978 } 3980 3979 3981 3980 static int
+6 -12
kernel/taskstats.c
··· 411 411 struct nlattr *na; 412 412 size_t size; 413 413 u32 fd; 414 - struct fd f; 415 414 416 415 na = info->attrs[CGROUPSTATS_CMD_ATTR_FD]; 417 416 if (!na) 418 417 return -EINVAL; 419 418 420 419 fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]); 421 - f = fdget(fd); 422 - if (!fd_file(f)) 420 + CLASS(fd, f)(fd); 421 + if (fd_empty(f)) 423 422 return 0; 424 423 425 424 size = nla_total_size(sizeof(struct cgroupstats)); ··· 426 427 rc = prepare_reply(info, CGROUPSTATS_CMD_NEW, &rep_skb, 427 428 size); 428 429 if (rc < 0) 429 - goto err; 430 + return rc; 430 431 431 432 na = nla_reserve(rep_skb, CGROUPSTATS_TYPE_CGROUP_STATS, 432 433 sizeof(struct cgroupstats)); 433 434 if (na == NULL) { 434 435 nlmsg_free(rep_skb); 435 - rc = -EMSGSIZE; 436 - goto err; 436 + return -EMSGSIZE; 437 437 } 438 438 439 439 stats = nla_data(na); ··· 441 443 rc = cgroupstats_build(stats, fd_file(f)->f_path.dentry); 442 444 if (rc < 0) { 443 445 nlmsg_free(rep_skb); 444 - goto err; 446 + return rc; 445 447 } 446 448 447 - rc = send_reply(rep_skb, info); 448 - 449 - err: 450 - fdput(f); 451 - return rc; 449 + return send_reply(rep_skb, info); 452 450 } 453 451 454 452 static int cmd_attr_register_cpumask(struct genl_info *info)
+2 -5
security/integrity/ima/ima_main.c
··· 1062 1062 */ 1063 1063 void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) 1064 1064 { 1065 - struct fd f; 1066 - 1067 1065 if (!buf || !size) 1068 1066 return; 1069 1067 1070 - f = fdget(kernel_fd); 1071 - if (!fd_file(f)) 1068 + CLASS(fd, f)(kernel_fd); 1069 + if (fd_empty(f)) 1072 1070 return; 1073 1071 1074 1072 process_buffer_measurement(file_mnt_idmap(fd_file(f)), file_inode(fd_file(f)), 1075 1073 buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0, 1076 1074 NULL, false, NULL, 0); 1077 - fdput(f); 1078 1075 } 1079 1076 1080 1077 /**
+2 -6
security/loadpin/loadpin.c
··· 283 283 284 284 static int read_trusted_verity_root_digests(unsigned int fd) 285 285 { 286 - struct fd f; 287 286 void *data; 288 287 int rc; 289 288 char *p, *d; ··· 294 295 if (!list_empty(&dm_verity_loadpin_trusted_root_digests)) 295 296 return -EPERM; 296 297 297 - f = fdget(fd); 298 - if (!fd_file(f)) 298 + CLASS(fd, f)(fd); 299 + if (fd_empty(f)) 299 300 return -EINVAL; 300 301 301 302 data = kzalloc(SZ_4K, GFP_KERNEL); ··· 358 359 } 359 360 360 361 kfree(data); 361 - fdput(f); 362 362 363 363 return 0; 364 364 ··· 376 378 377 379 /* disallow further attempts after reading a corrupt/invalid file */ 378 380 deny_reading_verity_digests = true; 379 - 380 - fdput(f); 381 381 382 382 return rc; 383 383 }
+2 -4
virt/kvm/vfio.c
··· 229 229 struct kvm_vfio_spapr_tce param; 230 230 struct kvm_vfio *kv = dev->private; 231 231 struct kvm_vfio_file *kvf; 232 - struct fd f; 233 232 int ret; 234 233 235 234 if (copy_from_user(&param, arg, sizeof(struct kvm_vfio_spapr_tce))) 236 235 return -EFAULT; 237 236 238 - f = fdget(param.groupfd); 239 - if (!fd_file(f)) 237 + CLASS(fd, f)(param.groupfd); 238 + if (fd_empty(f)) 240 239 return -EBADF; 241 240 242 241 ret = -ENOENT; ··· 261 262 262 263 err_fdput: 263 264 mutex_unlock(&kv->lock); 264 - fdput(f); 265 265 return ret; 266 266 } 267 267 #endif