summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2026-07-29 15:03:04 +0200
committerCarlos Maiolino <cem@kernel.org>2026-09-03 08:51:54 +0200
commit1e6f3dd66fc19affea43d7760d4ec2e75dafe2e7 (patch)
treed02808b1164c30231f453656a4070ccdb280bffb
parentddb7719b20b71aa587da198f6fc84291542a13aa (diff)
downloadlinux-next-1e6f3dd66fc19affea43d7760d4ec2e75dafe2e7.tar.gz
linux-next-1e6f3dd66fc19affea43d7760d4ec2e75dafe2e7.zip
xfs: split out the handler for XFS_IOC_DIOINFO
Split out a helper for XFS_IOC_DIOINFO to keep the stack variables out of xfs_file_ioctl and to clean up the main 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_ioctl.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 479947456b1f..48cee2bf6691 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1200,6 +1200,32 @@ xfs_ioc_fs_counts(
return 0;
}
+static int
+xfs_ioc_dioinfo(
+ struct file *file,
+ void __user *arg)
+{
+ struct kstat st;
+ struct dioattr da;
+ int error;
+
+ error = vfs_getattr(&file->f_path, &st, STATX_DIOALIGN, 0);
+ if (error)
+ return error;
+
+ /*
+ * Some userspace directly feeds the return value to posix_memalign,
+ * which fails for values that are smaller than the pointer size.
+ * Round up the value to not break userspace.
+ */
+ da.d_mem = roundup(st.dio_mem_align, sizeof(void *));
+ da.d_miniosz = st.dio_offset_align;
+ da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
+ if (copy_to_user(arg, &da, sizeof(da)))
+ return -EFAULT;
+ return 0;
+}
+
/*
* These long-unused ioctls were removed from the official ioctl API in 5.17,
* but retain these definitions so that we can log warnings about them.
@@ -1238,26 +1264,9 @@ xfs_file_ioctl(
"%s should use fallocate; XFS_IOC_{ALLOC,FREE}SP ioctl unsupported",
current->comm);
return -ENOTTY;
- case XFS_IOC_DIOINFO: {
- struct kstat st;
- struct dioattr da;
-
- error = vfs_getattr(&filp->f_path, &st, STATX_DIOALIGN, 0);
- if (error)
- return error;
- /*
- * Some userspace directly feeds the return value to
- * posix_memalign, which fails for values that are smaller than
- * the pointer size. Round up the value to not break userspace.
- */
- da.d_mem = roundup(st.dio_mem_align, sizeof(void *));
- da.d_miniosz = st.dio_offset_align;
- da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
- if (copy_to_user(arg, &da, sizeof(da)))
- return -EFAULT;
- return 0;
- }
+ case XFS_IOC_DIOINFO:
+ return xfs_ioc_dioinfo(filp, arg);
case XFS_IOC_FSBULKSTAT_SINGLE:
case XFS_IOC_FSBULKSTAT: