kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amd/powerplay: off by one bugs in smu_cmn_to_asic_specific_index()
@ 2020-07-27 13:39 Dan Carpenter
  2020-07-27 19:00 ` Alex Deucher
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-07-27 13:39 UTC (permalink / raw)
  To: Evan Quan
  Cc: David Airlie, kernel-janitors, amd-gfx, Daniel Vetter,
	Alex Deucher, Christian König

These tables have _COUNT number of elements so the comparisons should be
>= instead of > to prevent reading one element beyond the end of the
array.

Fixes: 8264ee69f0d8 ("drm/amd/powerplay: drop unused code")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/amd/powerplay/smu_cmn.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smu_cmn.c b/drivers/gpu/drm/amd/powerplay/smu_cmn.c
index be4b678d0e60..5c23c44c33bd 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_cmn.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_cmn.c
@@ -166,7 +166,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
 
 	switch (type) {
 	case CMN2ASIC_MAPPING_MSG:
-		if (index > SMU_MSG_MAX_COUNT ||
+		if (index >= SMU_MSG_MAX_COUNT ||
 		    !smu->message_map)
 			return -EINVAL;
 
@@ -181,7 +181,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
 		return msg_mapping.map_to;
 
 	case CMN2ASIC_MAPPING_CLK:
-		if (index > SMU_CLK_COUNT ||
+		if (index >= SMU_CLK_COUNT ||
 		    !smu->clock_map)
 			return -EINVAL;
 
@@ -192,7 +192,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
 		return mapping.map_to;
 
 	case CMN2ASIC_MAPPING_FEATURE:
-		if (index > SMU_FEATURE_COUNT ||
+		if (index >= SMU_FEATURE_COUNT ||
 		    !smu->feature_map)
 			return -EINVAL;
 
@@ -203,7 +203,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
 		return mapping.map_to;
 
 	case CMN2ASIC_MAPPING_TABLE:
-		if (index > SMU_TABLE_COUNT ||
+		if (index >= SMU_TABLE_COUNT ||
 		    !smu->table_map)
 			return -EINVAL;
 
@@ -214,7 +214,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
 		return mapping.map_to;
 
 	case CMN2ASIC_MAPPING_PWR:
-		if (index > SMU_POWER_SOURCE_COUNT ||
+		if (index >= SMU_POWER_SOURCE_COUNT ||
 		    !smu->pwr_src_map)
 			return -EINVAL;
 
-- 
2.27.0

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

* Re: [PATCH] drm/amd/powerplay: off by one bugs in smu_cmn_to_asic_specific_index()
  2020-07-27 13:39 [PATCH] drm/amd/powerplay: off by one bugs in smu_cmn_to_asic_specific_index() Dan Carpenter
@ 2020-07-27 19:00 ` Alex Deucher
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Deucher @ 2020-07-27 19:00 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Airlie, kernel-janitors, amd-gfx list, Daniel Vetter,
	Alex Deucher, Evan Quan, Christian König

On Mon, Jul 27, 2020 at 9:42 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> These tables have _COUNT number of elements so the comparisons should be
> >= instead of > to prevent reading one element beyond the end of the
> array.
>
> Fixes: 8264ee69f0d8 ("drm/amd/powerplay: drop unused code")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/amd/powerplay/smu_cmn.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/powerplay/smu_cmn.c b/drivers/gpu/drm/amd/powerplay/smu_cmn.c
> index be4b678d0e60..5c23c44c33bd 100644
> --- a/drivers/gpu/drm/amd/powerplay/smu_cmn.c
> +++ b/drivers/gpu/drm/amd/powerplay/smu_cmn.c
> @@ -166,7 +166,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
>
>         switch (type) {
>         case CMN2ASIC_MAPPING_MSG:
> -               if (index > SMU_MSG_MAX_COUNT ||
> +               if (index >= SMU_MSG_MAX_COUNT ||
>                     !smu->message_map)
>                         return -EINVAL;
>
> @@ -181,7 +181,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
>                 return msg_mapping.map_to;
>
>         case CMN2ASIC_MAPPING_CLK:
> -               if (index > SMU_CLK_COUNT ||
> +               if (index >= SMU_CLK_COUNT ||
>                     !smu->clock_map)
>                         return -EINVAL;
>
> @@ -192,7 +192,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
>                 return mapping.map_to;
>
>         case CMN2ASIC_MAPPING_FEATURE:
> -               if (index > SMU_FEATURE_COUNT ||
> +               if (index >= SMU_FEATURE_COUNT ||
>                     !smu->feature_map)
>                         return -EINVAL;
>
> @@ -203,7 +203,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
>                 return mapping.map_to;
>
>         case CMN2ASIC_MAPPING_TABLE:
> -               if (index > SMU_TABLE_COUNT ||
> +               if (index >= SMU_TABLE_COUNT ||
>                     !smu->table_map)
>                         return -EINVAL;
>
> @@ -214,7 +214,7 @@ int smu_cmn_to_asic_specific_index(struct smu_context *smu,
>                 return mapping.map_to;
>
>         case CMN2ASIC_MAPPING_PWR:
> -               if (index > SMU_POWER_SOURCE_COUNT ||
> +               if (index >= SMU_POWER_SOURCE_COUNT ||
>                     !smu->pwr_src_map)
>                         return -EINVAL;
>
> --
> 2.27.0
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

end of thread, other threads:[~2020-07-27 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 13:39 [PATCH] drm/amd/powerplay: off by one bugs in smu_cmn_to_asic_specific_index() Dan Carpenter
2020-07-27 19:00 ` Alex Deucher

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