From patchwork Tue May 22 11:46:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 10418193 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 12D1E600CC for ; Tue, 22 May 2018 11:39:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA02528BFB for ; Tue, 22 May 2018 11:39:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D84FC28C19; Tue, 22 May 2018 11:39: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, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D37CF28CC6 for ; Tue, 22 May 2018 11:39:16 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B449126765E; Tue, 22 May 2018 13:39:14 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id F018826765F; Tue, 22 May 2018 13:39:12 +0200 (CEST) Received: from huawei.com (unknown [45.249.212.35]) by alsa0.perex.cz (Postfix) with ESMTP id 8E0A926765C for ; Tue, 22 May 2018 13:39:10 +0200 (CEST) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 026E65732129; Tue, 22 May 2018 19:39:07 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.382.0; Tue, 22 May 2018 19:39:00 +0800 From: Wei Yongjun To: Srinivas Kandagatla , Sagar Dharia Date: Tue, 22 May 2018 11:46:22 +0000 Message-ID: <1526989582-139939-1-git-send-email-weiyongjun1@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Cc: kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org, Wei Yongjun , linux-kernel@vger.kernel.org Subject: [alsa-devel] [PATCH -next] slimbus: qcom: fix potential NULL dereference in qcom_slim_prg_slew() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP platform_get_resource() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code. This is detected by Coccinelle semantic patch. @@ expression pdev, res, n, t, e, e1, e2; @@ res = platform_get_resource_byname(pdev, t, n); + if (!res) + return -EINVAL; ... when != res == NULL e = devm_ioremap(e1, res->start, e2); Fixes: ad7fcbc308b0 ("slimbus: qcom: Add Qualcomm Slimbus controller driver") Signed-off-by: Wei Yongjun --- drivers/slimbus/qcom-ctrl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c index bb36a8f..caea3b9 100644 --- a/drivers/slimbus/qcom-ctrl.c +++ b/drivers/slimbus/qcom-ctrl.c @@ -478,6 +478,8 @@ static void qcom_slim_prg_slew(struct platform_device *pdev, /* SLEW RATE register for this SLIMbus */ slew_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "slew"); + if (!slew_mem) + return; ctrl->slew_reg = devm_ioremap(&pdev->dev, slew_mem->start, resource_size(slew_mem)); if (!ctrl->slew_reg)