Skip to contentSkip to conversation

x86/mm: Refine mmap syscall implementation

PATCH Applied Adrian Huang 3 participants 3 messages Dec 17, 2020 – Jan 5, 2021 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: Refine mmap syscall implementation

From: Adrian Huang <[email protected]>

It is unnecessary to use the local variable 'error' in the mmap syscall implementation function, so use the return statement instead of it.

---
 arch/x86/kernel/sys_x86_64.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/sys_x86_64.c +2 -6
index 504fa5425bce..660b78827638 100644
@@ -90,14 +90,10 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
 		unsigned long, prot, unsigned long, flags,
 		unsigned long, fd, unsigned long, off)
 {
-	long error;
-	error = -EINVAL;
 	if (off & ~PAGE_MASK)
-		goto out;
+		return -EINVAL;
 
-	error = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
-out:
-	return error;
+	return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
 }
 
 static void find_start_end(unsigned long addr, unsigned long flags,
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Adrian Huang

From: Adrian Huang <[email protected]>

It is unnecessary to use the local variable 'error' in the mmap syscall implementation function, so use the return statement instead of it.

I'm normally not a fan of standalone cleanup patches, but this one actually improves the function a lot, so:

merge bot Applied
#2 lore raw
In reply to Adrian Huang
The following commit has been merged into the x86/cleanups branch of tip:

The following commit has been merged into the x86/cleanups branch of tip:

Commit-ID:     91a8f6cb06b33adc79fbf5f7381d907485767c00
Gitweb:        https://git.kernel.org/tip/91a8f6cb06b33adc79fbf5f7381d907485767c00
Author:        Adrian Huang <[email protected]>
AuthorDate:    Thu, 17 Dec 2020 13:26:48 +08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 05 Jan 2021 19:07:42 +01:00

x86/mm: Refine mmap syscall implementation

It is unnecessary to use the local variable 'error' in the mmap syscall implementation function - just return -EINVAL directly and get rid of the local variable altogether.

[ bp: Massage commit message. ]

---
 arch/x86/kernel/sys_x86_64.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/sys_x86_64.c +2 -6
index 504fa54..660b788 100644
@@ -90,14 +90,10 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
 		unsigned long, prot, unsigned long, flags,
 		unsigned long, fd, unsigned long, off)
 {
-	long error;
-	error = -EINVAL;
 	if (off & ~PAGE_MASK)
-		goto out;
+		return -EINVAL;
 
-	error = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
-out:
-	return error;
+	return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
 }
 
 static void find_start_end(unsigned long addr, unsigned long flags,