Skip to contentSkip to conversation

drm/gma500: fix a potential repeat execution in psb_driver_load

PATCH Superseded Xiaomeng Tong 2 participants 3 messages Apr 6, 2022 – Apr 13, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 the entry is found.

---

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

v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/gma500/psb_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/gma500/psb_drv.c +2 -1
index 2aff54d505e2..929fd47548b4 100644
@@ -400,9 +400,10 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 		case INTEL_OUTPUT_LVDS:
 		case INTEL_OUTPUT_MIPI:
 			ret = gma_backlight_init(dev);
-			break;
+			goto out;
 		}
 	}
+out:
 	drm_connector_list_iter_end(&conn_iter);
 
 	if (ret)
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 23 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 the entry is found.

---

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

v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/gma500/psb_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/gma500/psb_drv.c +0 -0
index 2aff54d505e2..929fd47548b4 100644

drivers/gpu/drm/gma500/psb_drv.c static int psb_driver_load(struct drm_device *dev, unsigned long flags) · line 407

Quoted 9 lines
drivers/gpu/drm/gma500/psb_drv.c +2 -1
@@ -400,9 +400,10 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
                case INTEL_OUTPUT_LVDS:
                case INTEL_OUTPUT_MIPI:
                        ret = gma_backlight_init(dev);
-                       break;
+                       goto out;
                }
        }
+out:
        drm_connector_list_iter_end(&conn_iter);

Hi,
This would work but using gotos like this easily turns the code into spaghetti. See "7. Centralized exiting of functions" in Documentation/process/coding-style.rst for when to use gotos.

In this particular case I think we are better off using an if-statement. What about something like this:

if (gma_encoder->type == INTEL_OUTPUT_LVDS ||

    gma_encoder->type == INTEL_OUTPUT_MIPI) {
        ret = gma_backlight_init();
        break;
}

-Patrik

Quoted 5 lines
drivers/gpu/drm/gma500/psb_drv.c +0 -1
        if (ret)
--

2.17.1

#2 lore raw
Quoted 5 lines · Patrik Jakobsson

Hi,
This would work but using gotos like this easily turns the code into spaghetti. See "7. Centralized exiting of functions" in Documentation/process/coding-style.rst for when to use gotos.

Quoted 8 lines

In this particular case I think we are better off using an if-statement. What about something like this:

if (gma_encoder->type == INTEL_OUTPUT_LVDS ||

    gma_encoder->type == INTEL_OUTPUT_MIPI) {
        ret = gma_backlight_init();
        break;
}

Yes, it looks better.
I have sent a PATCH v3 with changes as you suggested, please check it. Thank you very much.

--
Xiaomeng Tong