Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752611AbdGGUJB (ORCPT ); Fri, 7 Jul 2017 16:09:01 -0400 Received: from gateway30.websitewelcome.com ([192.185.197.25]:33536 "EHLO gateway30.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752578AbdGGUI7 (ORCPT ); Fri, 7 Jul 2017 16:08:59 -0400 Date: Fri, 07 Jul 2017 15:08:31 -0500 Message-ID: <20170707150831.Horde.MYtEbXeqxGS-hTg2bUv3DWt@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Andrew Lunn Cc: Felix Fietkau , John Crispin , Matthias Brugger , netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value References: <20170707071135.GA29205@embeddedgus> <20170707145717.GG24237@lunn.ch> In-Reply-To: <20170707145717.GG24237@lunn.ch> User-Agent: Horde Application Framework 5 Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 108.167.133.22 X-Exim-ID: 1dTZYF-002S8T-P8 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:39067 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 2 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1528 Lines: 56 Hi Andrew, Quoting Andrew Lunn : > On Fri, Jul 07, 2017 at 02:11:35AM -0500, Gustavo A. R. Silva wrote: >> 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 >> --- >> 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; > > Hi Gustavo > > I think you are fixing the wrong thing. The soc variable is unused. Also, > > const struct of_device_id of_mtk_match[] = { > { .compatible = "mediatek,mt2701-eth" }, > {}, > }; > > So match->data is NULL. This code is all pointless and should be > removed, rather than try to avoid a NULL pointer dereference which can > not actually happen. > You are right. Thank you for pointing it out. I'll remove that code and send a new patch shortly. Thanks! -- Gustavo A. R. Silva