linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Chen Wandun <chenwandun@huawei.com>,
	tyreld@linux.ibm.com, linuxppc-dev@lists.ozlabs.org,
	linux-kernel@vger.kernel.org, mahesh@linux.vnet.ibm.com,
	paulus@samba.org
Cc: chenwandun@huawei.com
Subject: Re: [PATCH] powerpc/pseries: remove variable 'status' set but not used
Date: Tue, 19 Nov 2019 16:53:26 +1100	[thread overview]
Message-ID: <87blt8csyx.fsf@mpe.ellerman.id.au> (raw)
In-Reply-To: <1573873650-62511-1-git-send-email-chenwandun@huawei.com>

Chen Wandun <chenwandun@huawei.com> writes:
> Fixes gcc '-Wunused-but-set-variable' warning:
>
> arch/powerpc/platforms/pseries/ras.c: In function ras_epow_interrupt:
> arch/powerpc/platforms/pseries/ras.c:319:6: warning: variable status set but not used [-Wunused-but-set-variable]

Thanks for the patch.

But it almost certainly is wrong to not check the status.

It's calling firmware and just assuming that the call succeeded. It then
goes on to use the result that should have been written by firmware, but
is now potentially random junk.

So I'd much rather a patch to change it to check the status. 

> diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
> index 1d7f973..4a61d0f 100644
> --- a/arch/powerpc/platforms/pseries/ras.c
> +++ b/arch/powerpc/platforms/pseries/ras.c
> @@ -316,12 +316,11 @@ static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id)
>  /* Handle environmental and power warning (EPOW) interrupts. */
>  static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
>  {
> -	int status;
>  	int state;
>  	int critical;
>  
> -	status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
> -				      &state);
> +	rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
> +			     &state);

This is calling a helper which already does some translation of the
return value, any value < 0 indicates an error.

> @@ -330,12 +329,12 @@ static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
>  
>  	spin_lock(&ras_log_buf_lock);
>  
> -	status = rtas_call(ras_check_exception_token, 6, 1, NULL,
> -			   RTAS_VECTOR_EXTERNAL_INTERRUPT,
> -			   virq_to_hw(irq),
> -			   RTAS_EPOW_WARNING,
> -			   critical, __pa(&ras_log_buf),
> -				rtas_get_error_log_max());
> +	rtas_call(ras_check_exception_token, 6, 1, NULL,
> +		  RTAS_VECTOR_EXTERNAL_INTERRUPT,
> +		  virq_to_hw(irq),
> +		  RTAS_EPOW_WARNING,
> +		  critical, __pa(&ras_log_buf),
> +		  rtas_get_error_log_max());

This is directly calling firmware.

As documented in LoPAPR, a negative status indicates an error, 0
indicates a new error log was found (ie. the function should continue),
or 1 there was no error log (ie. nothing to do).

cheers

>  	log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
>  
> -- 
> 2.7.4

  reply	other threads:[~2019-11-19  5:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-16  3:07 [PATCH] powerpc/pseries: remove variable 'status' set but not used Chen Wandun
2019-11-19  5:53 ` Michael Ellerman [this message]
2019-11-20 21:34   ` Tyrel Datwyler
2019-11-22 10:53     ` Chen Wandun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87blt8csyx.fsf@mpe.ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=chenwandun@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=paulus@samba.org \
    --cc=tyreld@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).