Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1297489imw; Sat, 16 Jul 2022 03:32:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v3f0tpoU9uviuLbSe6A30tiwRUUDMixDzy1103Ak7H70LHW9y9yZDqF72/F/5OAFEBWDdf X-Received: by 2002:a17:902:b617:b0:16c:bd91:22eb with SMTP id b23-20020a170902b61700b0016cbd9122ebmr10004007pls.108.1657967521334; Sat, 16 Jul 2022 03:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657967521; cv=none; d=google.com; s=arc-20160816; b=FfBxAcg5eTIT9wG4JLC8mTNQHw+/kwXsRthmJa5XPiNvBRt9K9GvlWL4r2gw+yfTC/ aBbPt3OdHyUAIeEopckvmNK6xElL+C6hpPRzwwWvTFt6edBd3c7q/mxFYcXJR+O/K1F+ zcDwo3hmMEbFwqUIwMUMPHbJ98AP7ro44AfPj8u7qBNcZRBbpkFGTem3p3xvF7sKJ0Xl X1oeBAx4kYmC4cDUWS6sKWcO8jzye8kOvRFmn+zdBl7mxm2SD99argkS0WB57vjEplHr Ht8Ga9RSd5CLzxKs1DKofclMqDII8Pgyvl0T2UI3wNsKHh8c8CJb7BMfsL7pLSJYs8BE cL/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=2LH15c4xt7NJbN1cqfSEkHK1f9CqKqoWDSLN2M2jQfM=; b=0evVs+zghDB3hBKg0sdL/zadRMNPlPkJ6MzoCOnb2YZg++gogEu/3LfjeOat5+JItD I5J2Gew5RdIQGRDLVtrfUG8tLmq7sxW0gF229beN+8lpX7LO/2yalwt9L47LjBPbRrh6 VuUv0cn9FpY7/ODtaL0tGZyWGjo2TusVE+Sp1fWo8HJaDvv5ScE8qPrY+vC1UYQgdm0u X0mMWif0UlaITQzQNlOP0OajC0IyHyP2ZBRj3pnOPEvt+d2mLgy2pUmPHJCjaQAZm5nV 5PkR7GrvlNMwnbeKIxgoZUbK1GYeslzfnim648aw3b7DB2rtkTe2wjrTcw7XBt/kwVea JiOg== 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 k82-20020a628455000000b0052aceb310c2si7855040pfd.95.2022.07.16.03.31.44; Sat, 16 Jul 2022 03:32:01 -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 S232333AbiGPJ7T (ORCPT + 99 others); Sat, 16 Jul 2022 05:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbiGPJ7S (ORCPT ); Sat, 16 Jul 2022 05:59:18 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF351C111 for ; Sat, 16 Jul 2022 02:59:15 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LlNtK4QvPzkWKB; Sat, 16 Jul 2022 17:56:57 +0800 (CST) Received: from [10.67.110.176] (10.67.110.176) 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 17:59:13 +0800 Subject: Re: [PATCH -next] nvmem: core: Fix memleak in nvmem_register() To: Greg KH CC: , , , References: <20220716075352.2622809-1-cuigaosheng1@huawei.com> From: cuigaosheng Message-ID: <544cfbdb-9005-3d4d-58f9-258f875984dd@huawei.com> Date: Sat, 16 Jul 2022 17:59:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.176] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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,NICE_REPLY_A, 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 Thanks for your time. I have made the v2 patch and moving dev_set_name after nvmem_validate_keepouts to fix the issue, hope you can provide some advice. Thanks. ?? 2022/7/16 16:23, Greg KH ะด??: > On Sat, Jul 16, 2022 at 03:53:52PM +0800, Gaosheng Cui wrote: >> 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); > Something is really wrong, you should never be touching the name pointer > of a kobject directly like this. Also the device structure itself > should be cleaning up the memory, not a kfree. So this feels wrong... > > greg k-h > .