[PATCH] net: xilinx: fix potential NULL dereference in temac_probe()

Xu Wang vulab at iscas.ac.cn
Mon Jul 13 22:23:04 EDT 2020


platform_get_resource() may return NULL, add proper
check to avoid potential NULL dereferencing.

Signed-off-by: Xu Wang <vulab at iscas.ac.cn>
---
 drivers/net/ethernet/xilinx/ll_temac_main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 929244064abd..85a767fa2ecf 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -1408,6 +1408,8 @@ static int temac_probe(struct platform_device *pdev)
 
 	/* map device registers */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 	lp->regs = devm_ioremap(&pdev->dev, res->start,
 					resource_size(res));
 	if (!lp->regs) {
@@ -1503,6 +1505,8 @@ static int temac_probe(struct platform_device *pdev)
 	} else if (pdata) {
 		/* 2nd memory resource specifies DMA registers */
 		res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+		if (!res)
+			return -EINVAL;
 		lp->sdma_regs = devm_ioremap(&pdev->dev, res->start,
 						     resource_size(res));
 		if (!lp->sdma_regs) {
-- 
2.17.1




More information about the linux-arm-kernel mailing list