From patchwork Wed Mar 17 09:36:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yingjie Wang X-Patchwork-Id: 12145317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_50,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2E91C433DB for ; Wed, 17 Mar 2021 09:37:03 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5384464F41 for ; Wed, 17 Mar 2021 09:37:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5384464F41 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=126.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1A3EE100EB82D; Wed, 17 Mar 2021 02:37:03 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=123.126.96.3; helo=mail-m963.mail.126.com; envelope-from=wangyingjie55@126.com; receiver= Received: from mail-m963.mail.126.com (mail-m963.mail.126.com [123.126.96.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 085A1100EB829 for ; Wed, 17 Mar 2021 02:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=6myTYJ/6oXihRxGonF RwbGYMjlu+sduVYchFyN3kgEE=; b=FroKIg9E10IEsfVhExlbkntjUINapaat5x KmtHqtGmSyhSMwaMi9YsmULg6/DQO9fypijWXYcwbepEVEtVdNsuAIBWkgUeteP5 nUJlRSslv5OKz3KgjRSz2qMfVwrVel0aMPPkEaXuIUWj1NtsESyYHOfo0/MZJyZ8 xi1mrmqeQ= Received: from localhost.localdomain (unknown [116.162.2.6]) by smtp8 (Coremail) with SMTP id NORpCgDHqWiyzVFgW2EYFw--.6516S2; Wed, 17 Mar 2021 17:36:51 +0800 (CST) From: wangyingjie55@126.com To: dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, ira.weiny@intel.com Subject: [PATCH v1] libnvdimm, dax: Fix a missing check in nd_dax_probe() Date: Wed, 17 Mar 2021 02:36:39 -0700 Message-Id: <1615973799-16077-1-git-send-email-wangyingjie55@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: NORpCgDHqWiyzVFgW2EYFw--.6516S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrtFykKr4rJFyxArykKFy5XFb_yoWfKFbEkF y7Zr929Fy0krnayr42vr1fu34vyrn29r1kur4jgw13Ar4j9r13GrWkur9Ikrsagr4xZr1D urnFqFnxuF15ujkaLaAFLSUrUUUUbb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUj-J57UUUUU== X-Originating-IP: [116.162.2.6] X-CM-SenderInfo: 5zdqw5xlqjyxrhvvqiyswou0bp/1tbiWBRYp11w5leZjgABs5 Message-ID-Hash: W3CXPK26TVE7CHZOGZMUGSXAK62RRUHA X-Message-ID-Hash: W3CXPK26TVE7CHZOGZMUGSXAK62RRUHA X-MailFrom: wangyingjie55@126.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: wangyingjie55@126.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yingjie Wang In nd_dax_probe(), 'nd_dax' is allocated by nd_dax_alloc(). nd_dax_alloc() 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. Fixes: c5ed9268643c ("libnvdimm, dax: autodetect support") Signed-off-by: Yingjie Wang --- drivers/nvdimm/dax_devs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c index 99965077bac4..b1426ac03f01 100644 --- a/drivers/nvdimm/dax_devs.c +++ b/drivers/nvdimm/dax_devs.c @@ -106,6 +106,8 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) nvdimm_bus_lock(&ndns->dev); nd_dax = nd_dax_alloc(nd_region); + if (!nd_dax) + return -ENOMEM; nd_pfn = &nd_dax->nd_pfn; dax_dev = nd_pfn_devinit(nd_pfn, ndns); nvdimm_bus_unlock(&ndns->dev);