Commit a9384e23ab19eba0dedb861ebcba805b98a3b7a5

Authored by Namhyung Kim
Committed by Linus Torvalds
1 parent 9e1cb20619

ptrace: cleanup arch_ptrace() on sparc

Factor out struct fps and remove redundant castings.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 24 additions and 38 deletions Side-by-side Diff

arch/sparc/kernel/ptrace_32.c
... ... @@ -323,19 +323,35 @@
323 323 return &user_sparc32_view;
324 324 }
325 325  
  326 +struct fps {
  327 + unsigned long regs[32];
  328 + unsigned long fsr;
  329 + unsigned long flags;
  330 + unsigned long extra;
  331 + unsigned long fpqd;
  332 + struct fq {
  333 + unsigned long *insnaddr;
  334 + unsigned long insn;
  335 + } fpq[16];
  336 +};
  337 +
326 338 long arch_ptrace(struct task_struct *child, long request,
327 339 unsigned long addr, unsigned long data)
328 340 {
329 341 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
  342 + void __user *addr2p;
330 343 const struct user_regset_view *view;
  344 + struct pt_regs __user *pregs;
  345 + struct fps __user *fps;
331 346 int ret;
332 347  
333 348 view = task_user_regset_view(current);
  349 + addr2p = (void __user *) addr2;
  350 + pregs = (struct pt_regs __user *) addr;
  351 + fps = (struct fps __user *) addr;
334 352  
335 353 switch(request) {
336 354 case PTRACE_GETREGS: {
337   - struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
338   -
339 355 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
340 356 32 * sizeof(u32),
341 357 4 * sizeof(u32),
... ... @@ -349,8 +365,6 @@
349 365 }
350 366  
351 367 case PTRACE_SETREGS: {
352   - struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
353   -
354 368 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
355 369 32 * sizeof(u32),
356 370 4 * sizeof(u32),
... ... @@ -364,19 +378,6 @@
364 378 }
365 379  
366 380 case PTRACE_GETFPREGS: {
367   - struct fps {
368   - unsigned long regs[32];
369   - unsigned long fsr;
370   - unsigned long flags;
371   - unsigned long extra;
372   - unsigned long fpqd;
373   - struct fq {
374   - unsigned long *insnaddr;
375   - unsigned long insn;
376   - } fpq[16];
377   - };
378   - struct fps __user *fps = (struct fps __user *) addr;
379   -
380 381 ret = copy_regset_to_user(child, view, REGSET_FP,
381 382 0 * sizeof(u32),
382 383 32 * sizeof(u32),
... ... @@ -398,19 +399,6 @@
398 399 }
399 400  
400 401 case PTRACE_SETFPREGS: {
401   - struct fps {
402   - unsigned long regs[32];
403   - unsigned long fsr;
404   - unsigned long flags;
405   - unsigned long extra;
406   - unsigned long fpqd;
407   - struct fq {
408   - unsigned long *insnaddr;
409   - unsigned long insn;
410   - } fpq[16];
411   - };
412   - struct fps __user *fps = (struct fps __user *) addr;
413   -
414 402 ret = copy_regset_from_user(child, view, REGSET_FP,
415 403 0 * sizeof(u32),
416 404 32 * sizeof(u32),
... ... @@ -425,8 +413,7 @@
425 413  
426 414 case PTRACE_READTEXT:
427 415 case PTRACE_READDATA:
428   - ret = ptrace_readdata(child, addr,
429   - (void __user *) addr2, data);
  416 + ret = ptrace_readdata(child, addr, addr2p, data);
430 417  
431 418 if (ret == data)
432 419 ret = 0;
... ... @@ -436,8 +423,7 @@
436 423  
437 424 case PTRACE_WRITETEXT:
438 425 case PTRACE_WRITEDATA:
439   - ret = ptrace_writedata(child, (void __user *) addr2,
440   - addr, data);
  426 + ret = ptrace_writedata(child, addr2p, addr, data);
441 427  
442 428 if (ret == data)
443 429 ret = 0;
arch/sparc/kernel/ptrace_64.c
... ... @@ -976,10 +976,12 @@
976 976 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
977 977 struct pt_regs __user *pregs;
978 978 struct fps __user *fps;
  979 + void __user *addr2p;
979 980 int ret;
980 981  
981 982 pregs = (struct pt_regs __user *) addr;
982 983 fps = (struct fps __user *) addr;
  984 + addr2p = (void __user *) addr2;
983 985  
984 986 switch (request) {
985 987 case PTRACE_PEEKUSR:
... ... @@ -1030,8 +1032,7 @@
1030 1032  
1031 1033 case PTRACE_READTEXT:
1032 1034 case PTRACE_READDATA:
1033   - ret = ptrace_readdata(child, addr,
1034   - (char __user *)addr2, data);
  1035 + ret = ptrace_readdata(child, addr, addr2p, data);
1035 1036 if (ret == data)
1036 1037 ret = 0;
1037 1038 else if (ret >= 0)
... ... @@ -1040,8 +1041,7 @@
1040 1041  
1041 1042 case PTRACE_WRITETEXT:
1042 1043 case PTRACE_WRITEDATA:
1043   - ret = ptrace_writedata(child, (char __user *) addr2,
1044   - addr, data);
  1044 + ret = ptrace_writedata(child, addr2p, addr, data);
1045 1045 if (ret == data)
1046 1046 ret = 0;
1047 1047 else if (ret >= 0)