Skip to contentSkip to conversation

drm/gma500: fix a potential repeat execution in psb_driver_load

PATCH In review Xiaomeng Tong 2 participants 2 messages Apr 13, 2022 – Apr 20, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 drm/gma500: fix a potential repeat execution in psb_driver_load

Instead of exiting the loop as expected when an entry is found, the list_for_each_entry() continues until the traversal is complete. To avoid potential executing 'ret = gma_backlight_init(dev);' repeatly, goto outside the loop when found entry by replacing switch/case with if statement.

---
changes since v2:
- replace switch with if statement (Patrik Jakobsson)

changes since v1:
- goto outside the loop (Xiaomeng Tong)

v2: https://lore.kernel.org/dri-devel/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/gma500/psb_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/gma500/psb_drv.c +2 -3
index 2aff54d505e2..85211ec16e52 100644
@@ -396,9 +396,8 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 	drm_for_each_connector_iter(connector, &conn_iter) {
 		gma_encoder = gma_attached_encoder(connector);
 
-		switch (gma_encoder->type) {
-		case INTEL_OUTPUT_LVDS:
-		case INTEL_OUTPUT_MIPI:
+		if (gma_encoder->type == INTEL_OUTPUT_LVDS ||
+			gma_encoder->type == INTEL_OUTPUT_MIPI) {
 			ret = gma_backlight_init(dev);
 			break;
 		}
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 8 lines · Xiaomeng Tong

Instead of exiting the loop as expected when an entry is found, the list_for_each_entry() continues until the traversal is complete. To avoid potential executing 'ret = gma_backlight_init(dev);' repeatly, goto outside the loop when found entry by replacing switch/case with if statement.

Thanks for the patch. I've applied it to drm-misc-next.

I fixed up an indentation issue on the second line.

Cheers
Patrik

Quoted 32 lines

---
changes since v2:
- replace switch with if statement (Patrik Jakobsson)

changes since v1:
- goto outside the loop (Xiaomeng Tong)

v2: https://lore.kernel.org/dri-devel/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/gma500/psb_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/gma500/psb_drv.c +2 -4
index 2aff54d505e2..85211ec16e52 100644
@@ -396,9 +396,8 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
        drm_for_each_connector_iter(connector, &conn_iter) {
                gma_encoder = gma_attached_encoder(connector);
 
-               switch (gma_encoder->type) {
-               case INTEL_OUTPUT_LVDS:
-               case INTEL_OUTPUT_MIPI:
+               if (gma_encoder->type == INTEL_OUTPUT_LVDS ||
+                       gma_encoder->type == INTEL_OUTPUT_MIPI) {
                        ret = gma_backlight_init(dev);
                        break;
                }
--

2.17.1