Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4030993rdb; Thu, 14 Sep 2023 09:40:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLMbdL9pKz28itXMDbNin/rzVA/2QOBsifLyKuuNUxznWfQg6Ohb1WSQcLcn9Bw5HJDiLW X-Received: by 2002:a17:902:e545:b0:1c4:1392:e4b4 with SMTP id n5-20020a170902e54500b001c41392e4b4mr2510577plf.20.1694709619116; Thu, 14 Sep 2023 09:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694709619; cv=none; d=google.com; s=arc-20160816; b=aFxUpks5sZMr3fQTtxrFB9CssM5cgxtgnEmpMKNd8Xzf8O3h1izXgmqT6Mmfadcc2c jkGXYmc+Rd0qSz1/9kAodZPxvZewBwpp7cqGrW9MWIYvzL+1sfFlzj0il0IDcCh8yWLJ nhDY2A6Thlm+85OV2cQZOUJLxWC6NjzT8AEWoeY+a5PTX4d0gIC2o8L9AiPzslDHprtY RcD3w9BIwPEVHMu2k60pco/fj2KTxSYXHq0E6OwA6wQlviS+yOFDxVktGfz2OlO7TgvL ngfW2FT3XON8CGCFKJWV0bYCo+4NsZmJbQ8FTCT6fe0OWkS50cZ+8CMGah4pInkVcSTL 4+sg== 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=XNyYEULC5bxsTingQGn6LgnjUfURWVdp9wZbHVG0t/Y=; fh=Vrycax08uga51SP6NYY6NxTLUEqAkqTr/T0uiIcwuoc=; b=jZFcg+lgBUxJ32Zy7IP48sJmgykuebyVlJWo98XTvr71LrlPlzNlZRhOYovwr6OKD6 H4yI6IdbcMxp4m8qM1aVwNXOfW5lozlAe2BLxWhG7fbqHDdknEvZ4WVfYXsyV99ENGnE OaAXlrLKMFa6pbZAwj7PqXzewBedHHrkBTQdDhq/IgEhmqw45+tjkDtTeNAcNE2iOMh9 uGMgT0Sl09bpDTK7BUr0rZGaEoblJCL1dMqEivd3ethwOQJ6KJ26l3iUoAKAHMcvehn7 YbyurspHNwkFcfao2eBogwXLvf2D/jTFWjqKewGEBu2M9VzENepGUNU4pZN8n7tdVdlo DwdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id lv14-20020a1709032a8e00b001bbc0ca8650si1929977plb.370.2023.09.14.09.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:40:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9EB4F8159635; Thu, 14 Sep 2023 00:04:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234381AbjINHEQ (ORCPT + 99 others); Thu, 14 Sep 2023 03:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230141AbjINHEP (ORCPT ); Thu, 14 Sep 2023 03:04:15 -0400 Received: from cstnet.cn (smtp81.cstnet.cn [159.226.251.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA619CE5 for ; Thu, 14 Sep 2023 00:04:10 -0700 (PDT) Received: from localhost (unknown [124.16.138.129]) by APP-03 (Coremail) with SMTP id rQCowAAHD6NfsAJl3Y7dDA--.34809S2; Thu, 14 Sep 2023 15:03:59 +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, aneesh.kumar@linux.ibm.com Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, Chen Ni Subject: [PATCH v3] libnvdimm/of_pmem: Use devm_kstrdup instead of kstrdup and check its return value Date: Thu, 14 Sep 2023 07:03:27 +0000 Message-Id: <20230914070328.2121-1-nichen@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAAHD6NfsAJl3Y7dDA--.34809S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKw4kJFyrKr4fAFyfKF17KFg_yoWDtwcEkr 18ZFyagr1UCa9IkwnIkwsa9Fyakw48uF48ZF1Fq3W3XFZrCF13XrWUArs8G39xZrn7tFsx Cr1qgF98Wr17GjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbc8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVWxJr 0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r4x MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUYMKZDUUUU X-Originating-IP: [124.16.138.129] X-CM-SenderInfo: xqlfxv3q6l2u1dvotugofq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 00:04:13 -0700 (PDT) Use devm_kstrdup() instead of kstrdup() and check its return value to avoid memory leak. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Chen Ni --- Changelog: v2 -> v3: 1. Use devm_kstrdup() instead of kstrdup() v1 -> v2: 1. Add a fixes tag. 2. Update commit message. --- drivers/nvdimm/of_pmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 1b9f5b8a6167..5765674b36f2 100644 --- a/drivers/nvdimm/of_pmem.c +++ b/drivers/nvdimm/of_pmem.c @@ -30,7 +30,13 @@ 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