linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: snvs: fix uninitialized usage of "lpcr" in snvs_rtc_enable()
@ 2019-10-04 18:52 Yizhuo
  2019-10-04 19:12 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-10-04 18:52 UTC (permalink / raw)
  Cc: Yizhuo, Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel

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.

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtc: snvs: fix uninitialized usage of "lpcr" in snvs_rtc_enable()
  2019-10-04 18:52 [PATCH] rtc: snvs: fix uninitialized usage of "lpcr" in snvs_rtc_enable() Yizhuo
@ 2019-10-04 19:12 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2019-10-04 19:12 UTC (permalink / raw)
  To: Yizhuo; +Cc: Alessandro Zummo, linux-rtc, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-04 19:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 18:52 [PATCH] rtc: snvs: fix uninitialized usage of "lpcr" in snvs_rtc_enable() Yizhuo
2019-10-04 19:12 ` Alexandre Belloni

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).