Commit 475a4b81 authored by Namhyung Kim's avatar Namhyung Kim Committed by Linus Torvalds

ptrace: cleanup arch_ptrace() on cris

Use new 'regno' variable in order to remove redandunt expression and
remove checking @addr less than 0 because @addr is now unsigned.  Also
update 'datap' on PTRACE_GET/SETREGS to fix a bug on arch-v10.
Signed-off-by: default avatarNamhyung Kim <namhyung@gmail.com>
Acked-by: default avatarMikael Starvik <starvik@axis.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent aeebd3a3
...@@ -80,6 +80,7 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -80,6 +80,7 @@ long arch_ptrace(struct task_struct *child, long request,
unsigned long addr, unsigned long data) unsigned long addr, unsigned long data)
{ {
int ret; int ret;
unsigned int regno = addr >> 2;
unsigned long __user *datap = (unsigned long __user *)data; unsigned long __user *datap = (unsigned long __user *)data;
switch (request) { switch (request) {
...@@ -94,10 +95,10 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -94,10 +95,10 @@ long arch_ptrace(struct task_struct *child, long request,
unsigned long tmp; unsigned long tmp;
ret = -EIO; ret = -EIO;
if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) if ((addr & 3) || regno > PT_MAX)
break; break;
tmp = get_reg(child, addr >> 2); tmp = get_reg(child, regno);
ret = put_user(tmp, datap); ret = put_user(tmp, datap);
break; break;
} }
...@@ -111,19 +112,17 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -111,19 +112,17 @@ long arch_ptrace(struct task_struct *child, long request,
/* Write the word at location address in the USER area. */ /* Write the word at location address in the USER area. */
case PTRACE_POKEUSR: case PTRACE_POKEUSR:
ret = -EIO; ret = -EIO;
if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) if ((addr & 3) || regno > PT_MAX)
break; break;
addr >>= 2; if (regno == PT_DCCR) {
if (addr == PT_DCCR) {
/* don't allow the tracing process to change stuff like /* don't allow the tracing process to change stuff like
* interrupt enable, kernel/user bit, dma enables etc. * interrupt enable, kernel/user bit, dma enables etc.
*/ */
data &= DCCR_MASK; data &= DCCR_MASK;
data |= get_reg(child, PT_DCCR) & ~DCCR_MASK; data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
} }
if (put_reg(child, addr, data)) if (put_reg(child, regno, data))
break; break;
ret = 0; ret = 0;
break; break;
...@@ -142,7 +141,7 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -142,7 +141,7 @@ long arch_ptrace(struct task_struct *child, long request,
break; break;
} }
data += sizeof(unsigned long); datap++;
} }
break; break;
...@@ -166,7 +165,7 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -166,7 +165,7 @@ long arch_ptrace(struct task_struct *child, long request,
} }
put_reg(child, i, tmp); put_reg(child, i, tmp);
data += sizeof(unsigned long); datap++;
} }
break; break;
......
...@@ -130,6 +130,7 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -130,6 +130,7 @@ long arch_ptrace(struct task_struct *child, long request,
unsigned long addr, unsigned long data) unsigned long addr, unsigned long data)
{ {
int ret; int ret;
unsigned int regno = addr >> 2;
unsigned long __user *datap = (unsigned long __user *)data; unsigned long __user *datap = (unsigned long __user *)data;
switch (request) { switch (request) {
...@@ -164,10 +165,10 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -164,10 +165,10 @@ long arch_ptrace(struct task_struct *child, long request,
unsigned long tmp; unsigned long tmp;
ret = -EIO; ret = -EIO;
if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) if ((addr & 3) || regno > PT_MAX)
break; break;
tmp = get_reg(child, addr >> 2); tmp = get_reg(child, regno);
ret = put_user(tmp, datap); ret = put_user(tmp, datap);
break; break;
} }
...@@ -181,19 +182,17 @@ long arch_ptrace(struct task_struct *child, long request, ...@@ -181,19 +182,17 @@ long arch_ptrace(struct task_struct *child, long request,
/* Write the word at location address in the USER area. */ /* Write the word at location address in the USER area. */
case PTRACE_POKEUSR: case PTRACE_POKEUSR:
ret = -EIO; ret = -EIO;
if ((addr & 3) || addr < 0 || addr > PT_MAX << 2) if ((addr & 3) || regno > PT_MAX)
break; break;
addr >>= 2; if (regno == PT_CCS) {
if (addr == PT_CCS) {
/* don't allow the tracing process to change stuff like /* don't allow the tracing process to change stuff like
* interrupt enable, kernel/user bit, dma enables etc. * interrupt enable, kernel/user bit, dma enables etc.
*/ */
data &= CCS_MASK; data &= CCS_MASK;
data |= get_reg(child, PT_CCS) & ~CCS_MASK; data |= get_reg(child, PT_CCS) & ~CCS_MASK;
} }
if (put_reg(child, addr, data)) if (put_reg(child, regno, data))
break; break;
ret = 0; ret = 0;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment