summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2026-07-29 15:03:13 +0200
committerCarlos Maiolino <cem@kernel.org>2026-09-07 07:51:51 +0200
commita9a1dc9eaf2a1992e46a8c2d98c63b1105c3b20a (patch)
tree3b48b36bd535a59a68e234c27b27ef71b487f772
parentd99d2af5b5152c677f12088c7ab3919e2127731d (diff)
downloadlinux-next-a9a1dc9eaf2a1992e46a8c2d98c63b1105c3b20a.tar.gz
linux-next-a9a1dc9eaf2a1992e46a8c2d98c63b1105c3b20a.zip
xfs: split out the handlers for XFS_IOC_SWAPEXT_32
Split out a helper for XFS_IOC_SWAPEXT_32 to keep the stack variables out of xfs_file_compat_ioctl and to clean up the main compat ioctl handler flow. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
-rw-r--r--fs/xfs/xfs_ioctl32.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c
index ede890d4cbc3..a6e3b35db6e2 100644
--- a/fs/xfs/xfs_ioctl32.c
+++ b/fs/xfs/xfs_ioctl32.c
@@ -158,6 +158,27 @@ xfs_ioctl32_bstat_copyin(
return 0;
}
+static int
+xfs_compat_ioc_swapext(
+ struct file *file,
+ struct compat_xfs_swapext __user *sxu)
+{
+ struct xfs_swapext sxp;
+ int error;
+
+ /* Bulk copy in up to the sx_stat field, then copy bstat */
+ if (copy_from_user(&sxp, sxu, offsetof(struct xfs_swapext, sx_stat)) ||
+ xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat))
+ return -EFAULT;
+
+ error = mnt_want_write_file(file);
+ if (error)
+ return error;
+ error = xfs_swapext(&sxp);
+ mnt_drop_write_file(file);
+ return error;
+}
+
/* XFS_IOC_FSBULKSTAT and friends */
STATIC int
@@ -446,7 +467,6 @@ xfs_file_compat_ioctl(
struct inode *inode = file_inode(filp);
struct xfs_inode *ip = XFS_I(inode);
void __user *arg = compat_ptr(p);
- int error;
trace_xfs_file_compat_ioctl(ip);
@@ -462,22 +482,8 @@ xfs_file_compat_ioctl(
case XFS_IOC_GETVERSION_32:
/* long changes size, but xfs only copies out 32 bits */
return xfs_file_ioctl(filp, _NATIVE_IOC(cmd, long), p);
- case XFS_IOC_SWAPEXT_32: {
- struct xfs_swapext sxp;
- struct compat_xfs_swapext __user *sxu = arg;
-
- /* Bulk copy in up to the sx_stat field, then copy bstat */
- if (copy_from_user(&sxp, sxu,
- offsetof(struct xfs_swapext, sx_stat)) ||
- xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat))
- return -EFAULT;
- error = mnt_want_write_file(filp);
- if (error)
- return error;
- error = xfs_swapext(&sxp);
- mnt_drop_write_file(filp);
- return error;
- }
+ case XFS_IOC_SWAPEXT_32:
+ return xfs_compat_ioc_swapext(filp, arg);
case XFS_IOC_FSBULKSTAT_32:
case XFS_IOC_FSBULKSTAT_SINGLE_32:
case XFS_IOC_FSINUMBERS_32: