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

signal/parisc: 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: James Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: linux-parisc@vger.kernel.org
Acked-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+39 -85
+3 -8
arch/parisc/kernel/ptrace.c
··· 76 76 set_tsk_thread_flag(task, TIF_SINGLESTEP); 77 77 78 78 if (pa_psw(task)->n) { 79 - struct siginfo si; 80 - 81 79 /* Nullified, just crank over the queue. */ 82 80 task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1]; 83 81 task_regs(task)->iasq[0] = task_regs(task)->iasq[1]; ··· 88 90 ptrace_disable(task); 89 91 /* Don't wake up the task, but let the 90 92 parent know something happened. */ 91 - clear_siginfo(&si); 92 - si.si_code = TRAP_TRACE; 93 - si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3); 94 - si.si_signo = SIGTRAP; 95 - si.si_errno = 0; 96 - force_sig_info(SIGTRAP, &si, task); 93 + force_sig_fault(SIGTRAP, TRAP_TRACE, 94 + (void __user *) (task_regs(task)->iaoq[0] & ~3), 95 + task); 97 96 /* notify_parent(task, SIGCHLD); */ 98 97 return; 99 98 }
+20 -43
arch/parisc/kernel/traps.c
··· 297 297 #define GDB_BREAK_INSN 0x10004 298 298 static void handle_gdb_break(struct pt_regs *regs, int wot) 299 299 { 300 - struct siginfo si; 301 - 302 - clear_siginfo(&si); 303 - si.si_signo = SIGTRAP; 304 - si.si_errno = 0; 305 - si.si_code = wot; 306 - si.si_addr = (void __user *) (regs->iaoq[0] & ~3); 307 - force_sig_info(SIGTRAP, &si, current); 300 + force_sig_fault(SIGTRAP, wot, 301 + (void __user *) (regs->iaoq[0] & ~3), current); 308 302 } 309 303 310 304 static void handle_break(struct pt_regs *regs) ··· 482 488 { 483 489 unsigned long fault_address = 0; 484 490 unsigned long fault_space = 0; 485 - struct siginfo si; 491 + int si_code; 486 492 487 - clear_siginfo(&si); 488 493 if (code == 1) 489 494 pdc_console_restart(); /* switch back to pdc if HPMC */ 490 495 else ··· 566 573 case 8: 567 574 /* Illegal instruction trap */ 568 575 die_if_kernel("Illegal instruction", regs, code); 569 - si.si_code = ILL_ILLOPC; 576 + si_code = ILL_ILLOPC; 570 577 goto give_sigill; 571 578 572 579 case 9: ··· 577 584 case 10: 578 585 /* Privileged operation trap */ 579 586 die_if_kernel("Privileged operation", regs, code); 580 - si.si_code = ILL_PRVOPC; 587 + si_code = ILL_PRVOPC; 581 588 goto give_sigill; 582 589 583 590 case 11: ··· 600 607 } 601 608 602 609 die_if_kernel("Privileged register usage", regs, code); 603 - si.si_code = ILL_PRVREG; 610 + si_code = ILL_PRVREG; 604 611 give_sigill: 605 - si.si_signo = SIGILL; 606 - si.si_errno = 0; 607 - si.si_addr = (void __user *) regs->iaoq[0]; 608 - force_sig_info(SIGILL, &si, current); 612 + force_sig_fault(SIGILL, si_code, 613 + (void __user *) regs->iaoq[0], current); 609 614 return; 610 615 611 616 case 12: 612 617 /* Overflow Trap, let the userland signal handler do the cleanup */ 613 - si.si_signo = SIGFPE; 614 - si.si_code = FPE_INTOVF; 615 - si.si_addr = (void __user *) regs->iaoq[0]; 616 - force_sig_info(SIGFPE, &si, current); 618 + force_sig_fault(SIGFPE, FPE_INTOVF, 619 + (void __user *) regs->iaoq[0], current); 617 620 return; 618 621 619 622 case 13: ··· 617 628 The condition succeeds in an instruction which traps 618 629 on condition */ 619 630 if(user_mode(regs)){ 620 - si.si_signo = SIGFPE; 621 631 /* Let userspace app figure it out from the insn pointed 622 632 * to by si_addr. 623 633 */ 624 - si.si_code = FPE_CONDTRAP; 625 - si.si_addr = (void __user *) regs->iaoq[0]; 626 - force_sig_info(SIGFPE, &si, current); 634 + force_sig_fault(SIGFPE, FPE_CONDTRAP, 635 + (void __user *) regs->iaoq[0], current); 627 636 return; 628 637 } 629 638 /* The kernel doesn't want to handle condition codes */ ··· 730 743 return; 731 744 732 745 die_if_kernel("Protection id trap", regs, code); 733 - si.si_code = SEGV_MAPERR; 734 - si.si_signo = SIGSEGV; 735 - si.si_errno = 0; 736 - if (code == 7) 737 - si.si_addr = (void __user *) regs->iaoq[0]; 738 - else 739 - si.si_addr = (void __user *) regs->ior; 740 - force_sig_info(SIGSEGV, &si, current); 746 + force_sig_fault(SIGSEGV, SEGV_MAPERR, 747 + (code == 7)? 748 + ((void __user *) regs->iaoq[0]) : 749 + ((void __user *) regs->ior), current); 741 750 return; 742 751 743 752 case 28: ··· 747 764 "handle_interruption() pid=%d command='%s'\n", 748 765 task_pid_nr(current), current->comm); 749 766 /* SIGBUS, for lack of a better one. */ 750 - si.si_signo = SIGBUS; 751 - si.si_code = BUS_OBJERR; 752 - si.si_errno = 0; 753 - si.si_addr = (void __user *) regs->ior; 754 - force_sig_info(SIGBUS, &si, current); 767 + force_sig_fault(SIGBUS, BUS_OBJERR, 768 + (void __user *)regs->ior, current); 755 769 return; 756 770 } 757 771 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC); ··· 763 783 "User fault %d on space 0x%08lx, pid=%d command='%s'\n", 764 784 code, fault_space, 765 785 task_pid_nr(current), current->comm); 766 - si.si_signo = SIGSEGV; 767 - si.si_errno = 0; 768 - si.si_code = SEGV_MAPERR; 769 - si.si_addr = (void __user *) regs->ior; 770 - force_sig_info(SIGSEGV, &si, current); 786 + force_sig_fault(SIGSEGV, SEGV_MAPERR, 787 + (void __user *)regs->ior, current); 771 788 return; 772 789 } 773 790 }
+4 -12
arch/parisc/kernel/unaligned.c
··· 452 452 unsigned long newbase = R1(regs->iir)?regs->gr[R1(regs->iir)]:0; 453 453 int modify = 0; 454 454 int ret = ERR_NOTHANDLED; 455 - struct siginfo si; 456 455 register int flop=0; /* true if this is a flop */ 457 456 458 - clear_siginfo(&si); 459 457 __inc_irq_stat(irq_unaligned_count); 460 458 461 459 /* log a message with pacing */ ··· 689 691 690 692 if (ret == ERR_PAGEFAULT) 691 693 { 692 - si.si_signo = SIGSEGV; 693 - si.si_errno = 0; 694 - si.si_code = SEGV_MAPERR; 695 - si.si_addr = (void __user *)regs->ior; 696 - force_sig_info(SIGSEGV, &si, current); 694 + force_sig_fault(SIGSEGV, SEGV_MAPERR, 695 + (void __user *)regs->ior, current); 697 696 } 698 697 else 699 698 { 700 699 force_sigbus: 701 700 /* couldn't handle it ... */ 702 - si.si_signo = SIGBUS; 703 - si.si_errno = 0; 704 - si.si_code = BUS_ADRALN; 705 - si.si_addr = (void __user *)regs->ior; 706 - force_sig_info(SIGBUS, &si, current); 701 + force_sig_fault(SIGBUS, BUS_ADRALN, 702 + (void __user *)regs->ior, current); 707 703 } 708 704 709 705 return;
+2 -7
arch/parisc/math-emu/driver.c
··· 81 81 handle_fpe(struct pt_regs *regs) 82 82 { 83 83 extern void printbinary(unsigned long x, int nbits); 84 - struct siginfo si; 85 84 unsigned int orig_sw, sw; 86 85 int signalcode; 87 86 /* need an intermediate copy of float regs because FPU emulation ··· 92 93 */ 93 94 __u64 frcopy[36]; 94 95 95 - clear_siginfo(&si); 96 96 memcpy(frcopy, regs->fr, sizeof regs->fr); 97 97 frcopy[32] = 0; 98 98 ··· 116 118 117 119 memcpy(regs->fr, frcopy, sizeof regs->fr); 118 120 if (signalcode != 0) { 119 - si.si_signo = signalcode >> 24; 120 - si.si_errno = 0; 121 - si.si_code = signalcode & 0xffffff; 122 - si.si_addr = (void __user *) regs->iaoq[0]; 123 - force_sig_info(si.si_signo, &si, current); 121 + force_sig_fault(signalcode >> 24, signalcode & 0xffffff, 122 + (void __user *) regs->iaoq[0], current); 124 123 return -1; 125 124 } 126 125
+10 -15
arch/parisc/mm/fault.c
··· 353 353 up_read(&mm->mmap_sem); 354 354 355 355 if (user_mode(regs)) { 356 - struct siginfo si; 356 + int signo, si_code; 357 357 358 - clear_siginfo(&si); 359 358 switch (code) { 360 359 case 15: /* Data TLB miss fault/Data page fault */ 361 360 /* send SIGSEGV when outside of vma */ 362 361 if (!vma || 363 362 address < vma->vm_start || address >= vma->vm_end) { 364 - si.si_signo = SIGSEGV; 365 - si.si_code = SEGV_MAPERR; 363 + signo = SIGSEGV; 364 + si_code = SEGV_MAPERR; 366 365 break; 367 366 } 368 367 369 368 /* send SIGSEGV for wrong permissions */ 370 369 if ((vma->vm_flags & acc_type) != acc_type) { 371 - si.si_signo = SIGSEGV; 372 - si.si_code = SEGV_ACCERR; 370 + signo = SIGSEGV; 371 + si_code = SEGV_ACCERR; 373 372 break; 374 373 } 375 374 ··· 376 377 /* fall through */ 377 378 case 17: /* NA data TLB miss / page fault */ 378 379 case 18: /* Unaligned access - PCXS only */ 379 - si.si_signo = SIGBUS; 380 - si.si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR; 380 + signo = SIGBUS; 381 + si_code = (code == 18) ? BUS_ADRALN : BUS_ADRERR; 381 382 break; 382 383 case 16: /* Non-access instruction TLB miss fault */ 383 384 case 26: /* PCXL: Data memory access rights trap */ 384 385 default: 385 - si.si_signo = SIGSEGV; 386 - si.si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR; 386 + signo = SIGSEGV; 387 + si_code = (code == 26) ? SEGV_ACCERR : SEGV_MAPERR; 387 388 break; 388 389 } 389 - 390 390 #ifdef CONFIG_MEMORY_FAILURE 391 391 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) { 392 392 unsigned int lsb = 0; ··· 407 409 return; 408 410 } 409 411 #endif 410 - 411 412 show_signal_msg(regs, code, address, tsk, vma); 412 413 413 - si.si_errno = 0; 414 - si.si_addr = (void __user *) address; 415 - force_sig_info(si.si_signo, &si, current); 414 + force_sig_fault(signo, si_code, (void __user *) address, current); 416 415 return; 417 416 } 418 417