drm/amd/display: Correctly initialize some memory in get_available_dsc_slices()

Message ID f7953bb41b7d5e28ec6bc3abfa06c8aaa0193ca4.1682409190.git.christophe.jaillet@wanadoo.fr
State New
Headers
Series drm/amd/display: Correctly initialize some memory in get_available_dsc_slices() |

Commit Message

Christophe JAILLET April 25, 2023, 7:53 a.m. UTC
  The intent here is to clear the 'available_slices' buffer before setting
some values in it.

This is an array of int, so in order to fully initialize it, we must clear
MIN_AVAILABLE_SLICES_SIZE * sizeof(int) bytes.

Compute the right length of the buffer when calling memset().

Fixes: 97bda0322b8a ("drm/amd/display: Add DSC support for Navi (v2)")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
NOT even compile-tested.

make -j7  drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.o

on my setup, it fails with:
  CC      drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.o
drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c:27:10: fatal error: dc_hw_types.h: Aucun fichier ou dossier de ce type
   27 | #include "dc_hw_types.h"
      |          ^~~~~~~~~~~~~~~

I've not investigated why.
---
 drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Hamza Mahfooz April 26, 2023, 5:28 p.m. UTC | #1
On 4/25/23 03:53, Christophe JAILLET wrote:
> The intent here is to clear the 'available_slices' buffer before setting
> some values in it.
> 
> This is an array of int, so in order to fully initialize it, we must clear
> MIN_AVAILABLE_SLICES_SIZE * sizeof(int) bytes.
> 
> Compute the right length of the buffer when calling memset().
> 
> Fixes: 97bda0322b8a ("drm/amd/display: Add DSC support for Navi (v2)")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> NOT even compile-tested.
> 
> make -j7  drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.o
> 
> on my setup, it fails with:
>    CC      drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.o
> drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c:27:10: fatal error: dc_hw_types.h: Aucun fichier ou dossier de ce type
>     27 | #include "dc_hw_types.h"
>        |          ^~~~~~~~~~~~~~~
> 
> I've not investigated why.
> ---
>   drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c b/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
> index b9a05bb025db..1d7384b2be28 100644
> --- a/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
> +++ b/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
> @@ -645,7 +645,7 @@ static int get_available_dsc_slices(union dsc_enc_slice_caps slice_caps, int *av
>   {
>   	int idx = 0;
>   
> -	memset(available_slices, -1, MIN_AVAILABLE_SLICES_SIZE);
> +	memset(available_slices, -1, MIN_AVAILABLE_SLICES_SIZE * sizeof(*available_slices));

Actually, I believe we can drop this memset(). Since,
get_available_dsc_slices() returns the number of indices set, and all of
the users of get_available_dsc_slices() don't cross that bound.

>   
>   	if (slice_caps.bits.NUM_SLICES_1)
>   		available_slices[idx++] = 1;
  

Patch

diff --git a/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c b/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
index b9a05bb025db..1d7384b2be28 100644
--- a/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
+++ b/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
@@ -645,7 +645,7 @@  static int get_available_dsc_slices(union dsc_enc_slice_caps slice_caps, int *av
 {
 	int idx = 0;
 
-	memset(available_slices, -1, MIN_AVAILABLE_SLICES_SIZE);
+	memset(available_slices, -1, MIN_AVAILABLE_SLICES_SIZE * sizeof(*available_slices));
 
 	if (slice_caps.bits.NUM_SLICES_1)
 		available_slices[idx++] = 1;