diff mbox

[U-Boot,2/2] Use map_sysmem when accessing memory in setexpr

Message ID 1431370394-29923-2-git-send-email-joe.hershberger@ni.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Joe Hershberger May 11, 2015, 6:53 p.m. UTC
The setexpr command used to segfault when accessing memory in sandbox.
The pointer accesses should be mapped.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Cc: Simon Glass <sjg@chromium.org>
---

 common/cmd_setexpr.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

Comments

Simon Glass May 11, 2015, 10:41 p.m. UTC | #1
On 11 May 2015 at 12:53, Joe Hershberger <joe.hershberger@ni.com> wrote:
> The setexpr command used to segfault when accessing memory in sandbox.
> The pointer accesses should be mapped.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Simon Glass <sjg@chromium.org>
> ---
>
>  common/cmd_setexpr.c | 32 +++++++++++++++++++++++---------
>  1 file changed, 23 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Joe Hershberger May 13, 2015, 10:01 p.m. UTC | #2
Hi Tom,

On Mon, May 11, 2015 at 5:41 PM, Simon Glass <sjg@chromium.org> wrote:
> On 11 May 2015 at 12:53, Joe Hershberger <joe.hershberger@ni.com> wrote:
>> The setexpr command used to segfault when accessing memory in sandbox.
>> The pointer accesses should be mapped.
>>
>> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>> Cc: Simon Glass <sjg@chromium.org>
>> ---
>>
>>  common/cmd_setexpr.c | 32 +++++++++++++++++++++++---------
>>  1 file changed, 23 insertions(+), 9 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Can you pull this patch in?

I have to regenerate patch 1 in this series, but this is pretty much
independent. These should not have been in the same series.

Thanks,
-Joe
Tom Rini May 14, 2015, 7:14 p.m. UTC | #3
On Mon, May 11, 2015 at 01:53:13PM -0500, Joe Hershberger wrote:

> The setexpr command used to segfault when accessing memory in sandbox.
> The pointer accesses should be mapped.
> 
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Simon Glass <sjg@chromium.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/common/cmd_setexpr.c b/common/cmd_setexpr.c
index 926339b..e7194fc 100644
--- a/common/cmd_setexpr.c
+++ b/common/cmd_setexpr.c
@@ -12,23 +12,37 @@ 
 #include <common.h>
 #include <config.h>
 #include <command.h>
+#include <mapmem.h>
 
 static ulong get_arg(char *s, int w)
 {
-	ulong *p;
-
 	/*
-	 * if the parameter starts with a '*' then assume
-	 * it is a pointer to the value we want
+	 * If the parameter starts with a '*' then assume it is a pointer to
+	 * the value we want.
 	 */
-
 	if (s[0] == '*') {
-		p = (ulong *)simple_strtoul(&s[1], NULL, 16);
+		ulong *p;
+		ulong addr;
+		ulong val;
+
+		addr = simple_strtoul(&s[1], NULL, 16);
 		switch (w) {
-		case 1: return((ulong)(*(uchar *)p));
-		case 2: return((ulong)(*(ushort *)p));
+		case 1:
+			p = map_sysmem(addr, sizeof(uchar));
+			val = (ulong)*(uchar *)p;
+			unmap_sysmem(p);
+			return val;
+		case 2:
+			p = map_sysmem(addr, sizeof(ushort));
+			val = (ulong)*(ushort *)p;
+			unmap_sysmem(p);
+			return val;
 		case 4:
-		default: return(*p);
+		default:
+			p = map_sysmem(addr, sizeof(ulong));
+			val = *p;
+			unmap_sysmem(p);
+			return val;
 		}
 	} else {
 		return simple_strtoul(s, NULL, 16);