From patchwork Mon Aug 28 06:23:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Ni X-Patchwork-Id: 13367584 X-Patchwork-Delegate: iweiny@gmail.com Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BB3BA4D for ; Mon, 28 Aug 2023 06:24:18 +0000 (UTC) Received: from localhost (unknown [124.16.138.129]) by APP-05 (Coremail) with SMTP id zQCowAA3PGCIPexk7dWPBg--.32603S2; Mon, 28 Aug 2023 14:24:08 +0800 (CST) From: Chen Ni To: oohall@gmail.com, dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, ira.weiny@intel.com Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, Chen Ni Subject: [PATCH] nvdimm: of_pmem: Add kfree for kstrdup Date: Mon, 28 Aug 2023 06:23:10 +0000 Message-Id: <20230828062310.6802-1-nichen@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: zQCowAA3PGCIPexk7dWPBg--.32603S2 X-Coremail-Antispam: 1UD129KBjvdXoWrurykJFWUWFW8Jw4xury3Jwb_yoWfXrcEkF 1UXFWSqr48Ca9Ik39Fywna9r9Ika18ZF4rZr1ag3W5JFZrJF43JrWUZrn5G393Zrs7GF9I kr1jkFn8Cry7GjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbc8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_GF1l 42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r 4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY 6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUYeHqDUUUU X-Originating-IP: [124.16.138.129] X-CM-SenderInfo: xqlfxv3q6l2u1dvotugofq/ Add kfree() for kstrdup() in order to avoid memory leak. Signed-off-by: Chen Ni --- drivers/nvdimm/of_pmem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 10dbdcdfb9ce..fe6edb7e6631 100644 --- a/drivers/nvdimm/of_pmem.c +++ b/drivers/nvdimm/of_pmem.c @@ -31,11 +31,17 @@ static int of_pmem_region_probe(struct platform_device *pdev) return -ENOMEM; priv->bus_desc.provider_name = 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; priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc); if (!bus) { + kfree(priv->bus_desc.provider_name); kfree(priv); return -ENODEV; }