From patchwork Sat Apr 10 00:33:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yingjie Wang X-Patchwork-Id: 12195235 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 7C3A5C433ED for ; Sat, 10 Apr 2021 00:33:48 +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 CB57161108 for ; Sat, 10 Apr 2021 00:33:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB57161108 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 A4310100EAB7B; Fri, 9 Apr 2021 17:33:47 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=220.181.15.112; helo=m15112.mail.126.com; envelope-from=wangyingjie55@126.com; receiver= Received: from m15112.mail.126.com (m15112.mail.126.com [220.181.15.112]) (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 24F1A100EF265 for ; Fri, 9 Apr 2021 17:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=YjzmIwerweOGbfblgC /Ly+OrKlNwezN7iggMM3swgJM=; b=MJHaL0orm8TvdDuB7Ke+swd6jhy8BrifMI +AmmCaqyYsUXYS/mlvoGVJkb5MVHH8OlYONPAzTbVhf15OK1JCiodjpjbSWlC8pq Es3/zLe6WynvMoDcLRKBGHs0EpyF02SeZdbgyiAoQipLo2pQbY/zcpPjNl9+LSR6 7yGPEDbrc= Received: from localhost.localdomain (unknown [106.17.213.220]) by smtp2 (Coremail) with SMTP id DMmowAA3nwNa8nBgdqQBAQ--.18230S2; Sat, 10 Apr 2021 08:33:32 +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, linux-nvdimm@lists.01.org Subject: [PATCH v1] libnvdimm, dax: Fix a missing check in nd_dax_probe() Date: Fri, 9 Apr 2021 17:33:23 -0700 Message-Id: <1618014803-17231-1-git-send-email-wangyingjie55@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DMmowAA3nwNa8nBgdqQBAQ--.18230S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrtrW3XF15XF15Gw4rtry5urg_yoWfArXEkr 17Zr929Fy0kwnayr4aqr1fWryvyrs29r18ur4jgw13Ar4Y9r13GFykur9xtrsagr48urnr ur1DXFnxZF15GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjeyI5UUUUU== X-Originating-IP: [106.17.213.220] X-CM-SenderInfo: 5zdqw5xlqjyxrhvvqiyswou0bp/1tbiJRxwp13WGyhjMQAAsE Message-ID-Hash: LIJUL3B6IINDKLE6QOYHIDKUDBUXTWWR X-Message-ID-Hash: LIJUL3B6IINDKLE6QOYHIDKUDBUXTWWR 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-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_alloc() may fail and return NULL. Check for NULL before attempting to use nd_dax to avoid a NULL pointer dereference. 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);