ptrace: cleanup arch_ptrace() on sh
authorNamhyung Kim <namhyung@gmail.com>
Wed, 27 Oct 2010 22:34:03 +0000 (15:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Oct 2010 01:03:12 +0000 (18:03 -0700)
Remove unnecessary castings and get rid of dummy pointer in favor of
offsetof() macro in ptrace_32.c. Also use temporary variables and
break long lines in order to improve readability.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/sh/kernel/ptrace_32.c
arch/sh/kernel/ptrace_64.c

index 34bf03745e86dcae5a3b4cf59e90e5fa8bf48f32..90a15d29feebdceb4aa019bc7cc8e4f649f08721 100644 (file)
@@ -368,7 +368,6 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 long arch_ptrace(struct task_struct *child, long request,
                 unsigned long addr, unsigned long data)
 {
-       struct user * dummy = NULL;
        unsigned long __user *datap = (unsigned long __user *)data;
        int ret;
 
@@ -384,17 +383,20 @@ long arch_ptrace(struct task_struct *child, long request,
 
                if (addr < sizeof(struct pt_regs))
                        tmp = get_stack_long(child, addr);
-               else if (addr >= (unsigned long) &dummy->fpu &&
-                        addr < (unsigned long) &dummy->u_fpvalid) {
+               else if (addr >= offsetof(struct user, fpu) &&
+                        addr < offsetof(struct user, u_fpvalid)) {
                        if (!tsk_used_math(child)) {
-                               if (addr == (unsigned long)&dummy->fpu.fpscr)
+                               if (addr == offsetof(struct user, fpu.fpscr))
                                        tmp = FPSCR_INIT;
                                else
                                        tmp = 0;
-                       } else
+                       } else {
+                               unsigned long index;
+                               index = addr - offsetof(struct user, fpu);
                                tmp = ((unsigned long *)child->thread.xstate)
-                                       [(addr - (long)&dummy->fpu) >> 2];
-               } else if (addr == (unsigned long) &dummy->u_fpvalid)
+                                       [index >> 2];
+                       }
+               } else if (addr == offsetof(struct user, u_fpvalid))
                        tmp = !!tsk_used_math(child);
                else if (addr == PT_TEXT_ADDR)
                        tmp = child->mm->start_code;
@@ -418,13 +420,15 @@ long arch_ptrace(struct task_struct *child, long request,
 
                if (addr < sizeof(struct pt_regs))
                        ret = put_stack_long(child, addr, data);
-               else if (addr >= (unsigned long) &dummy->fpu &&
-                        addr < (unsigned long) &dummy->u_fpvalid) {
+               else if (addr >= offsetof(struct user, fpu) &&
+                        addr < offsetof(struct user, u_fpvalid)) {
+                       unsigned long index;
+                       index = addr - offsetof(struct user, fpu);
                        set_stopped_child_used_math(child);
                        ((unsigned long *)child->thread.xstate)
-                               [(addr - (long)&dummy->fpu) >> 2] = data;
+                               [index >> 2] = data;
                        ret = 0;
-               } else if (addr == (unsigned long) &dummy->u_fpvalid) {
+               } else if (addr == offsetof(struct user, u_fpvalid)) {
                        conditional_stopped_child_used_math(data, child);
                        ret = 0;
                }
@@ -434,35 +438,35 @@ long arch_ptrace(struct task_struct *child, long request,
                return copy_regset_to_user(child, &user_sh_native_view,
                                           REGSET_GENERAL,
                                           0, sizeof(struct pt_regs),
-                                          (void __user *)data);
+                                          datap);
        case PTRACE_SETREGS:
                return copy_regset_from_user(child, &user_sh_native_view,
                                             REGSET_GENERAL,
                                             0, sizeof(struct pt_regs),
-                                            (const void __user *)data);
+                                            datap);
 #ifdef CONFIG_SH_FPU
        case PTRACE_GETFPREGS:
                return copy_regset_to_user(child, &user_sh_native_view,
                                           REGSET_FPU,
                                           0, sizeof(struct user_fpu_struct),
-                                          (void __user *)data);
+                                          datap);
        case PTRACE_SETFPREGS:
                return copy_regset_from_user(child, &user_sh_native_view,
                                             REGSET_FPU,
                                             0, sizeof(struct user_fpu_struct),
-                                            (const void __user *)data);
+                                            datap);
 #endif
 #ifdef CONFIG_SH_DSP
        case PTRACE_GETDSPREGS:
                return copy_regset_to_user(child, &user_sh_native_view,
                                           REGSET_DSP,
                                           0, sizeof(struct pt_dspregs),
-                                          (void __user *)data);
+                                          datap);
        case PTRACE_SETDSPREGS:
                return copy_regset_from_user(child, &user_sh_native_view,
                                             REGSET_DSP,
                                             0, sizeof(struct pt_dspregs),
-                                            (const void __user *)data);
+                                            datap);
 #endif
        default:
                ret = ptrace_request(child, request, addr, data);
index 4840716c196a55d811c932988538b5c674d9b4fc..4436eacddb1536e6aaf5a00299a659dc12a210c6 100644 (file)
@@ -387,6 +387,7 @@ long arch_ptrace(struct task_struct *child, long request,
                 unsigned long addr, unsigned long data)
 {
        int ret;
+       unsigned long __user *datap = (unsigned long __user *) data;
 
        switch (request) {
        /* read the word at location addr in the USER area. */
@@ -401,13 +402,15 @@ long arch_ptrace(struct task_struct *child, long request,
                        tmp = get_stack_long(child, addr);
                else if ((addr >= offsetof(struct user, fpu)) &&
                         (addr <  offsetof(struct user, u_fpvalid))) {
-                       tmp = get_fpu_long(child, addr - offsetof(struct user, fpu));
+                       unsigned long index;
+                       index = addr - offsetof(struct user, fpu);
+                       tmp = get_fpu_long(child, index);
                } else if (addr == offsetof(struct user, u_fpvalid)) {
                        tmp = !!tsk_used_math(child);
                } else {
                        break;
                }
-               ret = put_user(tmp, (unsigned long *)data);
+               ret = put_user(tmp, datap);
                break;
        }
 
@@ -438,7 +441,9 @@ long arch_ptrace(struct task_struct *child, long request,
                }
                else if ((addr >= offsetof(struct user, fpu)) &&
                         (addr <  offsetof(struct user, u_fpvalid))) {
-                       ret = put_fpu_long(child, addr - offsetof(struct user, fpu), data);
+                       unsigned long index;
+                       index = addr - offsetof(struct user, fpu);
+                       ret = put_fpu_long(child, index, data);
                }
                break;
 
@@ -446,23 +451,23 @@ long arch_ptrace(struct task_struct *child, long request,
                return copy_regset_to_user(child, &user_sh64_native_view,
                                           REGSET_GENERAL,
                                           0, sizeof(struct pt_regs),
-                                          (void __user *)data);
+                                          datap);
        case PTRACE_SETREGS:
                return copy_regset_from_user(child, &user_sh64_native_view,
                                             REGSET_GENERAL,
                                             0, sizeof(struct pt_regs),
-                                            (const void __user *)data);
+                                            datap);
 #ifdef CONFIG_SH_FPU
        case PTRACE_GETFPREGS:
                return copy_regset_to_user(child, &user_sh64_native_view,
                                           REGSET_FPU,
                                           0, sizeof(struct user_fpu_struct),
-                                          (void __user *)data);
+                                          datap);
        case PTRACE_SETFPREGS:
                return copy_regset_from_user(child, &user_sh64_native_view,
                                             REGSET_FPU,
                                             0, sizeof(struct user_fpu_struct),
-                                            (const void __user *)data);
+                                            datap);
 #endif
        default:
                ret = ptrace_request(child, request, addr, data);