[PATCH] powerpc/syscalls: Simplify do_mmap2()

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE1869d LANDED

Landed in mainline as 316389e904f9 on 2021-08-25.

2 messages, 2 authors, 2021-08-27 · open the first message on its own page

[PATCH] powerpc/syscalls: Simplify do_mmap2()

From: Christophe Leroy <hidden>
Date: 2021-06-25 10:58:37

When shift is nul, operations remain valid so no test needed.

And 'ret' is unnecessary.

And use IS_ALIGNED() to check alignment, that's more clear.

Signed-off-by: Christophe Leroy <redacted>
---
 arch/powerpc/kernel/syscalls.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
index bf4ae0f0e36c..825931e400df 100644
--- a/arch/powerpc/kernel/syscalls.c
+++ b/arch/powerpc/kernel/syscalls.c
@@ -41,20 +41,13 @@ static inline long do_mmap2(unsigned long addr, size_t len,
 			unsigned long prot, unsigned long flags,
 			unsigned long fd, unsigned long off, int shift)
 {
-	long ret = -EINVAL;
-
 	if (!arch_validate_prot(prot, addr))
-		goto out;
+		return -EINVAL;
 
-	if (shift) {
-		if (off & ((1 << shift) - 1))
-			goto out;
-		off >>= shift;
-	}
+	if (!IS_ALIGNED(off, 1 << shift))
+		return -EINVAL;
 
-	ret = ksys_mmap_pgoff(addr, len, prot, flags, fd, off);
-out:
-	return ret;
+	return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> shift);
 }
 
 SYSCALL_DEFINE6(mmap2, unsigned long, addr, size_t, len,
-- 
2.25.0

Re: [PATCH] powerpc/syscalls: Simplify do_mmap2()

From: Michael Ellerman <hidden>
Date: 2021-08-27 13:22:38

On Fri, 25 Jun 2021 10:58:33 +0000 (UTC), Christophe Leroy wrote:
When shift is nul, operations remain valid so no test needed.

And 'ret' is unnecessary.

And use IS_ALIGNED() to check alignment, that's more clear.


[...]
Applied to powerpc/next.

[1/1] powerpc/syscalls: Simplify do_mmap2()
      https://git.kernel.org/powerpc/c/316389e904f968d24d44cd96a6d171ee1ef269cf

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help