* [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table()
@ 2022-05-20 15:02 Dan Carpenter
2022-05-20 15:25 ` Daniel Lezcano
2022-07-28 15:41 ` [thermal: thermal/next] thermal/drivers/k3_j72xx_bandgap: " thermal-bot for Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-05-20 15:02 UTC (permalink / raw)
To: Rafael J. Wysocki, Keerthy
Cc: Daniel Lezcano, Amit Kucheria, Zhang Rui, linux-pm,
kernel-janitors
This while loop exits with "i" set to -1 and so then it sets:
derived_table[-1] = derived_table[0] - 300;
There is no need for this assignment at all. Just delete it.
Fixes: 72b3fc61c752 ("thermal: k3_j72xx_bandgap: Add the bandgap driver support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/thermal/k3_j72xx_bandgap.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
index 64e323158952..a9789b17513b 100644
--- a/drivers/thermal/k3_j72xx_bandgap.c
+++ b/drivers/thermal/k3_j72xx_bandgap.c
@@ -151,8 +151,6 @@ static int prep_lookup_table(struct err_values *err_vals, int *ref_table)
/* 300 milli celsius steps */
while (i--)
derived_table[i] = derived_table[i + 1] - 300;
- /* case 0 */
- derived_table[i] = derived_table[i + 1] - 300;
}
/*
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table()
2022-05-20 15:02 [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table() Dan Carpenter
@ 2022-05-20 15:25 ` Daniel Lezcano
2022-05-21 6:56 ` Dan Carpenter
2022-07-28 15:41 ` [thermal: thermal/next] thermal/drivers/k3_j72xx_bandgap: " thermal-bot for Dan Carpenter
1 sibling, 1 reply; 5+ messages in thread
From: Daniel Lezcano @ 2022-05-20 15:25 UTC (permalink / raw)
To: Dan Carpenter, Rafael J. Wysocki, Keerthy
Cc: Amit Kucheria, Zhang Rui, linux-pm, kernel-janitors
On 20/05/2022 17:02, Dan Carpenter wrote:
> This while loop exits with "i" set to -1 and so then it sets:
Won't it exit with 'i' set to '0' ?
> derived_table[-1] = derived_table[0] - 300;
>
> There is no need for this assignment at all. Just delete it.
>
> Fixes: 72b3fc61c752 ("thermal: k3_j72xx_bandgap: Add the bandgap driver support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/thermal/k3_j72xx_bandgap.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
> index 64e323158952..a9789b17513b 100644
> --- a/drivers/thermal/k3_j72xx_bandgap.c
> +++ b/drivers/thermal/k3_j72xx_bandgap.c
> @@ -151,8 +151,6 @@ static int prep_lookup_table(struct err_values *err_vals, int *ref_table)
> /* 300 milli celsius steps */
> while (i--)
> derived_table[i] = derived_table[i + 1] - 300;
> - /* case 0 */
> - derived_table[i] = derived_table[i + 1] - 300;
> }
>
> /*
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table()
2022-05-20 15:25 ` Daniel Lezcano
@ 2022-05-21 6:56 ` Dan Carpenter
2022-05-21 7:04 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2022-05-21 6:56 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Rafael J. Wysocki, Keerthy, Amit Kucheria, Zhang Rui, linux-pm,
kernel-janitors
On Fri, May 20, 2022 at 05:25:56PM +0200, Daniel Lezcano wrote:
> On 20/05/2022 17:02, Dan Carpenter wrote:
> > This while loop exits with "i" set to -1 and so then it sets:
>
> Won't it exit with 'i' set to '0' ?
>
Wow. You made me worried there. I had to make a test case just to be
sure:
int i = 10;
while (i--)
printf("in %d\n", i);
printf("out %d\n", i);
Yep. Ends on on -1.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table()
2022-05-21 6:56 ` Dan Carpenter
@ 2022-05-21 7:04 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2022-05-21 7:04 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Rafael J. Wysocki, Keerthy, Amit Kucheria, Zhang Rui, linux-pm,
kernel-janitors
On Sat, May 21, 2022 at 09:56:16AM +0300, Dan Carpenter wrote:
> On Fri, May 20, 2022 at 05:25:56PM +0200, Daniel Lezcano wrote:
> > On 20/05/2022 17:02, Dan Carpenter wrote:
> > > This while loop exits with "i" set to -1 and so then it sets:
> >
> > Won't it exit with 'i' set to '0' ?
> >
>
> Wow. You made me worried there. I had to make a test case just to be
> sure:
>
> int i = 10;
>
> while (i--)
> printf("in %d\n", i);
> printf("out %d\n", i);
>
> Yep. Ends on on -1.
I wrote a blog about this a few days back.
https://staticthinking.wordpress.com/2022/05/17/i-or-i/
I really think the most readable way is to say:
while (--i >= 0)
derived_table[i] = derived_table[i + 1] - 300;
Some people like while (i--) because it works on unsigned variables but
that doesn't apply here and "unsigned int i;" is dumb.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* [thermal: thermal/next] thermal/drivers/k3_j72xx_bandgap: Fix array underflow in prep_lookup_table()
2022-05-20 15:02 [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table() Dan Carpenter
2022-05-20 15:25 ` Daniel Lezcano
@ 2022-07-28 15:41 ` thermal-bot for Dan Carpenter
1 sibling, 0 replies; 5+ messages in thread
From: thermal-bot for Dan Carpenter @ 2022-07-28 15:41 UTC (permalink / raw)
To: linux-pm; +Cc: Dan Carpenter, Daniel Lezcano, rui.zhang, amitk
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: cc67ca28cf8b29245b71e01117927ed2793f35b7
Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//cc67ca28cf8b29245b71e01117927ed2793f35b7
Author: Dan Carpenter <dan.carpenter@oracle.com>
AuthorDate: Fri, 20 May 2022 18:02:39 +03:00
Committer: Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Thu, 28 Jul 2022 17:29:48 +02:00
thermal/drivers/k3_j72xx_bandgap: Fix array underflow in prep_lookup_table()
This while loop exits with "i" set to -1 and so then it sets:
derived_table[-1] = derived_table[0] - 300;
There is no need for this assignment at all. Just delete it.
Fixes: 72b3fc61c752 ("thermal: k3_j72xx_bandgap: Add the bandgap driver support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YoetjwcOEzYEFp9b@kili
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
drivers/thermal/k3_j72xx_bandgap.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
index 3a35aa3..27d4cae 100644
--- a/drivers/thermal/k3_j72xx_bandgap.c
+++ b/drivers/thermal/k3_j72xx_bandgap.c
@@ -151,8 +151,6 @@ static int prep_lookup_table(struct err_values *err_vals, int *ref_table)
/* 300 milli celsius steps */
while (i--)
derived_table[i] = derived_table[i + 1] - 300;
- /* case 0 */
- derived_table[i] = derived_table[i + 1] - 300;
}
/*
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-28 15:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-20 15:02 [PATCH] thermal: k3_j72xx_bandgap: Fix array underflow in prep_lookup_table() Dan Carpenter
2022-05-20 15:25 ` Daniel Lezcano
2022-05-21 6:56 ` Dan Carpenter
2022-05-21 7:04 ` Dan Carpenter
2022-07-28 15:41 ` [thermal: thermal/next] thermal/drivers/k3_j72xx_bandgap: " thermal-bot for Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.