ptrace: cleanup arch_ptrace() on h8300
authorNamhyung Kim <namhyung@gmail.com>
Wed, 27 Oct 2010 22:33:53 +0000 (15:33 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Oct 2010 01:03:11 +0000 (18:03 -0700)
Use new 'regno', 'datap' variables in order to remove duplicated
expressions and unnecessary castings. Alse remove checking @addr
less than 0 because addr is now unsigned.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/h8300/kernel/ptrace.c

index ef1aa0b8b20fde1fd5f277c37d905d787ff7be46..497fa89b5df40815ca3b20b4c252a8d9e09c3d1a 100644 (file)
@@ -54,24 +54,25 @@ long arch_ptrace(struct task_struct *child, long request,
                 unsigned long addr, unsigned long data)
 {
        int ret;
+       int regno = addr >> 2;
+       unsigned long __user *datap = (unsigned long __user *) data;
 
        switch (request) {
        /* read the word at location addr in the USER area. */
                case PTRACE_PEEKUSR: {
                        unsigned long tmp = 0;
                        
-                       if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
+                       if ((addr & 3) || addr >= sizeof(struct user)) {
                                ret = -EIO;
                                break ;
                        }
                        
                        ret = 0;  /* Default return condition */
-                       addr = addr >> 2; /* temporary hack. */
 
-                       if (addr < H8300_REGS_NO)
-                               tmp = h8300_get_reg(child, addr);
+                       if (regno < H8300_REGS_NO)
+                               tmp = h8300_get_reg(child, regno);
                        else {
-                               switch(addr) {
+                               switch (regno) {
                                case 49:
                                        tmp = child->mm->start_code;
                                        break ;
@@ -89,24 +90,23 @@ long arch_ptrace(struct task_struct *child, long request,
                                }
                        }
                        if (!ret)
-                               ret = put_user(tmp,(unsigned long *) data);
+                               ret = put_user(tmp, datap);
                        break ;
                }
 
       /* when I and D space are separate, this will have to be fixed. */
                case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
-                       if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
+                       if ((addr & 3) || addr >= sizeof(struct user)) {
                                ret = -EIO;
                                break ;
                        }
-                       addr = addr >> 2; /* temporary hack. */
                            
-                       if (addr == PT_ORIG_ER0) {
+                       if (regno == PT_ORIG_ER0) {
                                ret = -EIO;
                                break ;
                        }
-                       if (addr < H8300_REGS_NO) {
-                               ret = h8300_put_reg(child, addr, data);
+                       if (regno < H8300_REGS_NO) {
+                               ret = h8300_put_reg(child, regno, data);
                                break ;
                        }
                        ret = -EIO;
@@ -117,11 +117,11 @@ long arch_ptrace(struct task_struct *child, long request,
                        unsigned long tmp;
                        for (i = 0; i < H8300_REGS_NO; i++) {
                            tmp = h8300_get_reg(child, i);
-                           if (put_user(tmp, (unsigned long *) data)) {
+                           if (put_user(tmp, datap)) {
                                ret = -EFAULT;
                                break;
                            }
-                           data += sizeof(unsigned long);
+                           datap++;
                        }
                        ret = 0;
                        break;
@@ -131,12 +131,12 @@ long arch_ptrace(struct task_struct *child, long request,
                        int i;
                        unsigned long tmp;
                        for (i = 0; i < H8300_REGS_NO; i++) {
-                           if (get_user(tmp, (unsigned long *) data)) {
+                           if (get_user(tmp, datap)) {
                                ret = -EFAULT;
                                break;
                            }
                            h8300_put_reg(child, i, tmp);
-                           data += sizeof(unsigned long);
+                           datap++;
                        }
                        ret = 0;
                        break;