rockchip_drm_match_remove() walks dev->links.consumers and calls
device_link_del() for every entry.  That drops the link's reference and,
once it reaches zero, __device_link_del() removes the link from the
device link lists and schedules the release of the link object.

list_for_each_entry() still reads link->s_node after the loop body to
find the next entry, so it accesses a link that has already been
released.  Use list_for_each_entry_safe() so that the next entry is
loaded before the current link is deleted.

Fixes: 7d4e981d41e3 ("drm/rockchip: Add device links for master and components")
Cc: [email protected]
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <[email protected]>
---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index 3099408e9d05..9edfe4db9393 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -356,9 +356,9 @@ int rockchip_drm_endpoint_is_subdriver(struct device_node 
*ep)
 
 static void rockchip_drm_match_remove(struct device *dev)
 {
-       struct device_link *link;
+       struct device_link *link, *tmp;
 
-       list_for_each_entry(link, &dev->links.consumers, s_node)
+       list_for_each_entry_safe(link, tmp, &dev->links.consumers, s_node)
                device_link_del(link);
 }
 
-- 
2.34.1

Reply via email to