Subject: Re: [PATCH] powerpc/eeh: Fix wrong flag passed to eeh_unfreeze_pe()

From: Michael Ellerman <[email-masked]>
Date: Wed, 18 Jan 2017 16:49:58 +1100

Gavin Shan <[email-masked]> writes:

> In __eeh_clear_pe_frozen_state(), we should pass the flag's value
> instead of its address to eeh_unfreeze_pe(). This doesn't introduce
> any problems, but the code is just wrong.

It means any caller that passes false, will be getting the wrong
behaviour. eg. I see at least one call in eeh_reset_device() which
passes false to eeh_clear_pe_frozen_state(), which is then passed to
__eeh_clear_pe_frozen_state().

But I guess you're saying that caller doesn't actually see a bug because
of this?

> This fixes the code by passing flag's value to eeh_unfreeze_pe().
>
> Cc: [email-masked] #3.18+
> Fixes: 5cfb20b96f6 ("powerpc/eeh: Emulate EEH recovery for VFIO devices")
> Signed-off-by: Gavin Shan <[email-masked]>
>
> diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
> index d88573b..fa15fa6 100644
> --- a/arch/powerpc/kernel/eeh_driver.c
> +++ b/arch/powerpc/kernel/eeh_driver.c
> @@ -549,7 +549,7 @@ static void *__eeh_clear_pe_frozen_state(void *data, void *flag)

	bool *clear_sw_state = flag;

>  	int i, rc = 1;
>  
>  	for (i = 0; rc && i < 3; i++)
> -		rc = eeh_unfreeze_pe(pe, clear_sw_state);
> +		rc = eeh_unfreeze_pe(pe, *clear_sw_state);

I think it would be better to just do the dereference once:

	bool clear_sw_state = *(bool *)flag;
	int i, rc = 1;

	for (i = 0; rc && i < 3; i++)
		rc = eeh_unfreeze_pe(pe, clear_sw_state);

cheers