Skip to contentSkip to conversation

phy: mediatek: Fix missing check in mtk_mipi_tx_probe

PATCH In review Miaoqian Lin 4 participants 5 messages Dec 24, 2021 – Jan 6, 2022

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

PATCH 1/1 phy: mediatek: Fix missing check in mtk_mipi_tx_probe

The of_device_get_match_data() function may return NULL. Add check to prevent potential null dereference.

---
 drivers/phy/mediatek/phy-mtk-mipi-dsi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +2 -0
index 28ad9403c441..67b005d5b9e3 100644
@@ -146,6 +146,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	mipi_tx->driver_data = of_device_get_match_data(dev);
+	if (!mipi_tx->driver_data)
+		return -ENODEV;
 
 	mipi_tx->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(mipi_tx->regs))
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 22 lines · Miaoqian Lin

The of_device_get_match_data() function may return NULL. Add check to prevent potential null dereference.

---
 drivers/phy/mediatek/phy-mtk-mipi-dsi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +2 -0
index 28ad9403c441..67b005d5b9e3 100644
@@ -146,6 +146,8 @@ static int mtk_mipi_tx_probe(struct
 platform_device *pdev)
 		return -ENOMEM;
 
 	mipi_tx->driver_data = of_device_get_match_data(dev);
+	if (!mipi_tx->driver_data)
+		return -ENODEV;
 
 	mipi_tx->regs = devm_platform_ioremap_resource(pdev, 0);
Quoted 1 line

if (IS_ERR(mipi_tx->regs))

Thanks

maintainer
#3 lore raw
In reply to Miaoqian Lin

Hi, Miaoqian:

Miaoqian Lin <[email protected]> 於 2021年12月24日 週五 下午4:21寫道:

Quoted 14 lines

The of_device_get_match_data() function may return NULL. Add check to prevent potential null dereference.

---
 drivers/phy/mediatek/phy-mtk-mipi-dsi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +0 -0
index 28ad9403c441..67b005d5b9e3 100644

drivers/phy/mediatek/phy-mtk-mipi-dsi.c static int mtk_mipi_tx_probe(struct platform_device *pdev) · line 149

Quoted 4 lines
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +1 -0
@@ -146,6 +146,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        mipi_tx->driver_data = of_device_get_match_data(dev);
+       if (!mipi_tx->driver_data)

I'm confused. mtk_mipi_tx_probe() is called because this device node's compatible match one in mtk_mipi_tx_match[]. So I think the return value of of_device_get_match_data(dev) would not be NULL. If this is true, this checking is redundant.

Regards,
Chun-Kuang.

Quoted 7 lines
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +1 -1
+               return -ENODEV;
 
        mipi_tx->regs = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(mipi_tx->regs))
--

2.17.1

#4 lore raw

Hi, Chun-Kuang:

Quoted 7 lines · Chun-Kuang Hu
Quoted 7 lines
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +0 -0
index 28ad9403c441..67b005d5b9e3 100644
@@ -146,6 +146,8 @@ static int mtk_mipi_tx_probe(struct platform_device *pdev)
                return -ENOMEM;
 
Quoted 8 lines

drivers/phy/mediatek/phy-mtk-mipi-dsi.c static int mtk_mipi_tx_probe(struct platform_device *pdev) · line 149

Quoted 2 lines
drivers/phy/mediatek/phy-mtk-mipi-dsi.c +1 -0
        mipi_tx->driver_data = of_device_get_match_data(dev);
+       if (!mipi_tx->driver_data)

I'm confused. mtk_mipi_tx_probe() is called because this device node's compatible match one in mtk_mipi_tx_match[]. So I think the return value of of_device_get_match_data(dev) would not be NULL. If this is true, this checking is redundant.

I think your are right, this checking is redundant. Thanks for your reply.

Regards,
Miaoqian.