Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5845154rwd; Sun, 18 Jun 2023 21:03:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rsF4FjsKMMukQQO6abKu6IUIK0LfbMRGvp7/gpGrz2TvwgAhUmYI2ihn2m8c0bd6j+Tx2 X-Received: by 2002:a05:6214:2347:b0:625:1c04:6761 with SMTP id hu7-20020a056214234700b006251c046761mr9615870qvb.27.1687147434958; Sun, 18 Jun 2023 21:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687147434; cv=none; d=google.com; s=arc-20160816; b=hDswfuQhtCsKiiOWVuShBZKunwhuizyiKViXYCx9Iu3LjFNZrwu9ostqPr3q98Xve1 txKZmqcgphA+MtNsVxBTtwOOVt846WunXJvTiLLf6Ww8e2DNF9ZGhE6waGp8+XzmB6X9 8lV5kwb2KtdJM75u1hV7Xw8Nmr6gB/FdYq4wEVBb1lPnLW/T7ZKdWx+1iJIdaC80ucK3 W+LeUAkv+ghTkwAS/FPrH2vUYSomNC1oJ9ss4xwI7iNHnDkORR2UDungTcUAhAEPjCny WQC65/Wy7hKwqP/jo7NJBEaOf3y+UGJimsnWSYKIoVKpIzgezyT0dwKskB1WpAu6MIYc nHTw== 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=9+xVtWnSNDe+huBcHOCrkOFQ46OiqE+FsnhAf65rjco=; b=itb1zkBZ+DK4UsDsE8lrOzQEc5TWC9Xcu2l9lsfaJNY3GRFM5cJcNYHMtLMlKwmXHp Gio+T76HKsSU/RjtoEytYfD2YajPlQIURx5eo/GcgSjt7Z+vrva2niXSYjEKmWhItPx5 YqnE2jMuWRMPlYafmJhQPNIvbFtZ8apNnYj6w5f5ebpEtPf2XALMgE7JEVMg75NTvxJ1 0DApJwUA84GTIw5pzqaNI/VN4u5kC6IAazJCmEIQdMIiI1qNYrw54TM7BCwy2LIiXcEq J1SXibzVVQRN3ot5zI6ohDtwruIwbos5J9ljArJK1LqhPBYIc8r2P7A6jEu0jJg7gpYi Hfiw== 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 u64-20020a638543000000b005509c8e0ac3si8467364pgd.698.2023.06.18.21.03.40; Sun, 18 Jun 2023 21:03:54 -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 S229781AbjFSDgg (ORCPT + 99 others); Sun, 18 Jun 2023 23:36:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjFSDge (ORCPT ); Sun, 18 Jun 2023 23:36:34 -0400 Received: from cstnet.cn (smtp80.cstnet.cn [159.226.251.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6454183 for ; Sun, 18 Jun 2023 20:36:33 -0700 (PDT) Received: from ed3e173716be.home.arpa (unknown [124.16.138.129]) by APP-01 (Coremail) with SMTP id qwCowAAHDws4zY9k6sFGAQ--.12194S2; Mon, 19 Jun 2023 11:36:25 +0800 (CST) From: Jiasheng Jiang To: dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, ira.weiny@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: Add check and kfree for kstrdup Date: Mon, 19 Jun 2023 11:36:23 +0800 Message-Id: <20230619033623.11044-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowAAHDws4zY9k6sFGAQ--.12194S2 X-Coremail-Antispam: 1UD129KBjvdXoWrur45XrWxZF1fArWxWryDJrb_yoWkXrcEkr 1UXFy3Wr4xC3sakwsFywna9r9Ika1qvr1rZr1Sg3WayFZrGa13JrWUZrn5Gws3Zrn7tF9F kr1jkF98Cry7GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbcAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F 4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_ Gr4l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI 42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUnQ6pDUUUU 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 Add check for the return value of kstrdup() and return the error if it fails in order to avoid NULL pointer dereference. Moreover, use kfree() in the later error handling in order to avoid memory leak. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Jiasheng Jiang --- 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; } -- 2.25.1