From: Stafford Horne <shorne@gmail.com>
To: openrisc@lists.librecores.org
Subject: [OpenRISC] [PATCH v2 3/6] openrisc: uaccess: Use static inline function in access_ok
Date: Thu, 6 Aug 2020 06:07:22 +0900 [thread overview]
Message-ID: <20200805210725.310301-4-shorne@gmail.com> (raw)
In-Reply-To: <20200805210725.310301-1-shorne@gmail.com>
As suggested by Linus when reviewing commit 9cb2feb4d21d
("arch/openrisc: Fix issues with access_ok()") last year; making
__range_ok an inline function also fixes the used twice issue that the
commit was fixing. I agree it's a good cleanup. This patch addresses
that as I am currently working on the access_ok macro to fixup sparse
annotations in OpenRISC.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
arch/openrisc/include/asm/uaccess.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/openrisc/include/asm/uaccess.h b/arch/openrisc/include/asm/uaccess.h
index f2fc5c4b88c3..4b59dc9ad300 100644
--- a/arch/openrisc/include/asm/uaccess.h
+++ b/arch/openrisc/include/asm/uaccess.h
@@ -48,16 +48,19 @@
/* Ensure that the range from addr to addr+size is all within the process'
* address space
*/
-#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs()-size))
+static inline int __range_ok(unsigned long addr, unsigned long size)
+{
+ const mm_segment_t fs = get_fs();
+
+ return size <= fs && addr <= (fs - size);
+}
/* Ensure that addr is below task's addr_limit */
#define __addr_ok(addr) ((unsigned long) addr < get_fs())
#define access_ok(addr, size) \
({ \
- unsigned long __ao_addr = (unsigned long)(addr); \
- unsigned long __ao_size = (unsigned long)(size); \
- __range_ok(__ao_addr, __ao_size); \
+ __range_ok((unsigned long)(addr), (size)); \
})
/*
--
2.26.2
WARNING: multiple messages have this Message-ID (diff)
From: Stafford Horne <shorne@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Stafford Horne <shorne@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
openrisc@lists.librecores.org
Subject: [PATCH v2 3/6] openrisc: uaccess: Use static inline function in access_ok
Date: Thu, 6 Aug 2020 06:07:22 +0900 [thread overview]
Message-ID: <20200805210725.310301-4-shorne@gmail.com> (raw)
In-Reply-To: <20200805210725.310301-1-shorne@gmail.com>
As suggested by Linus when reviewing commit 9cb2feb4d21d
("arch/openrisc: Fix issues with access_ok()") last year; making
__range_ok an inline function also fixes the used twice issue that the
commit was fixing. I agree it's a good cleanup. This patch addresses
that as I am currently working on the access_ok macro to fixup sparse
annotations in OpenRISC.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
arch/openrisc/include/asm/uaccess.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/openrisc/include/asm/uaccess.h b/arch/openrisc/include/asm/uaccess.h
index f2fc5c4b88c3..4b59dc9ad300 100644
--- a/arch/openrisc/include/asm/uaccess.h
+++ b/arch/openrisc/include/asm/uaccess.h
@@ -48,16 +48,19 @@
/* Ensure that the range from addr to addr+size is all within the process'
* address space
*/
-#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs()-size))
+static inline int __range_ok(unsigned long addr, unsigned long size)
+{
+ const mm_segment_t fs = get_fs();
+
+ return size <= fs && addr <= (fs - size);
+}
/* Ensure that addr is below task's addr_limit */
#define __addr_ok(addr) ((unsigned long) addr < get_fs())
#define access_ok(addr, size) \
({ \
- unsigned long __ao_addr = (unsigned long)(addr); \
- unsigned long __ao_size = (unsigned long)(size); \
- __range_ok(__ao_addr, __ao_size); \
+ __range_ok((unsigned long)(addr), (size)); \
})
/*
--
2.26.2
next prev parent reply other threads:[~2020-08-05 21:07 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-05 21:07 [PATCH v2 0/6] OpenRISC header and sparse warning fixes for 5.9 Stafford Horne
2020-08-05 21:07 ` [OpenRISC] [PATCH v2 1/6] openrisc: io: Fixup defines and move include to the end Stafford Horne
2020-08-05 21:07 ` Stafford Horne
2020-08-05 21:07 ` [OpenRISC] [PATCH v2 2/6] openrisc: uaccess: Fix sparse address space warnings Stafford Horne
2020-08-05 21:07 ` Stafford Horne
2020-08-05 21:07 ` Stafford Horne [this message]
2020-08-05 21:07 ` [PATCH v2 3/6] openrisc: uaccess: Use static inline function in access_ok Stafford Horne
2020-08-06 20:16 ` kernel test robot
2020-08-05 21:07 ` [OpenRISC] [PATCH v2 4/6] openrisc: uaccess: Remove unused macro __addr_ok Stafford Horne
2020-08-05 21:07 ` Stafford Horne
2020-08-05 21:07 ` [OpenRISC] [PATCH v2 5/6] openrisc: signal: Fix sparse address space warnings Stafford Horne
2020-08-05 21:07 ` Stafford Horne
2020-08-06 19:04 ` [OpenRISC] " Luc Van Oostenryck
2020-08-06 19:04 ` Luc Van Oostenryck
2020-08-08 22:48 ` [OpenRISC] " Stafford Horne
2020-08-08 22:48 ` Stafford Horne
2020-08-08 23:08 ` [OpenRISC] " Luc Van Oostenryck
2020-08-08 23:08 ` Luc Van Oostenryck
2020-08-09 8:37 ` [OpenRISC] " Stafford Horne
2020-08-09 8:37 ` Stafford Horne
2020-08-05 21:07 ` [OpenRISC] [PATCH v2 6/6] openrisc: uaccess: Add user address space check to access_ok Stafford Horne
2020-08-05 21:07 ` Stafford Horne
2020-08-06 19:02 ` [OpenRISC] " Luc Van Oostenryck
2020-08-06 19:02 ` Luc Van Oostenryck
2020-08-08 22:35 ` [OpenRISC] " Stafford Horne
2020-08-08 22:35 ` Stafford Horne
2020-08-06 19:11 ` [PATCH v2 0/6] OpenRISC header and sparse warning fixes for 5.9 Luc Van Oostenryck
2020-08-08 22:49 ` Stafford Horne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200805210725.310301-4-shorne@gmail.com \
--to=shorne@gmail.com \
--cc=openrisc@lists.librecores.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.