Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp11012359rwd; Thu, 22 Jun 2023 07:42:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rf72acSxOl8SSZ7wD1akXHy584qNJsvt3BSPzUW2hNuAg50mjOYiltNbCtUMgST59fKvp X-Received: by 2002:a17:90a:66cd:b0:25b:f332:9108 with SMTP id z13-20020a17090a66cd00b0025bf3329108mr33804480pjl.2.1687444920635; Thu, 22 Jun 2023 07:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687444920; cv=none; d=google.com; s=arc-20160816; b=LJTLHkc1F0qpzW660cbG1My9lUxwWGp2VL09Wvr4nKWncQHetMRpZlgUuwIe3u7GHc 7bqpnDYvWqvOWoZX9QHeJ4sRQ12vT5qwB7z3elbTPGKrpoKtRN+aaTTYsCZ3Ws3c5fkt V8S6OkridbV/A6uiXufa77fghuJ2IpPsHA4p6Gu2W7cny4xdKV30o5IRKJaYcQqTVrSs YaITSj+6bo2TGWTECMRZcIKE+J27GtUWCdr12aG0kY9/hVS0VTjsE8t0QbbxNGk8/eom olJYu0ixlYL2G4KNFQLSe/cFBT8nmKfXJ4DD1+2uyZEBvvgMvr6+keyNhF+XgSvlkXYi GJJg== 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=5QNba9XPr7SZaMjHxyGS3XNW07Y54hOYlQMjyfpi7Ow=; b=d/5L/yocNmw59ZhL5VHo+ngRRtYZ6M8qI2cnchOV2duYBtXLX4bocL3u1laxDPEoaj gLITqZ9HyEpbEV00aCGPpIWFTsVW2P6mPfyQhXOQYn110fy2h231chjnCoFV89vZE+CV I+r6xbt5Y1acRtWMvqkgmQ0fQWlh2zaQuRt1Vf/+y0Xi4qMIkRi4VxamoMrGDJwskfoS aEQmiDha9TBii9T7ftvpBUCZil7hlGLcU1zWOG56lnIWjzKDvgLIsAgmaWR1aIiTlCCk bgHwZrUKr0qQVLRIsXCz6egFk8LuOhaKvvuU1rXHGMdSFayk2s/jXIkpffaegSftWK43 GKJg== 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 e8-20020a636908000000b0053011490008si6293187pgc.885.2023.06.22.07.41.47; Thu, 22 Jun 2023 07:42:00 -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 S231130AbjFVOcu (ORCPT + 99 others); Thu, 22 Jun 2023 10:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbjFVOcs (ORCPT ); Thu, 22 Jun 2023 10:32:48 -0400 Received: from cstnet.cn (smtp81.cstnet.cn [159.226.251.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 723FA10F6 for ; Thu, 22 Jun 2023 07:32:46 -0700 (PDT) Received: from ed3e173716be.home.arpa (unknown [124.16.138.129]) by APP-03 (Coremail) with SMTP id rQCowAAXHcWBW5RkGTrGAg--.21392S2; Thu, 22 Jun 2023 22:32:34 +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] libnvdimm/of_pmem: Replace kstrdup with devm_kstrdup and add check Date: Thu, 22 Jun 2023 22:32:32 +0800 Message-Id: <20230622143232.16863-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAAXHcWBW5RkGTrGAg--.21392S2 X-Coremail-Antispam: 1UD129KBjvdXoWruFWfWr4fZrW5ZrWrAFWfGrg_yoWDWFgEkr 1UXa43Wr4UCa9IkwsIywnakr9Ikw48uF4ruF1Fq3W3Ja98KF13JrWUArn8G393Zrn7JFsr Cr4DtFn8Jry7GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbcxFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJV WxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6ry5 MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbkR65UUUUU== X-Originating-IP: [124.16.138.129] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 --- 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..5106dfe0147b 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->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