linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amd/powerplay: ensure loop does not wraparound on decrement
@ 2017-05-17 18:13 Colin King
  2017-05-17 19:30 ` Dan Carpenter
  2017-05-18  7:15 ` walter harms
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2017-05-17 18:13 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Rex Zhu,
	Eric Huang, Huang Rui, amd-gfx, dri-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The current for loop decrements i when it is zero and this causes
a wrap-around back to ~0 because i is unsigned. In the unlikely event
that mask is 0, the loop will run forever. Fix this so we can't loop
forever.

Detected by CoverityScan, CID#1435469 ("Unsigned compared against 0")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
index ad30f5d3a10d..d92c9b9b15be 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
@@ -4199,7 +4199,7 @@ static int vega10_force_clock_level(struct pp_hwmgr *hwmgr,
 		}
 		data->smc_state_table.gfx_boot_level = i;
 
-		for (i = 31; i >= 0; i--) {
+		for (i = 32; --i; ) {
 			if (mask & (1 << i))
 				break;
 		}
-- 
2.11.0

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

* Re: [PATCH] drm/amd/powerplay: ensure loop does not wraparound on decrement
  2017-05-17 18:13 [PATCH] drm/amd/powerplay: ensure loop does not wraparound on decrement Colin King
@ 2017-05-17 19:30 ` Dan Carpenter
  2017-05-18  7:15 ` walter harms
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2017-05-17 19:30 UTC (permalink / raw)
  To: Colin King
  Cc: Alex Deucher, Christian König, David Airlie, Rex Zhu,
	Eric Huang, Huang Rui, amd-gfx, dri-devel, kernel-janitors,
	linux-kernel

I sent a patch for this bug earlier.  There is a second bug later in the
function which my patch fixes as well.

regards,
dan carpenter

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

* Re: [PATCH] drm/amd/powerplay: ensure loop does not wraparound on decrement
  2017-05-17 18:13 [PATCH] drm/amd/powerplay: ensure loop does not wraparound on decrement Colin King
  2017-05-17 19:30 ` Dan Carpenter
@ 2017-05-18  7:15 ` walter harms
  1 sibling, 0 replies; 3+ messages in thread
From: walter harms @ 2017-05-18  7:15 UTC (permalink / raw)
  To: Colin King
  Cc: Alex Deucher, Christian König, David Airlie, Rex Zhu,
	Eric Huang, Huang Rui, amd-gfx, dri-devel, kernel-janitors,
	linux-kernel



Am 17.05.2017 20:13, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The current for loop decrements i when it is zero and this causes
> a wrap-around back to ~0 because i is unsigned. In the unlikely event
> that mask is 0, the loop will run forever. Fix this so we can't loop
> forever.
> 
> Detected by CoverityScan, CID#1435469 ("Unsigned compared against 0")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
> index ad30f5d3a10d..d92c9b9b15be 100644
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
> @@ -4199,7 +4199,7 @@ static int vega10_force_clock_level(struct pp_hwmgr *hwmgr,
>  		}
>  		data->smc_state_table.gfx_boot_level = i;
>  
> -		for (i = 31; i >= 0; i--) {
> +		for (i = 32; --i; ) {
>  			if (mask & (1 << i))
>  				break;
>  		}

nitpicking:
we notices at several points that programmers are bad at counting backwards.
Is there a reason not to start with i=0 ?

re,
 wh

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

end of thread, other threads:[~2017-05-18  7:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17 18:13 [PATCH] drm/amd/powerplay: ensure loop does not wraparound on decrement Colin King
2017-05-17 19:30 ` Dan Carpenter
2017-05-18  7:15 ` walter harms

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