From d97021bf0bf19401709587d93c602c9108822b8f Mon Sep 17 00:00:00 2001 From: jsg Date: Mon, 5 Sep 2022 14:09:09 +0000 Subject: [PATCH] drm/amd/display: Avoid MPC infinite loop From Josip Pavic 0c8abeceee0f58ad3fdc66e1de0c0e02b962653b in linux 5.15.y/5.15.65 8de297dc046c180651c0500f8611663ae1c3828a in mainline linux --- sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_mpc.c | 6 ++++++ sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_mpc.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_mpc.c b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_mpc.c index 11019c2c62c..8192f1967e9 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_mpc.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_mpc.c @@ -126,6 +126,12 @@ struct mpcc *mpc1_get_mpcc_for_dpp(struct mpc_tree *tree, int dpp_id) while (tmp_mpcc != NULL) { if (tmp_mpcc->dpp_id == dpp_id) return tmp_mpcc; + + /* avoid circular linked list */ + ASSERT(tmp_mpcc != tmp_mpcc->mpcc_bot); + if (tmp_mpcc == tmp_mpcc->mpcc_bot) + break; + tmp_mpcc = tmp_mpcc->mpcc_bot; } return NULL; diff --git a/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_mpc.c b/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_mpc.c index 947eb0df3f1..142fc0a3a53 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_mpc.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_mpc.c @@ -532,6 +532,12 @@ struct mpcc *mpc2_get_mpcc_for_dpp(struct mpc_tree *tree, int dpp_id) while (tmp_mpcc != NULL) { if (tmp_mpcc->dpp_id == 0xf || tmp_mpcc->dpp_id == dpp_id) return tmp_mpcc; + + /* avoid circular linked list */ + ASSERT(tmp_mpcc != tmp_mpcc->mpcc_bot); + if (tmp_mpcc == tmp_mpcc->mpcc_bot) + break; + tmp_mpcc = tmp_mpcc->mpcc_bot; } return NULL; -- 2.20.1