Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752093AbdGGOvY (ORCPT ); Fri, 7 Jul 2017 10:51:24 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36836 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751039AbdGGOvW (ORCPT ); Fri, 7 Jul 2017 10:51:22 -0400 Subject: Re: [PATCH] net: ethernet: mediatek: add NULL check on of_match_device() return value To: "Gustavo A. R. Silva" , Felix Fietkau , John Crispin Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org References: <20170707071135.GA29205@embeddedgus> From: Matthias Brugger Message-ID: <1eba7874-fd99-e45c-005a-dcc9a3d51538@gmail.com> Date: Fri, 7 Jul 2017 16:51:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170707071135.GA29205@embeddedgus> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1052 Lines: 33 On 07/07/2017 09:11 AM, 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 > --- Reviewed-by: Matthias Brugger > 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); >