From patchwork Fri Jun 22 11:42:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 10481929 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 A9AE860388 for ; Fri, 22 Jun 2018 11:43:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 963DB28E1D for ; Fri, 22 Jun 2018 11:43:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89DDB28E6D; Fri, 22 Jun 2018 11:43:31 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 445A328E1D for ; Fri, 22 Jun 2018 11:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=zVIdpU01TRW/yf+WPyUuMg7xOOet6xpLb8aeRJkqE5s=; b=gWO 5y8RI8RrrhJZeXX6pY1Daw2JHiCyOXWFfDAXBlasRgn6e7G+q5/1SLU567qiVJRRUL1rJqDLXN+L6 zILPFXfykRp6Xa5EdjCHgyVsYXNh5+alClJxS/o9QOW1w/UwTvFMdDoIhpRJXtFrEtwjh/r+uu2I1 k5FBKOs9ZgrM96gdfIm3OUa2EYr/PuEYM32H2qk1qddUaj8Xt+sNQyQGiiEGcJjz08LgnnxWmy1Me Palqg4llYt92O583uRh5CgF3JBy4PNLtsneDdhegQZy3vZniH03AVTUUUMOiUeAhLilMIZl7Egubz qInSMqXYmUkdPxU71jgse9TIGI3K5bQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWKTP-0002MP-KN for patchwork-linux-mediatek@patchwork.kernel.org; Fri, 22 Jun 2018 11:43:27 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWKSp-00023t-D2; Fri, 22 Jun 2018 11:42:57 +0000 Received: from ziggy.de (unknown [37.223.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DAD52415B; Fri, 22 Jun 2018 11:42:38 +0000 (UTC) From: Matthias Brugger To: dmitry.torokhov@gmail.com, chen.zhong@mediatek.com, lee.jones@linaro.org Subject: [PATCH] input: mtk-pmic-keys: Fix probe when no DT node present Date: Fri, 22 Jun 2018 13:42:28 +0200 Message-Id: <20180622114228.8619-1-matthias.bgg@gmail.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180622_044251_472955_F6C6C809 X-CRM114-Status: UNSURE ( 8.96 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthias Brugger , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-input@vger.kernel.org, matthias.bgg@gmail.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The drivers gets probed from a mfd devices. So the driver runs probe although no DT node exists. This leads to a NULL pointer dereference in the probe function. Check if a node exists and error out in case none is present. Fixes: 3e9f0b3e2b27 ("input: Add MediaTek PMIC keys support") Signed-off-by: Matthias Brugger --- drivers/input/keyboard/mtk-pmic-keys.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c index 02c67a1749fc..388043e1939c 100644 --- a/drivers/input/keyboard/mtk-pmic-keys.c +++ b/drivers/input/keyboard/mtk-pmic-keys.c @@ -257,6 +257,9 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev) const struct of_device_id *of_id = of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev); + if (of_id == NULL) + return -ENODEV; + keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL); if (!keys) return -ENOMEM;