Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

signal/nds32: Use force_sig_fault where appropriate

Filling in struct siginfo before calling force_sig_info a tedious and
error prone process, where once in a great while the wrong fields
are filled out, and siginfo has been inconsistently cleared.

Simplify this process by using the helper force_sig_fault. Which
takes as a parameters all of the information it needs, ensures
all of the fiddly bits of filling in struct siginfo are done properly
and then calls force_sig_info.

In short about a 5 line reduction in code for every time force_sig_info
is called, which makes the calling function clearer.

Cc: Greentime Hu <green.hu@gmail.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Acked-by: Vincent Chen <deanbo422@gmail.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+9 -30
+4 -16
arch/nds32/kernel/traps.c
··· 222 222 223 223 int bad_syscall(int n, struct pt_regs *regs) 224 224 { 225 - siginfo_t info; 226 - 227 225 if (current->personality != PER_LINUX) { 228 226 send_sig(SIGSEGV, current, 1); 229 227 return regs->uregs[0]; 230 228 } 231 229 232 - clear_siginfo(&info); 233 - info.si_signo = SIGILL; 234 - info.si_errno = 0; 235 - info.si_code = ILL_ILLTRP; 236 - info.si_addr = (void __user *)instruction_pointer(regs) - 4; 237 - 238 - force_sig_info(SIGILL, &info, current); 230 + force_sig_fault(SIGILL, ILL_ILLTRP, 231 + (void __user *)instruction_pointer(regs) - 4, current); 239 232 die_if_kernel("Oops - bad syscall", regs, n); 240 233 return regs->uregs[0]; 241 234 } ··· 281 288 void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, 282 289 int error_code, int si_code) 283 290 { 284 - struct siginfo info; 285 - 286 291 tsk->thread.trap_no = ENTRY_DEBUG_RELATED; 287 292 tsk->thread.error_code = error_code; 288 293 289 - clear_siginfo(&info); 290 - info.si_signo = SIGTRAP; 291 - info.si_code = si_code; 292 - info.si_addr = (void __user *)instruction_pointer(regs); 293 - force_sig_info(SIGTRAP, &info, tsk); 294 + force_sig_fault(SIGTRAP, si_code, 295 + (void __user *)instruction_pointer(regs), tsk); 294 296 } 295 297 296 298 void do_debug_trap(unsigned long entry, unsigned long addr,
+5 -14
arch/nds32/mm/fault.c
··· 72 72 struct task_struct *tsk; 73 73 struct mm_struct *mm; 74 74 struct vm_area_struct *vma; 75 - siginfo_t info; 75 + int si_code; 76 76 int fault; 77 77 unsigned int mask = VM_READ | VM_WRITE | VM_EXEC; 78 78 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; 79 79 80 - clear_siginfo(&info); 81 80 error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE); 82 81 tsk = current; 83 82 mm = tsk->mm; 84 - info.si_code = SEGV_MAPERR; 83 + si_code = SEGV_MAPERR; 85 84 /* 86 85 * We fault-in kernel-space virtual memory on-demand. The 87 86 * 'reference' page table is init_mm.pgd. ··· 161 162 */ 162 163 163 164 good_area: 164 - info.si_code = SEGV_ACCERR; 165 + si_code = SEGV_ACCERR; 165 166 166 167 /* first do some preliminary protection checks */ 167 168 if (entry == ENTRY_PTE_NOT_PRESENT) { ··· 266 267 tsk->thread.address = addr; 267 268 tsk->thread.error_code = error_code; 268 269 tsk->thread.trap_no = entry; 269 - info.si_signo = SIGSEGV; 270 - info.si_errno = 0; 271 - /* info.si_code has been set above */ 272 - info.si_addr = (void *)addr; 273 - force_sig_info(SIGSEGV, &info, tsk); 270 + force_sig_fault(SIGSEGV, si_code, (void __user *)addr, tsk); 274 271 return; 275 272 } 276 273 ··· 335 340 tsk->thread.address = addr; 336 341 tsk->thread.error_code = error_code; 337 342 tsk->thread.trap_no = entry; 338 - info.si_signo = SIGBUS; 339 - info.si_errno = 0; 340 - info.si_code = BUS_ADRERR; 341 - info.si_addr = (void *)addr; 342 - force_sig_info(SIGBUS, &info, tsk); 343 + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)addr, tsk); 343 344 344 345 return; 345 346