linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: bq256xx: Fix BQ256XX_NUM_WD_VAL and bq256xx_watchdog_time[] overrun
@ 2021-01-13 22:53 Ricardo Rivera-Matos
  2021-01-14 18:43 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Ricardo Rivera-Matos @ 2021-01-13 22:53 UTC (permalink / raw)
  To: sre, linux-pm, linux-kernel; +Cc: dan.carpenter, Ricardo Rivera-Matos

Corrects BQ256XX_NUM_WD_VAL from value of "8" to "4" and fixes the issue when 'i'
is equal to array size then array index over runs the array

Fixes: 32e4978bb92 ("power: supply: bq256xx: Introduce the BQ256XX charger driver")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ricardo Rivera-Matos <r-rivera-matos@ti.com>
---
 drivers/power/supply/bq256xx_charger.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
index dc74c44618af..8414472083a6 100644
--- a/drivers/power/supply/bq256xx_charger.c
+++ b/drivers/power/supply/bq256xx_charger.c
@@ -135,7 +135,7 @@
 #define BQ256XX_NTC_FAULT_COLD		(BIT(2) | BIT(0))
 #define BQ256XX_NTC_FAULT_HOT		(BIT(2) | BIT(1))
 
-#define BQ256XX_NUM_WD_VAL	8
+#define BQ256XX_NUM_WD_VAL	4
 #define BQ256XX_WATCHDOG_MASK	GENMASK(5, 4)
 #define BQ256XX_WATCHDOG_MAX	1600000
 #define BQ256XX_WATCHDOG_DIS	0
@@ -1508,6 +1508,10 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
 	int i;
 
 	for (i = 0; i < BQ256XX_NUM_WD_VAL; i++) {
+		if (bq->watchdog_timer == bq256xx_watchdog_time[i]) {
+			wd_reg_val = i;
+			break;
+		}
 		if (bq->watchdog_timer > bq256xx_watchdog_time[i] &&
 		    bq->watchdog_timer < bq256xx_watchdog_time[i + 1])
 			wd_reg_val = i;
-- 
2.30.0


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

* Re: [PATCH] power: supply: bq256xx: Fix BQ256XX_NUM_WD_VAL and bq256xx_watchdog_time[] overrun
  2021-01-13 22:53 [PATCH] power: supply: bq256xx: Fix BQ256XX_NUM_WD_VAL and bq256xx_watchdog_time[] overrun Ricardo Rivera-Matos
@ 2021-01-14 18:43 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2021-01-14 18:43 UTC (permalink / raw)
  To: Ricardo Rivera-Matos; +Cc: linux-pm, linux-kernel, dan.carpenter

[-- Attachment #1: Type: text/plain, Size: 1564 bytes --]

Hi,

On Wed, Jan 13, 2021 at 04:53:52PM -0600, Ricardo Rivera-Matos wrote:
> Corrects BQ256XX_NUM_WD_VAL from value of "8" to "4" and fixes the issue when 'i'
> is equal to array size then array index over runs the array
> 
> Fixes: 32e4978bb92 ("power: supply: bq256xx: Introduce the BQ256XX charger driver")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Ricardo Rivera-Matos <r-rivera-matos@ti.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/bq256xx_charger.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
> index dc74c44618af..8414472083a6 100644
> --- a/drivers/power/supply/bq256xx_charger.c
> +++ b/drivers/power/supply/bq256xx_charger.c
> @@ -135,7 +135,7 @@
>  #define BQ256XX_NTC_FAULT_COLD		(BIT(2) | BIT(0))
>  #define BQ256XX_NTC_FAULT_HOT		(BIT(2) | BIT(1))
>  
> -#define BQ256XX_NUM_WD_VAL	8
> +#define BQ256XX_NUM_WD_VAL	4
>  #define BQ256XX_WATCHDOG_MASK	GENMASK(5, 4)
>  #define BQ256XX_WATCHDOG_MAX	1600000
>  #define BQ256XX_WATCHDOG_DIS	0
> @@ -1508,6 +1508,10 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
>  	int i;
>  
>  	for (i = 0; i < BQ256XX_NUM_WD_VAL; i++) {
> +		if (bq->watchdog_timer == bq256xx_watchdog_time[i]) {
> +			wd_reg_val = i;
> +			break;
> +		}
>  		if (bq->watchdog_timer > bq256xx_watchdog_time[i] &&
>  		    bq->watchdog_timer < bq256xx_watchdog_time[i + 1])
>  			wd_reg_val = i;
> -- 
> 2.30.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2021-01-14 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 22:53 [PATCH] power: supply: bq256xx: Fix BQ256XX_NUM_WD_VAL and bq256xx_watchdog_time[] overrun Ricardo Rivera-Matos
2021-01-14 18:43 ` Sebastian Reichel

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