Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30202114rwd; Thu, 6 Jul 2023 02:21:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlHvRQyCU3OIdwVWGhNE29beHGksbJp/0Lydd7PzkMOddF8l4CAfXZWmA7b/RFZAl4KeAVXT X-Received: by 2002:a05:6808:218b:b0:3a1:eb7c:21d8 with SMTP id be11-20020a056808218b00b003a1eb7c21d8mr1701051oib.39.1688635284465; Thu, 06 Jul 2023 02:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688635284; cv=none; d=google.com; s=arc-20160816; b=IOWwTY0CZH1aSAxqb82oBkpK1itthY04KgfNUxLagqm/BaIj8fdld5RHJViocVJJhn ADPEanH4qa1IL4CjsVhH6r6TpMV5bcilz/9JRqnzIDcCcBTUGDfL1MVLl8McJ9C/TAn2 C8KYiuqRlJNQ7wIRfAnq5Xb0qfDh0yX+ojZZCmkiW6S6Ye3d2BGSu5HjfSllD13Nzj1M 5EI62qeqGoKwFW8HSLD655n3/MTb2HHU6G5dRLK1KymlfGnV/Gd0OhYkjOck8GzVCs6N 8CP+/iXCCvUaS/9YL9lqx+nvokeQV++isgGGuw5ulLOrWQWSLPs+pBpffdN89EzPXjMz 92eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+Gow+DcXxX22fqA/120WNYVCPO3hcJFO+6AuCYYBXck=; fh=++whkhXdmlAQdxIYkwkiN3CnOGX/lgQJFGlEpr+DQjE=; b=07Ex738YTmLIlfViLvmKH0zJ4cgvjGf5NplxxFlBs210Aa9JGb8XArVLepYq1VHvlj z490JlIbdBI/gY8jgzcf0eGHkl8fFiNpDkdKxRDWBwlV1qMZwepSsVueZ8/+0rwC1l/7 hjsEut9Y+knYLhMYRH1PfD/z4obDE2Cwr/7+f4/fo+aHyExWlm0Wi1VUuRjxGpUN0KpF s3KwFri67hc5gzJjV6eia2e8l8279rOzC/RlY/BPq21RIwJ2deTxINXnuIQRsCNZkrJn XFjndiLCyrRbRtt0pXrchJDIdKEcNKON12cD4u9BNot9o+uspHriWv3aTC3j7o6iLNlZ tYDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f38-20020a631026000000b0054fda551fecsi1026731pgl.426.2023.07.06.02.21.10; Thu, 06 Jul 2023 02:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231693AbjGFI64 (ORCPT + 99 others); Thu, 6 Jul 2023 04:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbjGFI6z (ORCPT ); Thu, 6 Jul 2023 04:58:55 -0400 Received: from cstnet.cn (smtp25.cstnet.cn [159.226.251.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0FB61990 for ; Thu, 6 Jul 2023 01:58:53 -0700 (PDT) Received: from ed3e173716be.home.arpa (unknown [124.16.138.129]) by APP-05 (Coremail) with SMTP id zQCowADX3rJAgqZkbVj+CA--.43353S2; Thu, 06 Jul 2023 16:58:40 +0800 (CST) From: Jiasheng Jiang To: ira.weiny@intel.com, dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, oohall@gmail.com, aneesh.kumar@linux.ibm.com Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v3] libnvdimm/of_pmem: Replace kstrdup with devm_kstrdup and add check Date: Thu, 6 Jul 2023 16:58:39 +0800 Message-Id: <20230706085839.31145-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowADX3rJAgqZkbVj+CA--.43353S2 X-Coremail-Antispam: 1UD129KBjvdXoWruFWfWr4fZrW5ZrWrAFWfGrg_yoWkAFcEkr 40va43Xr1UC39I9wnIkwnakF9Ikw4UuFWrurnYq3ZxJFZ8GF13JrWUAws8G393Xrn7JFsx ur4qqFZ8Wr9rGjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbc8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVWxJr 0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r43 MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUeHUDDUUUU X-Originating-IP: [124.16.138.129] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace kstrdup() with devm_kstrdup() to avoid memory leak and add check for the return value of the devm_kstrdup() to avoid NULL pointer dereference Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Jiasheng Jiang --- Changelog: v2 -> v3: 1. Correct the usage of devm_kstrdup(). v1 -> v2: 1. Replace kstrdup() with devm_kstrdup(). --- drivers/nvdimm/of_pmem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 10dbdcdfb9ce..1d2b1ab5b737 100644 --- a/drivers/nvdimm/of_pmem.c +++ b/drivers/nvdimm/of_pmem.c @@ -30,7 +30,12 @@ static int of_pmem_region_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; - priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL); + priv->bus_desc.provider_name = devm_kstrdup(&pdev->dev, pdev->name, GFP_KERNEL); + if (!priv->bus_desc.provider_name) { + kfree(priv); + return -ENOMEM; + } + priv->bus_desc.module = THIS_MODULE; priv->bus_desc.of_node = np; -- 2.25.1