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

signal/openrisc: 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: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Stafford Horne <shorne@gmail.com>
Cc: openrisc@lists.librecores.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+9 -43
+4 -29
arch/openrisc/kernel/traps.c
··· 250 250 251 251 asmlinkage void do_trap(struct pt_regs *regs, unsigned long address) 252 252 { 253 - siginfo_t info; 254 - clear_siginfo(&info); 255 - info.si_signo = SIGTRAP; 256 - info.si_code = TRAP_TRACE; 257 - info.si_addr = (void *)address; 258 - force_sig_info(SIGTRAP, &info, current); 253 + force_sig_fault(SIGTRAP, TRAP_TRACE, (void __user *)address, current); 259 254 260 255 regs->pc += 4; 261 256 } 262 257 263 258 asmlinkage void do_unaligned_access(struct pt_regs *regs, unsigned long address) 264 259 { 265 - siginfo_t info; 266 - 267 260 if (user_mode(regs)) { 268 261 /* Send a SIGBUS */ 269 - clear_siginfo(&info); 270 - info.si_signo = SIGBUS; 271 - info.si_errno = 0; 272 - info.si_code = BUS_ADRALN; 273 - info.si_addr = (void __user *)address; 274 - force_sig_info(SIGBUS, &info, current); 262 + force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)address, current); 275 263 } else { 276 264 printk("KERNEL: Unaligned Access 0x%.8lx\n", address); 277 265 show_registers(regs); ··· 270 282 271 283 asmlinkage void do_bus_fault(struct pt_regs *regs, unsigned long address) 272 284 { 273 - siginfo_t info; 274 - 275 285 if (user_mode(regs)) { 276 286 /* Send a SIGBUS */ 277 - clear_siginfo(&info); 278 - info.si_signo = SIGBUS; 279 - info.si_errno = 0; 280 - info.si_code = BUS_ADRERR; 281 - info.si_addr = (void *)address; 282 - force_sig_info(SIGBUS, &info, current); 287 + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address, current); 283 288 } else { /* Kernel mode */ 284 289 printk("KERNEL: Bus error (SIGBUS) 0x%.8lx\n", address); 285 290 show_registers(regs); ··· 447 466 asmlinkage void do_illegal_instruction(struct pt_regs *regs, 448 467 unsigned long address) 449 468 { 450 - siginfo_t info; 451 469 unsigned int op; 452 470 unsigned int insn = *((unsigned int *)address); 453 471 ··· 467 487 468 488 if (user_mode(regs)) { 469 489 /* Send a SIGILL */ 470 - clear_siginfo(&info); 471 - info.si_signo = SIGILL; 472 - info.si_errno = 0; 473 - info.si_code = ILL_ILLOPC; 474 - info.si_addr = (void *)address; 475 - force_sig_info(SIGBUS, &info, current); 490 + force_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)address, current); 476 491 } else { /* Kernel mode */ 477 492 printk("KERNEL: Illegal instruction (SIGILL) 0x%.8lx\n", 478 493 address);
+5 -14
arch/openrisc/mm/fault.c
··· 52 52 struct task_struct *tsk; 53 53 struct mm_struct *mm; 54 54 struct vm_area_struct *vma; 55 - siginfo_t info; 55 + int si_code; 56 56 int fault; 57 57 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; 58 58 59 - clear_siginfo(&info); 60 59 tsk = current; 61 60 62 61 /* ··· 97 98 } 98 99 99 100 mm = tsk->mm; 100 - info.si_code = SEGV_MAPERR; 101 + si_code = SEGV_MAPERR; 101 102 102 103 /* 103 104 * If we're in an interrupt or have no user ··· 139 140 */ 140 141 141 142 good_area: 142 - info.si_code = SEGV_ACCERR; 143 + si_code = SEGV_ACCERR; 143 144 144 145 /* first do some preliminary protection checks */ 145 146 ··· 213 214 /* User mode accesses just cause a SIGSEGV */ 214 215 215 216 if (user_mode(regs)) { 216 - info.si_signo = SIGSEGV; 217 - info.si_errno = 0; 218 - /* info.si_code has been set above */ 219 - info.si_addr = (void *)address; 220 - force_sig_info(SIGSEGV, &info, tsk); 217 + force_sig_fault(SIGSEGV, si_code, (void __user *)address, tsk); 221 218 return; 222 219 } 223 220 ··· 278 283 * Send a sigbus, regardless of whether we were in kernel 279 284 * or user mode. 280 285 */ 281 - info.si_signo = SIGBUS; 282 - info.si_errno = 0; 283 - info.si_code = BUS_ADRERR; 284 - info.si_addr = (void *)address; 285 - force_sig_info(SIGBUS, &info, tsk); 286 + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address, tsk); 286 287 287 288 /* Kernel mode? Handle exceptions or die */ 288 289 if (!user_mode(regs))