Re: [PATCH] x86/mm: fix an unused variable "tsk" warning

From: Dave Hansen
Date: Fri May 31 2019 - 16:57:46 EST


On 5/31/19 1:38 PM, Qian Cai wrote:
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1015,7 +1015,9 @@ static inline bool bad_area_access_from_pkeys(unsigned long error_code,
> do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
> vm_fault_t fault)
> {
> +#ifdef CONFIG_MEMORY_FAILURE
> struct task_struct *tsk = current;
> +#endif
>
> /* Kernel mode? Handle exceptions or die: */
> if (!(error_code & X86_PF_USER)) {

Ick. I'd much rather see this:

#ifdef CONFIG_MEMORY_FAILURE
if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
unsigned lsb = 0;

become:

if (IS_ENABLED(CONFIG_MEMORY_FAILURE) &&
(fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE))) {
unsigned lsb = 0;

than add another #ifdef.

BTW, which tree are you doing this against? Current -linus uses tsk in
the last line of do_sigbus():

force_sig_fault(SIGBUS, BUS_ADRERR, ..., tsk);