Skip to contentSkip to conversation

drm/kmb: Avoid warnings on impossible plane_id

PATCH In review Kees Cook 2 participants 4 messages Aug 25, 2021 – Sep 7, 2021

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 drm/kmb: Avoid warnings on impossible plane_id

KMB_MAX_PLANES is defined as 1, yet kmb_plane_atomic_disable() had code for writing beyond 1. It is gated by a WARN_ON() that would skip it, though, but under some compiler versions, poor Dead Code Elimination wasn't optimizing away the unused switch cases, leading to array bounds warnings when building with -Warray-bounds:

drivers/gpu/drm/kmb/kmb_plane.c:135:20: warning: array subscript 3 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] drivers/gpu/drm/kmb/kmb_plane.c:132:20: warning: array subscript 2 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] drivers/gpu/drm/kmb/kmb_plane.c:129:20: warning: array subscript 1 is above array bounds of 'struct layer_status[1]' [-Warray-bounds]

Instead, just remove the switch statement entirely and adjust the index type to match the struct "id" member.

Cc Anitha Chrisanthus <[email protected]>
Cc Edmund Dea <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Fixes 7f7b96a8a0a1 ("drm/kmb: Add support for KeemBay Display")
---
 drivers/gpu/drm/kmb/kmb_plane.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/kmb/kmb_plane.c +2 -16
index ecee6782612d..3d46e756f2fe 100644
@@ -113,7 +113,7 @@ static void kmb_plane_atomic_disable(struct drm_plane *plane,
 				     struct drm_atomic_state *state)
 {
 	struct kmb_plane *kmb_plane = to_kmb_plane(plane);
-	int plane_id = kmb_plane->id;
+	unsigned char plane_id = kmb_plane->id;
 	struct kmb_drm_private *kmb;
 
 	kmb = to_kmb(plane->dev);
@@ -121,21 +121,7 @@ static void kmb_plane_atomic_disable(struct drm_plane *plane,
 	if (WARN_ON(plane_id >= KMB_MAX_PLANES))
 		return;
 
-	switch (plane_id) {
-	case LAYER_0:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE;
-		break;
-	case LAYER_1:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL2_ENABLE;
-		break;
-	case LAYER_2:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL1_ENABLE;
-		break;
-	case LAYER_3:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL2_ENABLE;
-		break;
-	}
-
+	kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE;
 	kmb->plane_status[plane_id].disable = true;
 }
 
Signature · 1 line
2.30.2
#1 lore raw

Hi Kees,
Thanks for your patch.
The switch statement is needed for multiple planes which is already approved in this patch series.
https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/

This patch has dependencies on the previous patches in this series, and we are waiting for reviews on those before this can be checked in.

Thanks,
Anitha

Quoted 79 lines

-----Original Message-----
From: Kees Cook <[email protected]>
Sent: Wednesday, August 25, 2021 11:18 AM
To: Chrisanthus, Anitha <[email protected]>
Cc: Kees Cook <[email protected]>; Dea, Edmund J <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; [email protected]; Sam Ravnborg <[email protected]>; [email protected]; linux- [email protected]
Subject: [PATCH] drm/kmb: Avoid warnings on impossible plane_id

KMB_MAX_PLANES is defined as 1, yet kmb_plane_atomic_disable() had code for writing beyond 1. It is gated by a WARN_ON() that would skip it, though, but under some compiler versions, poor Dead Code Elimination wasn't optimizing away the unused switch cases, leading to array bounds warnings when building with -Warray-bounds:

drivers/gpu/drm/kmb/kmb_plane.c:135:20: warning: array subscript 3 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] drivers/gpu/drm/kmb/kmb_plane.c:132:20: warning: array subscript 2 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] drivers/gpu/drm/kmb/kmb_plane.c:129:20: warning: array subscript 1 is above array bounds of 'struct layer_status[1]' [-Warray-bounds]

Instead, just remove the switch statement entirely and adjust the index type to match the struct "id" member.

Cc Anitha Chrisanthus <[email protected]>
Cc Edmund Dea <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Fixes 7f7b96a8a0a1 ("drm/kmb: Add support for KeemBay Display")
---
 drivers/gpu/drm/kmb/kmb_plane.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/kmb/kmb_plane.c +1 -1
index ecee6782612d..3d46e756f2fe 100644
@@ -113,7 +113,7 @@ static void kmb_plane_atomic_disable(struct
 drm_plane *plane,
 				     struct drm_atomic_state *state)
 {
 	struct kmb_plane *kmb_plane = to_kmb_plane(plane);
-	int plane_id = kmb_plane->id;
+	unsigned char plane_id = kmb_plane->id;
 	struct kmb_drm_private *kmb;
 
drivers/gpu/drm/kmb/kmb_plane.c +1 -16
 	kmb = to_kmb(plane->dev);
@@ -121,21 +121,7 @@ static void kmb_plane_atomic_disable(struct
 drm_plane *plane,
 	if (WARN_ON(plane_id >= KMB_MAX_PLANES))
 		return;
 
-	switch (plane_id) {
-	case LAYER_0:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE;
-		break;
-	case LAYER_1:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL2_ENABLE;
-		break;
-	case LAYER_2:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL1_ENABLE;
-		break;
-	case LAYER_3:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL2_ENABLE;
-		break;
-	}
-
+	kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE;
 	kmb->plane_status[plane_id].disable = true;
 }
 
--

2.30.2

#2 lore raw

Hi Kees,
This patch https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ is pushed to drm-misc-fixes. This change should fix the below warnings.

I apologize for all the inconveniences.

Thanks,
Anitha

Quoted 103 lines

-----Original Message-----
From: Chrisanthus, Anitha
Sent: Wednesday, August 25, 2021 1:44 PM
To: Kees Cook <[email protected]>
Cc: Dea, Edmund J <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; [email protected]; Sam Ravnborg <[email protected]>; [email protected]; linux- [email protected]
Subject: RE: [PATCH] drm/kmb: Avoid warnings on impossible plane_id

Hi Kees,
Thanks for your patch.
The switch statement is needed for multiple planes which is already approved in this patch series.
https://patchwork.kernel.org/project/dri-
devel/patch/[email protected]/

This patch has dependencies on the previous patches in this series, and we are waiting for reviews on those before this can be checked in.

Thanks,
Anitha

Quoted 11 lines

-----Original Message-----
From: Kees Cook <[email protected]>
Sent: Wednesday, August 25, 2021 11:18 AM
To: Chrisanthus, Anitha <[email protected]>
Cc: Kees Cook <[email protected]>; Dea, Edmund J <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; [email protected]; Sam Ravnborg <[email protected]>; [email protected]; linux- [email protected]
Subject: [PATCH] drm/kmb: Avoid warnings on impossible plane_id

Quoted 1 line

KMB_MAX_PLANES is defined as 1, yet kmb_plane_atomic_disable() had

code

Quoted 67 lines

for writing beyond 1. It is gated by a WARN_ON() that would skip it, though, but under some compiler versions, poor Dead Code Elimination wasn't optimizing away the unused switch cases, leading to array bounds warnings when building with -Warray-bounds:

drivers/gpu/drm/kmb/kmb_plane.c:135:20: warning: array subscript 3 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] drivers/gpu/drm/kmb/kmb_plane.c:132:20: warning: array subscript 2 is above array bounds of 'struct layer_status[1]' [-Warray-bounds] drivers/gpu/drm/kmb/kmb_plane.c:129:20: warning: array subscript 1 is above array bounds of 'struct layer_status[1]' [-Warray-bounds]

Instead, just remove the switch statement entirely and adjust the index type to match the struct "id" member.

Cc Anitha Chrisanthus <[email protected]>
Cc Edmund Dea <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Fixes 7f7b96a8a0a1 ("drm/kmb: Add support for KeemBay Display")
---
 drivers/gpu/drm/kmb/kmb_plane.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)
drivers/gpu/drm/kmb/kmb_plane.c +1 -1
index ecee6782612d..3d46e756f2fe 100644
@@ -113,7 +113,7 @@ static void kmb_plane_atomic_disable(struct
 drm_plane *plane,
 				     struct drm_atomic_state *state)
 {
 	struct kmb_plane *kmb_plane = to_kmb_plane(plane);
-	int plane_id = kmb_plane->id;
+	unsigned char plane_id = kmb_plane->id;
 	struct kmb_drm_private *kmb;
 
drivers/gpu/drm/kmb/kmb_plane.c +1 -16
 	kmb = to_kmb(plane->dev);
@@ -121,21 +121,7 @@ static void kmb_plane_atomic_disable(struct
 drm_plane *plane,
 	if (WARN_ON(plane_id >= KMB_MAX_PLANES))
 		return;
 
-	switch (plane_id) {
-	case LAYER_0:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE;
-		break;
-	case LAYER_1:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL2_ENABLE;
-		break;
-	case LAYER_2:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL1_ENABLE;
-		break;
-	case LAYER_3:
-		kmb->plane_status[plane_id].ctrl = LCD_CTRL_GL2_ENABLE;
-		break;
-	}
-
+	kmb->plane_status[plane_id].ctrl = LCD_CTRL_VL1_ENABLE;
 	kmb->plane_status[plane_id].disable = true;
 }
 
--

2.30.2