Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932123AbdGJP0K (ORCPT ); Mon, 10 Jul 2017 11:26:10 -0400 Received: from gateway31.websitewelcome.com ([192.185.143.46]:49169 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753646AbdGJP0I (ORCPT ); Mon, 10 Jul 2017 11:26:08 -0400 Date: Mon, 10 Jul 2017 10:25:50 -0500 Message-ID: <20170710102550.Horde.A0-YaQd3DuTznXe59Uhkbr-@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Alan Tull Cc: Moritz Fischer , linux-fpga@vger.kernel.org, linux-kernel Subject: Re: [PATCH] fpga: altera-hps2fpga: add NULL check on of_match_device() return value References: <20170707062214.GA16142@embeddedgus> In-Reply-To: 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: 1dUaZK-004NZl-H5 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:50942 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: 1289 Lines: 56 Hi Alan, Quoting Alan Tull : > On Fri, Jul 7, 2017 at 1:22 AM, Gustavo A. R. Silva > > Hi Gustavo, > > Thanks for the fix! > Absolutely, glad to help. :) > Alan > > 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 > > Acked-by: Alan Tull > >> --- >> drivers/fpga/altera-hps2fpga.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/drivers/fpga/altera-hps2fpga.c b/drivers/fpga/altera-hps2fpga.c >> index 3066b80..ca8212c 100644 >> --- a/drivers/fpga/altera-hps2fpga.c >> +++ b/drivers/fpga/altera-hps2fpga.c >> @@ -143,6 +143,11 @@ static int alt_fpga_bridge_probe(struct >> platform_device *pdev) >> int ret; >> >> of_id = of_match_device(altera_fpga_of_match, dev); >> + if (!of_id) { >> + dev_err(dev, "failed to match device\n"); >> + return -ENODEV; >> + } >> + >> priv = (struct altera_hps2fpga_data *)of_id->data; >> >> priv->bridge_reset = of_reset_control_get_by_index(dev->of_node, 0); >> -- >> 2.5.0 >> -- Gustavo A. R. Silva