hw_breakpoints, powerpc: Fix CONFIG_HAVE_HW_BREAKPOINT off-case in ptrace_set_debugreg()

We make use of ptrace_get_breakpoints() / ptrace_put_breakpoints() to
protect ptrace_set_debugreg() even if CONFIG_HAVE_HW_BREAKPOINT if off.
However in this case, these APIs are not implemented.

To fix this, push the protection down inside the relevant ifdef.
Best would be to export the code inside
CONFIG_HAVE_HW_BREAKPOINT into a standalone function to cleanup
the ifdefury there and call the breakpoint ref API inside. But
as it is more invasive, this should be rather made in an -rc1.

Fixes this build error:

arch/powerpc/kernel/ptrace.c:1594: error: implicit declaration of function 'ptrace_get_breakpoints' make[2]: ***

Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: LPPC <linuxppc-dev@lists.ozlabs.org>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: v2.6.33.. <stable@kernel.org>
Link: http://lkml.kernel.org/r/1304639598-4707-1-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by

Frederic Weisbecker and committed by
Ingo Molnar
925f83c0 4d70230b

+11 -4
+11 -4
arch/powerpc/kernel/ptrace.c
··· 933 if (data && !(data & DABR_TRANSLATION)) 934 return -EIO; 935 #ifdef CONFIG_HAVE_HW_BREAKPOINT 936 bp = thread->ptrace_bps[0]; 937 if ((!data) || !(data & (DABR_DATA_WRITE | DABR_DATA_READ))) { 938 if (bp) { 939 unregister_hw_breakpoint(bp); 940 thread->ptrace_bps[0] = NULL; 941 } 942 return 0; 943 } 944 if (bp) { ··· 952 (DABR_DATA_WRITE | DABR_DATA_READ), 953 &attr.bp_type); 954 ret = modify_user_hw_breakpoint(bp, &attr); 955 - if (ret) 956 return ret; 957 thread->ptrace_bps[0] = bp; 958 thread->dabr = data; 959 return 0; 960 } ··· 972 ptrace_triggered, task); 973 if (IS_ERR(bp)) { 974 thread->ptrace_bps[0] = NULL; 975 return PTR_ERR(bp); 976 } 977 978 #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 979 ··· 1601 } 1602 1603 case PTRACE_SET_DEBUGREG: 1604 - if (ptrace_get_breakpoints(child) < 0) 1605 - return -ESRCH; 1606 ret = ptrace_set_debugreg(child, addr, data); 1607 - ptrace_put_breakpoints(child); 1608 break; 1609 1610 #ifdef CONFIG_PPC64
··· 933 if (data && !(data & DABR_TRANSLATION)) 934 return -EIO; 935 #ifdef CONFIG_HAVE_HW_BREAKPOINT 936 + if (ptrace_get_breakpoints(task) < 0) 937 + return -ESRCH; 938 + 939 bp = thread->ptrace_bps[0]; 940 if ((!data) || !(data & (DABR_DATA_WRITE | DABR_DATA_READ))) { 941 if (bp) { 942 unregister_hw_breakpoint(bp); 943 thread->ptrace_bps[0] = NULL; 944 } 945 + ptrace_put_breakpoints(task); 946 return 0; 947 } 948 if (bp) { ··· 948 (DABR_DATA_WRITE | DABR_DATA_READ), 949 &attr.bp_type); 950 ret = modify_user_hw_breakpoint(bp, &attr); 951 + if (ret) { 952 + ptrace_put_breakpoints(task); 953 return ret; 954 + } 955 thread->ptrace_bps[0] = bp; 956 + ptrace_put_breakpoints(task); 957 thread->dabr = data; 958 return 0; 959 } ··· 965 ptrace_triggered, task); 966 if (IS_ERR(bp)) { 967 thread->ptrace_bps[0] = NULL; 968 + ptrace_put_breakpoints(task); 969 return PTR_ERR(bp); 970 } 971 + 972 + ptrace_put_breakpoints(task); 973 974 #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 975 ··· 1591 } 1592 1593 case PTRACE_SET_DEBUGREG: 1594 ret = ptrace_set_debugreg(child, addr, data); 1595 break; 1596 1597 #ifdef CONFIG_PPC64