Skip to contentSkip to conversation

drm/msm/a6xx: Fix missing ARRAY_SIZE() check

PATCH In review Rob Clark 2 participants 4 messages Mar 4, 2022 – Mar 5, 2022

Subsystems (4)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm/msm/a6xx: Fix missing ARRAY_SIZE() check

From: Rob Clark <[email protected]>

Fixes f6d62d091cfd ("drm/msm/a6xx: add support for Adreno 660 GPU")
---
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +1 -0
index 02b47977b5c3..6406d8c3411a 100644
@@ -687,6 +687,7 @@ static void a6xx_set_cp_protect(struct msm_gpu *gpu)
 
 	BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
 	BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
+	BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);
 
 	if (adreno_is_a650(adreno_gpu)) {
 		regs = a650_protect;
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Rob Clark

From: Rob Clark <[email protected]>

Fixes f6d62d091cfd ("drm/msm/a6xx: add support for Adreno 660 GPU")

However see the comment below.

drivers/gpu/drm/msm/adreno/a6xx_gpu.c static void a6xx_set_cp_protect(struct msm_gpu *gpu) · line 690

Quoted 13 lines
---
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +1 -0
index 02b47977b5c3..6406d8c3411a 100644
@@ -687,6 +687,7 @@ static void a6xx_set_cp_protect(struct msm_gpu *gpu)
 
        BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
        BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
+       BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);

The magic number 32 and 48 are repeated through this code. I'd suggest to define them and use defined names.
It can come up as a separate commit.

Quoted 5 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0 -1
        if (adreno_is_a650(adreno_gpu)) {
                regs = a650_protect;
--

2.35.1

Signature · 2 lines
With best wishes
Dmitry
author
#2 lore raw
Quoted 21 lines · Dmitry Baryshkov
Quoted 5 lines · Rob Clark

From: Rob Clark <[email protected]>

Fixes f6d62d091cfd ("drm/msm/a6xx: add support for Adreno 660 GPU")

However see the comment below.

Quoted 10 lines
---
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0 -0
index 02b47977b5c3..6406d8c3411a 100644
@@ -687,6 +687,7 @@ static void a6xx_set_cp_protect(struct msm_gpu *gpu)
 
Quoted 8 lines

drivers/gpu/drm/msm/adreno/a6xx_gpu.c static void a6xx_set_cp_protect(struct msm_gpu *gpu) · line 690

Quoted 3 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +1 -0
        BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
        BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
+       BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);

The magic number 32 and 48 are repeated through this code. I'd suggest to define them and use defined names.
It can come up as a separate commit.

Or perhaps instead:
----

(quoted diff) +0 -0

b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
index 6406d8c3411a..58c371930fb4 100644

drivers/gpu/drm/msm/adreno/a6xx_gpu.c +8 -5
@@ -683,20 +683,23 @@ static void a6xx_set_cp_protect(struct msm_gpu *gpu)
 {
        struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
        const u32 *regs = a6xx_protect;
-       unsigned i, count = ARRAY_SIZE(a6xx_protect), count_max = 32;
-
-       BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
-       BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
-       BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);
+       unsigned i, count, count_max;
 
        if (adreno_is_a650(adreno_gpu)) {
                regs = a650_protect;
                count = ARRAY_SIZE(a650_protect);
                count_max = 48;
+               BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
        } else if (adreno_is_a660_family(adreno_gpu)) {
                regs = a660_protect;
                count = ARRAY_SIZE(a660_protect);
                count_max = 48;
+               BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);
+       } else {
+               regs = a6xx_protect;
+               count = ARRAY_SIZE(a6xx_protect);
+               count_max = 32;
+               BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
        }
 
        /*

----

that moves each of the two uses of constant together.. adding three #defines each used only twice seems a bit silly, IMHO

BR,
-R

Reviewed-by
#3 lore raw
Quoted 33 lines · Rob Clark
Quoted 21 lines · Dmitry Baryshkov
Quoted 5 lines · Rob Clark

From: Rob Clark <[email protected]>

Fixes f6d62d091cfd ("drm/msm/a6xx: add support for Adreno 660 GPU")

However see the comment below.

Quoted 10 lines
---
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0 -0
index 02b47977b5c3..6406d8c3411a 100644
@@ -687,6 +687,7 @@ static void a6xx_set_cp_protect(struct msm_gpu *gpu)
 
Quoted 8 lines

drivers/gpu/drm/msm/adreno/a6xx_gpu.c static void a6xx_set_cp_protect(struct msm_gpu *gpu) · line 690

Quoted 3 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +1 -0
        BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
        BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
+       BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);

The magic number 32 and 48 are repeated through this code. I'd suggest to define them and use defined names.
It can come up as a separate commit.

Quoted 1 line

Or perhaps instead:

IMO this is much better.

Quoted 42 lines

----

drivers/gpu/drm/msm/adreno/a6xx_gpu.c +8 -6
index 6406d8c3411a..58c371930fb4 100644
@@ -683,20 +683,23 @@ static void a6xx_set_cp_protect(struct msm_gpu *gpu)
 {
        struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
        const u32 *regs = a6xx_protect;
-       unsigned i, count = ARRAY_SIZE(a6xx_protect), count_max = 32;
-
-       BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
-       BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
-       BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);
+       unsigned i, count, count_max;
 
        if (adreno_is_a650(adreno_gpu)) {
                regs = a650_protect;
                count = ARRAY_SIZE(a650_protect);
                count_max = 48;
+               BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
        } else if (adreno_is_a660_family(adreno_gpu)) {
                regs = a660_protect;
                count = ARRAY_SIZE(a660_protect);
                count_max = 48;
+               BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);
+       } else {
+               regs = a6xx_protect;
+               count = ARRAY_SIZE(a6xx_protect);
+               count_max = 32;
+               BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
        }
 
        /*
----

that moves each of the two uses of constant together.. adding three #defines each used only twice seems a bit silly, IMHO

BR,
-R

Signature · 2 lines
With best wishes
Dmitry