diff mbox series

[RFC,V3,23/43] rv64ilp32_abi: compat: Correct compat_ulong_t cast

Message ID 20250325121624.523258-24-guoren@kernel.org (mailing list archive)
State New
Headers show
Series rv64ilp32_abi: Build CONFIG_64BIT kernel-self with ILP32 ABI | expand

Commit Message

Guo Ren March 25, 2025, 12:16 p.m. UTC
From: "Guo Ren (Alibaba DAMO Academy)" <guoren@kernel.org>

RV64ILP32 ABI systems have BITS_PER_LONG set to 32, matching
sizeof(compat_ulong_t). Adjust code involving compat_ulong_t
accordingly.

Signed-off-by: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
---
 include/uapi/linux/auto_fs.h |  6 ++++++
 kernel/compat.c              | 15 ++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/include/uapi/linux/auto_fs.h b/include/uapi/linux/auto_fs.h
index 8081df849743..7d925ee810b6 100644
--- a/include/uapi/linux/auto_fs.h
+++ b/include/uapi/linux/auto_fs.h
@@ -80,9 +80,15 @@  enum {
 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(AUTOFS_IOCTL, \
 				      AUTOFS_IOC_SETTIMEOUT_CMD, \
 				      compat_ulong_t)
+#if __riscv_xlen == 64
+#define AUTOFS_IOC_SETTIMEOUT   _IOWR(AUTOFS_IOCTL, \
+				      AUTOFS_IOC_SETTIMEOUT_CMD, \
+				      unsigned long long)
+#else
 #define AUTOFS_IOC_SETTIMEOUT   _IOWR(AUTOFS_IOCTL, \
 				      AUTOFS_IOC_SETTIMEOUT_CMD, \
 				      unsigned long)
+#endif
 #define AUTOFS_IOC_EXPIRE       _IOR(AUTOFS_IOCTL, \
 				     AUTOFS_IOC_EXPIRE_CMD, \
 				     struct autofs_packet_expire)
diff --git a/kernel/compat.c b/kernel/compat.c
index fb50f29d9b36..46ffdc5e7cc4 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -203,11 +203,17 @@  long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
 		return -EFAULT;
 
 	while (nr_compat_longs > 1) {
-		compat_ulong_t l1, l2;
+		compat_ulong_t l1;
 		unsafe_get_user(l1, umask++, Efault);
+		nr_compat_longs -= 1;
+#if BITS_PER_LONG == 64
+		compat_ulong_t l2;
 		unsafe_get_user(l2, umask++, Efault);
 		*mask++ = ((unsigned long)l2 << BITS_PER_COMPAT_LONG) | l1;
-		nr_compat_longs -= 2;
+		nr_compat_longs -= 1;
+#else
+		*mask++ = l1;
+#endif
 	}
 	if (nr_compat_longs)
 		unsafe_get_user(*mask, umask++, Efault);
@@ -234,8 +240,11 @@  long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
 	while (nr_compat_longs > 1) {
 		unsigned long m = *mask++;
 		unsafe_put_user((compat_ulong_t)m, umask++, Efault);
+		nr_compat_longs -= 1;
+#if BITS_PER_LONG == 64
 		unsafe_put_user(m >> BITS_PER_COMPAT_LONG, umask++, Efault);
-		nr_compat_longs -= 2;
+		nr_compat_longs -= 1;
+#endif
 	}
 	if (nr_compat_longs)
 		unsafe_put_user((compat_ulong_t)*mask, umask++, Efault);