From 8aa7d7baa5eb142261ddafc91b0ba884aa670421 Mon Sep 17 00:00:00 2001
From: Sandor Yu <Sandor.yu@nxp.com>
Date: Fri, 19 Jun 2020 16:17:55 +0800
Subject: [PATCH 31/49] LF-1514: drm: cdns-mhdp: check link rate index

Check link rate index to advoid negative array index read.
report by Coverity ID:6652950 6652949.

Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
Reviewed-by: Fancy Fang <chen.fang@nxp.com>
---
 drivers/gpu/drm/imx/mhdp/cdns-mhdp-dp-phy.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/imx/mhdp/cdns-mhdp-dp-phy.c b/drivers/gpu/drm/imx/mhdp/cdns-mhdp-dp-phy.c
index a6d03c94d196..5c75e7d40cc0 100644
--- a/drivers/gpu/drm/imx/mhdp/cdns-mhdp-dp-phy.c
+++ b/drivers/gpu/drm/imx/mhdp/cdns-mhdp-dp-phy.c
@@ -198,6 +198,10 @@ static void dp_phy_pma_cmn_pll0_24mhz(struct cdns_mhdp_device *mhdp)
 
 	/* DP PHY PLL 24MHz configuration */
 	index = link_rate_index(link_rate);
+	if (index < 0) {
+		dev_err(mhdp->dev, "wrong link rate index\n");
+		return;
+	}
 	for (i = 0; i < ARRAY_SIZE(phy_pll_24m_cfg); i++)
 		cdns_phy_reg_write(mhdp, phy_pll_24m_cfg[i].addr, phy_pll_24m_cfg[i].val[index]);
 
@@ -320,6 +324,10 @@ static void dp_phy_pma_cmn_pll0_27mhz(struct cdns_mhdp_device *mhdp)
 
 	/* DP PHY PLL 27MHz configuration */
 	index = link_rate_index(link_rate);
+	if (index < 0) {
+		dev_err(mhdp->dev, "wrong link rate index\n");
+		return;
+	}
 	for (i = 0; i < ARRAY_SIZE(phy_pll_27m_cfg); i++)
 		cdns_phy_reg_write(mhdp, phy_pll_27m_cfg[i].addr, phy_pll_27m_cfg[i].val[index]);
 
-- 
2.29.2

