netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value
@ 2017-07-07  7:11 Gustavo A. R. Silva
  2017-07-07 14:51 ` Matthias Brugger
  2017-07-07 14:57 ` Andrew Lunn
  0 siblings, 2 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-07  7:11 UTC (permalink / raw)
  To: Felix Fietkau, John Crispin, Matthias Brugger
  Cc: netdev, linux-arm-kernel, linux-mediatek, linux-kernel,
	Gustavo A. R. Silva

Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index adaaafc..6a77dea 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2408,6 +2408,11 @@ static int mtk_probe(struct platform_device *pdev)
 	int i;
 
 	match = of_match_device(of_mtk_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "failed to match device\n");
+		return -ENODEV;
+	}
+
 	soc = (struct mtk_soc_data *)match->data;
 
 	eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-07-08 10:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-07  7:11 [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value Gustavo A. R. Silva
2017-07-07 14:51 ` Matthias Brugger
2017-07-07 14:57 ` Andrew Lunn
2017-07-07 20:08   ` Gustavo A. R. Silva
2017-07-07 20:23     ` [PATCH] net: ethernet: mediatek: remove useless code in mtk_probe() Gustavo A. R. Silva
2017-07-08  6:56       ` Sean Wang
2017-07-08 10:28       ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).