Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752412AbdGGHmo (ORCPT ); Fri, 7 Jul 2017 03:42:44 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:7408 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752134AbdGGHmm (ORCPT ); Fri, 7 Jul 2017 03:42:42 -0400 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 07 Jul 2017 00:42:36 -0700 Subject: Re: [PATCH] input: tegra-kbc: add NULL check on of_match_device() return value To: "Gustavo A. R. Silva" , Rakesh Iyer , Laxman Dewangan , Dmitry Torokhov , Thierry Reding CC: , , References: <20170707062758.GA17584@embeddedgus> From: Jon Hunter Message-ID: Date: Fri, 7 Jul 2017 08:42:32 +0100 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: <20170707062758.GA17584@embeddedgus> X-Originating-IP: [10.21.132.162] X-ClientProxiedBy: UKMAIL101.nvidia.com (10.26.138.13) To UKMAIL101.nvidia.com (10.26.138.13) Content-Type: text/plain; charset="utf-8" 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: 993 Lines: 32 On 07/07/17 07:27, 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/input/keyboard/tegra-kbc.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c > index 0c07e10..742c5ac 100644 > --- a/drivers/input/keyboard/tegra-kbc.c > +++ b/drivers/input/keyboard/tegra-kbc.c > @@ -617,6 +617,10 @@ static int tegra_kbc_probe(struct platform_device *pdev) > const struct of_device_id *match; > > match = of_match_device(tegra_kbc_of_match, &pdev->dev); > + if (!match) { > + dev_err(&pdev->dev, "failed to match device\n"); > + return -ENODEV; > + } Given that Tegra always uses device-tree, I believe that this cannot happen and so this additional check is not needed. Jon -- nvpublic