From patchwork Fri Jul 7 06:27:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 9829623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 211A4602BD for ; Fri, 7 Jul 2017 06:28:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 120BE285F9 for ; Fri, 7 Jul 2017 06:28:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 061D6285FF; Fri, 7 Jul 2017 06:28:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84E0E285F9 for ; Fri, 7 Jul 2017 06:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751812AbdGGG2C (ORCPT ); Fri, 7 Jul 2017 02:28:02 -0400 Received: from gateway20.websitewelcome.com ([192.185.64.36]:32228 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750984AbdGGG2C (ORCPT ); Fri, 7 Jul 2017 02:28:02 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 9CC3F400DB202 for ; Fri, 7 Jul 2017 01:27:59 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id TMjodH56OUWWCTMjodmdCY; Fri, 07 Jul 2017 01:27:36 -0500 Received: from [189.152.152.176] (port=60094 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.87) (envelope-from ) id 1dTMkB-0024dG-9u; Fri, 07 Jul 2017 01:27:59 -0500 Date: Fri, 7 Jul 2017 01:27:58 -0500 From: "Gustavo A. R. Silva" To: Rakesh Iyer , Laxman Dewangan , Dmitry Torokhov , Thierry Reding , Jonathan Hunter Cc: linux-input@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] input: tegra-kbc: add NULL check on of_match_device() return value Message-ID: <20170707062758.GA17584@embeddedgus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) 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: 189.152.152.176 X-Exim-ID: 1dTMkB-0024dG-9u X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.152.152.176]:60094 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 22 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; + } kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); if (!kbc) {