Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1207638imw; Sat, 16 Jul 2022 01:02:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vdpLBv+I3Mr2QQ3s6KHhOf6BxU7ZYL4iIFh7+ShYlnXZOTwDvN0PPlha9Afw3I3kUsZFqn X-Received: by 2002:a17:907:b590:b0:72b:91f3:d4ef with SMTP id qx16-20020a170907b59000b0072b91f3d4efmr17662006ejc.29.1657958562284; Sat, 16 Jul 2022 01:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657958562; cv=none; d=google.com; s=arc-20160816; b=Ucjj+rjm5zHDwbtNcwoqhLWiKBXd4kzrw9Ic/si86L1z5rG/2eEFwQquckQRIECYXu ts+RanGTzIN7BWlpVVp/gbQEEQ79+vMQ4TvDPrbZ7tLyVlLDqNwxXXYN3p2GwP/utIL5 mFzhNS3+4nC1AOirgKVTF7c+lUCVmrCFx2wSvoXgRbEMXiplVPsxPl8YxvQC8Qrp2Jdk psLciTx5E+EEWkW1QAQG6Y3JuC+fBuZogzf2IRw9LIShbYExB8iot/XMIL/PdVTUR1XP Ii9Pbesm74eJpmMu/J//uzLN/k9RKt4WqQq8ReccAj3FblRMzZV0vAjmAFmoa24XcWJU OMnQ== 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=smvX94Rba3lCsm9v6Od5H0C24IGKwQFiS3db0EPT5vY=; b=z1Zui271O0qm4axRfqX4etbv7WN458lOMlj5TacsPebi6MjRuVh1vjd5vqO+Tvq35C wvwaGSTId/0T1TQfrUKuQummPRTS4yVvSgbeTzYVpa1lSX8vfkrIJVBcDNDNZJckDA0I rwzBxm6jVdoann42ligNLH4t8N7dzS6O39zUT5vYIbUCDEFPIjSgncRz5V4a9PtubrvZ kikMLcvRlRvsDxMbBXljB8jbL5oEZVn5lep1Gun4ovoZKvuIwb+xJRH8ukNnDjbV5rov h46YfDPnfFYfE5wA+rFPbwCpdwJcKinYMAufBDWMoqyzm7XxditfON4s5p0WQdXn9UET 33jg== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc8-20020a1709071c0800b00722d8f8fe8asi8968118ejc.422.2022.07.16.01.02.08; Sat, 16 Jul 2022 01:02:42 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbiGPHyA (ORCPT + 99 others); Sat, 16 Jul 2022 03:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbiGPHx6 (ORCPT ); Sat, 16 Jul 2022 03:53:58 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB7FBFD14 for ; Sat, 16 Jul 2022 00:53:55 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LlL7B4wQ6zFq1y; Sat, 16 Jul 2022 15:52:54 +0800 (CST) Received: from dggphis33418.huawei.com (10.244.148.83) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 16 Jul 2022 15:53:52 +0800 From: Gaosheng Cui To: , , CC: , , Subject: [PATCH -next] nvmem: core: Fix memleak in nvmem_register() Date: Sat, 16 Jul 2022 15:53:52 +0800 Message-ID: <20220716075352.2622809-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 dev_set_name will alloc memory for nvmem->dev.kobj.name in nvmem_register, when nvmem_validate_keepouts failed, nvmem's memory will be freed and return, but nobody will free memory for nvmem->dev.kobj.name, there will be memleak, so using kfree_const(nvmem->dev.kobj.name) to fix it. Fixes: de0534df9347 ("nvmem: core: fix error handling while validating keepout regions") Signed-off-by: Gaosheng Cui --- drivers/nvmem/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 1e3c754efd0d..6c75c9afa5f3 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -833,6 +833,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) rval = nvmem_validate_keepouts(nvmem); if (rval) { ida_free(&nvmem_ida, nvmem->id); + kfree_const(nvmem->dev.kobj.name); kfree(nvmem); return ERR_PTR(rval); } -- 2.25.1