mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Yizhuo <yzhai003@ucr.edu>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rtc: snvs: fix uninitialized usage of "lpcr" in snvs_rtc_enable()
Date: Fri, 4 Oct 2019 21:12:02 +0200	[thread overview]
Message-ID: <20191004191202.GB4106@piout.net> (raw)
In-Reply-To: <20191004185206.7466-1-yzhai003@ucr.edu>

On 04/10/2019 11:52:06-0700, Yizhuo wrote:
> Inside function snvs_rtc_enable(), variable "lpcr" could be
> uninitialized if regmap_read() returns -EINVAL. However,"lpcr"
> is used later in the if statement, which is potentially unsafe.
> 

This is not true, regmap_read either lock up the cpu or not fail in this
driver.

> Similar cases happened in function snvs_rtc_irq_handler() with
> variable "lpsr" and function snvs_rtc_read_alarm() with variables
> "lptar", "lpsr". The patch for those two are not easy since
> -EINVAL is not an acceptable return value for these functions.
> 
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> ---
>  drivers/rtc/rtc-snvs.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
> index 757f4daa7181..dadcc3e193b2 100644
> --- a/drivers/rtc/rtc-snvs.c
> +++ b/drivers/rtc/rtc-snvs.c
> @@ -124,12 +124,16 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
>  {
>  	int timeout = 1000;
>  	u32 lpcr;
> +	int ret;
>  
>  	regmap_update_bits(data->regmap, data->offset + SNVS_LPCR, SNVS_LPCR_SRTC_ENV,
>  			   enable ? SNVS_LPCR_SRTC_ENV : 0);
>  
>  	while (--timeout) {
> -		regmap_read(data->regmap, data->offset + SNVS_LPCR, &lpcr);
> +		ret = regmap_read(data->regmap,
> +					data->offset + SNVS_LPCR, &lpcr);
> +		if (ret)
> +			return ret;
>  
>  		if (enable) {
>  			if (lpcr & SNVS_LPCR_SRTC_ENV)
> -- 
> 2.17.1
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

      reply	other threads:[~2019-10-04 19:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04 18:52 Yizhuo
2019-10-04 19:12 ` Alexandre Belloni [this message]

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=20191004191202.GB4106@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=yzhai003@ucr.edu \
    /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

all inboxes | Powered by JetHome®