Skip to contentSkip to conversation

fix missing break in list_or_each_entry

PATCH In review Xiaomeng Tong 2 participants 13 messages Mar 30, 2022 – Apr 1, 2022

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

cover fix missing break in list_or_each_entry

Instead of exiting the loop as expected when an entry is found, the list_for_each_entry() continues until the traversal is complete. It could lead to invalid reference or set 'is_*' flags mistakely.

To fix this, when an entry is found, add a break to exit the loop.

Xiaomeng Tong (5):
gma500: fix a missing break in oaktrail_crtc_mode_set
gma500: fix a missing break in cdv_intel_crtc_mode_set
gma500: fix a missing break in psb_intel_crtc_mode_set
gma500: fix a missing break in cdv_intel_dp_set_m_n
gma500: fix a missing break in psb_driver_load

 drivers/gpu/drm/gma500/cdv_intel_display.c | 2 ++
 drivers/gpu/drm/gma500/cdv_intel_dp.c      | 2 ++
 drivers/gpu/drm/gma500/oaktrail_crtc.c     | 2 ++
 drivers/gpu/drm/gma500/psb_drv.c           | 2 ++
 drivers/gpu/drm/gma500/psb_intel_display.c | 2 ++
 5 files changed, 10 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 gma500: fix a missing break in oaktrail_crtc_mode_set

Instead of exiting the loop as expected when an entry is found, the list_for_each_entry() continues until the traversal is complete. It will certainly lead to a invalid reference to list itereator variable 'connector' after the loop pointing an bogus address at an offset from the list head, and could lead to multiple 'is_*' flags being set with true mistakely too.

The invalid reference to list itereator is here:

	drm_object_property_get_value(&connector->base,

To fix this, when found the entry, add a break after the switch statement.

Fixes a69ac9ea85d87 ("drm/gma500: drm_connector_property -> drm_object_property")
---
 drivers/gpu/drm/gma500/oaktrail_crtc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/oaktrail_crtc.c +2 -0
index 36c7c2686c90..eb2d79872bd5 100644
@@ -409,6 +409,8 @@ static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
 			is_mipi = true;
 			break;
 		}
+
+		break;
 	}
 
 	/* Disable the VGA plane that we never use */
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/5] gma500: fix a missing break in oaktrail_crtc_mode_set

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. It will certainly lead to a invalid reference to list itereator variable 'connector' after the loop pointing an bogus address at an offset from the list head, and could lead to multiple 'is_*' flags being set with true mistakely too.

Quoted 5 lines

The invalid reference to list itereator is here:

        drm_object_property_get_value(&connector->base,

To fix this, when found the entry, add a break after the switch statement.

Hi, this is already fixed in:
commit b1a7d0ddb169774c3db5afe9e64124daea7fdd9f

Author: Patrik Jakobsson <[email protected]>
Date:   Tue Mar 22 14:17:38 2022 +0100

drm/gma500: Make use of the drm connector iterator

Quoted 23 lines
Fixes a69ac9ea85d87 ("drm/gma500: drm_connector_property -> drm_object_property")
---
 drivers/gpu/drm/gma500/oaktrail_crtc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/oaktrail_crtc.c +2 -1
index 36c7c2686c90..eb2d79872bd5 100644
@@ -409,6 +409,8 @@ static int oaktrail_crtc_mode_set(struct drm_crtc *crtc,
                        is_mipi = true;
                        break;
                }
+
+               break;
        }
 
        /* Disable the VGA plane that we never use */
--

2.17.1

#3 lore raw

PATCH 2/5 gma500: fix a missing break in cdv_intel_crtc_mode_set

In reply to 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. It could lead to a invalid reference to 'ddi_select' after the loop, and could lead to multiple 'is_*' flags being set with true mistakely, too.

The invalid reference to 'ddi_select' is here:

	cdv_dpll_set_clock_cdv(dev, crtc, &clock, is_lvds, ddi_select);

To fix this, when found the entry, add a break after the switch statement.

Fixes d66760962d75 ("gma500: Program the DPLL lane based on the selected digitial port")
---
 drivers/gpu/drm/gma500/cdv_intel_display.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/cdv_intel_display.c +2 -0
index 94ebc48a4349..3e93019b17cb 100644
@@ -616,6 +616,8 @@ static int cdv_intel_crtc_mode_set(struct drm_crtc *crtc,
 			DRM_ERROR("invalid output type.\n");
 			return 0;
 		}
+
+		break;
 	}
 
 	if (dev_priv->dplla_96mhz)
Signature · 1 line
2.17.1
maintainer
#4 lore raw

Re: [PATCH 2/5] gma500: fix a missing break in cdv_intel_crtc_mode_set

Quoted 6 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. It could lead to a invalid reference to 'ddi_select' after the loop, and could lead to multiple 'is_*' flags being set with true mistakely, too.

Quoted 7 lines

The invalid reference to 'ddi_select' is here:

        cdv_dpll_set_clock_cdv(dev, crtc, &clock, is_lvds, ddi_select);

To fix this, when found the entry, add a break after the switch statement.

Fixes d66760962d75 ("gma500: Program the DPLL lane based on the selected digitial port")

Hi, this one is also already fixed in:

commit b1a7d0ddb169774c3db5afe9e64124daea7fdd9f

Author: Patrik Jakobsson <[email protected]>
Date:   Tue Mar 22 14:17:38 2022 +0100

drm/gma500: Make use of the drm connector iterator

Quoted 20 lines
---
 drivers/gpu/drm/gma500/cdv_intel_display.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/cdv_intel_display.c +2 -1
index 94ebc48a4349..3e93019b17cb 100644
@@ -616,6 +616,8 @@ static int cdv_intel_crtc_mode_set(struct drm_crtc *crtc,
                        DRM_ERROR("invalid output type.\n");
                        return 0;
                }
+
+               break;
        }
 
        if (dev_priv->dplla_96mhz)
--

2.17.1

#5 lore raw

PATCH 3/5 gma500: fix a missing break in psb_intel_crtc_mode_set

In reply to 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. It could result in multiple 'is_*' flags being set with true mistakely.

To fix this, when found the entry, add a break after the switch statement.

Fixes 89c78134cc54d (" gma500: Add Poulsbo support")
---
 drivers/gpu/drm/gma500/psb_intel_display.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/psb_intel_display.c +2 -0
index 42d1a733e124..85fc61bf333a 100644
@@ -134,6 +134,8 @@ static int psb_intel_crtc_mode_set(struct drm_crtc *crtc,
 			is_tv = true;
 			break;
 		}
+
+		break;
 	}
 
 	refclk = 96000;
Signature · 1 line
2.17.1
maintainer
#6 lore raw

Re: [PATCH 3/5] gma500: fix a missing break in psb_intel_crtc_mode_set

Quoted 10 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. It could result in multiple 'is_*' flags being set with true mistakely.

To fix this, when found the entry, add a break after the switch statement.

Fixes 89c78134cc54d (" gma500: Add Poulsbo support")

This patch doesn't apply for me and needs to be rebased on top of drm-misc-next or drm-tip.

On Poulsbo there should only be one encoder per crtc so this is only a theoretical issue. But it is good practice to exit the loop early if we can so the patch still makes sense.

Also, please use the correct subject prefix: drm/gma500: instead of just gma500:.

Thanks
Patrik

Quoted 20 lines
---
 drivers/gpu/drm/gma500/psb_intel_display.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/psb_intel_display.c +2 -1
index 42d1a733e124..85fc61bf333a 100644
@@ -134,6 +134,8 @@ static int psb_intel_crtc_mode_set(struct drm_crtc *crtc,
                        is_tv = true;
                        break;
                }
+
+               break;
        }
 
        refclk = 96000;
--

2.17.1

#7 lore raw

Re: [PATCH 3/5] gma500: fix a missing break in psb_intel_crtc_mode_set

Quoted 15 lines · Xiaomeng Tong
Quoted 10 lines

Instead of exiting the loop as expected when an entry is found, the list_for_each_entry() continues until the traversal is complete. It could result in multiple 'is_*' flags being set with true mistakely.

To fix this, when found the entry, add a break after the switch statement.

Fixes 89c78134cc54d (" gma500: Add Poulsbo support")

This patch doesn't apply for me and needs to be rebased on top of drm-misc-next or drm-tip.

Quoted 6 lines

On Poulsbo there should only be one encoder per crtc so this is only a theoretical issue. But it is good practice to exit the loop early if we can so the patch still makes sense.

Also, please use the correct subject prefix: drm/gma500: instead of just gma500:.

I will resend another patch as you suggested, thank you.

--
Xiaomeng Tong

#8 lore raw

PATCH 4/5 gma500: fix a missing break in cdv_intel_dp_set_m_n

In reply to 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. It could lead to a invalid reference to 'lane_count/bpp' after the loop.

The invalid reference to 'lane_count/bpp' is here:
cdv_intel_dp_compute_m_n(bpp, lane_count,

To fix this, when found the entry, add a break after the switch statement.

Fixes 8695b61294356 ("gma500: Add the support of display port on CDV")
---
 drivers/gpu/drm/gma500/cdv_intel_dp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/cdv_intel_dp.c +2 -0
index ba6ad1466374..e6473b8da296 100644
@@ -1016,6 +1016,8 @@ cdv_intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
 			bpp = dev_priv->edp.bpp;
 			break;
 		}
+
+		break;
 	}
 
 	/*
Signature · 1 line
2.17.1
maintainer
#9 lore raw

Re: [PATCH 4/5] gma500: fix a missing break in cdv_intel_dp_set_m_n

Quoted 5 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. It could lead to a invalid reference to 'lane_count/bpp' after the loop.

Quoted 7 lines

The invalid reference to 'lane_count/bpp' is here:
cdv_intel_dp_compute_m_n(bpp, lane_count,

To fix this, when found the entry, add a break after the switch statement.

Fixes 8695b61294356 ("gma500: Add the support of display port on CDV")

This loop already breaks when the desired conditions are met (see the if statements).

Quoted 20 lines
---
 drivers/gpu/drm/gma500/cdv_intel_dp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/cdv_intel_dp.c +2 -1
index ba6ad1466374..e6473b8da296 100644
@@ -1016,6 +1016,8 @@ cdv_intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
                        bpp = dev_priv->edp.bpp;
                        break;
                }
+
+               break;
        }
 
        /*
--

2.17.1

#10 lore raw

PATCH 5/5 gma500: fix a missing break in psb_driver_load

In reply to 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, add a break after the switch statement.

Fixes 5c49fd3aa0ab0 ("gma500: Add the core DRM files and headers")
---
 drivers/gpu/drm/gma500/psb_drv.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/psb_drv.c +2 -0
index 65cf1c79dd7c..d65a68811bf7 100644
@@ -398,6 +398,8 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 			ret = gma_backlight_init(dev);
 			break;
 		}
+
+		break;
 	}
 
 	if (ret)
Signature · 1 line
2.17.1
maintainer
#11 lore raw

Re: [PATCH 5/5] gma500: fix a missing break in psb_driver_load

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, add a break after the switch statement.

Fixes 5c49fd3aa0ab0 ("gma500: Add the core DRM files and headers")

This is incorrect. If we always break on the first iteration we will only run gma_backlight_init() if the first connector is LVDS or MIPI. This might not be the case and gma_backlight_init() will never run. The other loops you have been looking at have an "if (xxx != yyy) continue;" statement at the top which skips all the unwanted entries but this loop does not.

Quoted 20 lines
---
 drivers/gpu/drm/gma500/psb_drv.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/psb_drv.c +2 -1
index 65cf1c79dd7c..d65a68811bf7 100644
@@ -398,6 +398,8 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
                        ret = gma_backlight_init(dev);
                        break;
                }
+
+               break;
        }
 
        if (ret)
--

2.17.1

#12 lore raw

Re: [PATCH 5/5] gma500: fix a missing break in psb_driver_load

Quoted 10 lines · Patrik Jakobsson
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, add a break after the switch statement.

Fixes 5c49fd3aa0ab0 ("gma500: Add the core DRM files and headers")
Quoted 7 lines

This is incorrect. If we always break on the first iteration we will only run gma_backlight_init() if the first connector is LVDS or MIPI. This might not be the case and gma_backlight_init() will never run. The other loops you have been looking at have an "if (xxx != yyy) continue;" statement at the top which skips all the unwanted entries but this loop does not.

Yes, your are correct. But it still need to break the loop when found it. So it is better to add if(!ret) break; after the switch statment. I will resend another patch if it is necessary.

Quoted 16 lines
Quoted 16 lines
---
 drivers/gpu/drm/gma500/psb_drv.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/gma500/psb_drv.c +2 -0
index 65cf1c79dd7c..d65a68811bf7 100644
@@ -398,6 +398,8 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
                        ret = gma_backlight_init(dev);
                        break;
                }
+
+               break;
        }
 
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/gma500/psb_drv.c +0 -1
        if (ret)
--

2.17.1

--
Xiaomeng Tong