Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3320607imw; Mon, 18 Jul 2022 06:10:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uWXTzG7cm8qoBtXyHDChLgxA75u5/d0OR8gjJWO//3TQHjBwcSMlHTWppZilKmUP5Hb0JL X-Received: by 2002:a0c:f40f:0:b0:473:223b:fabc with SMTP id h15-20020a0cf40f000000b00473223bfabcmr5861735qvl.109.1658149854453; Mon, 18 Jul 2022 06:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658149854; cv=none; d=google.com; s=arc-20160816; b=bhhInXmZEejYAf6D8Skw2442nKHtvZEW2xTTagS/1+hc205n1DAUt9d2CnVq3cKCmf Tj/WS6HpRjOF1xuhQhDCvwjMJECteYttX8bXEW8nxN4hukdi0RNrof8QkqZ5LIy86WWH VZ6AwkO0eGCQMEEIuoau6ec0n9ZvXzsJ/I3ZhoSi3JKG3lPvyDXcx6TH0klo2aoJybjm RwoDrBoyYgf/GOsYQYw8H5Sm7lEYTFv+0nHA9EFvfQpykBZriLHMQU0hBrnWx4LXVUVm 4LIeD+uwqHE0zyvlMzVj42brUt/uN8rui/p9HZzTsrDhg8f+Jf9U05/129Q45MpQH+zJ ovwg== 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=tBIVvl/QH4H/9irxZOSECUiIt+nY0lXvDKEdT11bYaM=; b=LaNT+7/xNywj009P/P0PNQpwFgIQ63s8wP8Oia2KzwgLry3U+QlFZ/gbfphESN2P3T vuWzpP2UrAU4hSX0pQNVVkSqH7gdfq689D0RKBPJO3EwDiyLnjL2goLi72U8njQPDTcQ YGKl8s3d0S/kXoBeRCbxKw3W8WlzgdhwwniJFgxpWuvrgyaENUw636rTvUL15h8s7INJ KKVe9KiGjqvH0tuyJ8q7HW+PaShK5OCjFEnzGa5q5u0tIKUcXrhW55lUlfI47+v29LcC DYaGnYj7aO75rbIc2OZzrVemAJdLj7DVr4kXm9X1CtotZjZupv7k2GApU6Cs5fxq1scB TF6A== 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 bm18-20020a05620a199200b006b5e8279ea4si1346652qkb.487.2022.07.18.06.10.37; Mon, 18 Jul 2022 06:10: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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235078AbiGRMnY (ORCPT + 99 others); Mon, 18 Jul 2022 08:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235099AbiGRMnN (ORCPT ); Mon, 18 Jul 2022 08:43:13 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71A4E25C71 for ; Mon, 18 Jul 2022 05:43:11 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LmhQ35clLz1M7xd; Mon, 18 Jul 2022 20:40:27 +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; Mon, 18 Jul 2022 20:43:08 +0800 Subject: Re: [PATCH -next,v4] nvmem: core: Fix memleak in nvmem_register() To: Srinivas Kandagatla , CC: , , References: <20220718122120.3103545-1-cuigaosheng1@huawei.com> From: cuigaosheng Message-ID: Date: Mon, 18 Jul 2022 20:43:08 +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="utf-8"; 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 > > What changed since v3? I adjusted the commit message because the implementation of the code has changed. > > Unnecessary braces here. Already fixed. Thanks, 在 2022/7/18 20:24, Srinivas Kandagatla 写道: > > > On 18/07/2022 13:21, 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 moving >> nvmem_validate_keepouts() after device_register() and let >> the device core deal with cleaning name in error cases. >> >> Fixes: de0534df9347 ("nvmem: core: fix error handling while >> validating keepout regions") >> Signed-off-by: Gaosheng Cui >> --- > > What changed since v3? > >>   drivers/nvmem/core.c | 16 +++++++--------- >>   1 file changed, 7 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c >> index 1e3c754efd0d..6067d3bbff5d 100644 >> --- a/drivers/nvmem/core.c >> +++ b/drivers/nvmem/core.c >> @@ -829,21 +829,19 @@ struct nvmem_device *nvmem_register(const >> struct nvmem_config *config) >>       nvmem->dev.groups = nvmem_dev_groups; >>   #endif >>   -    if (nvmem->nkeepout) { >> -        rval = nvmem_validate_keepouts(nvmem); >> -        if (rval) { >> -            ida_free(&nvmem_ida, nvmem->id); >> -            kfree(nvmem); >> -            return ERR_PTR(rval); >> -        } >> -    } >> - >>       dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", >> config->name); >>         rval = device_register(&nvmem->dev); >>       if (rval) >>           goto err_put_device; >>   +    if (nvmem->nkeepout) { >> +        rval = nvmem_validate_keepouts(nvmem); >> +        if (rval) { > > Unnecessary braces here. > > --srini >> +            goto err_device_del; >> +        } >> +    } >> + >>       if (config->compat) { >>           rval = nvmem_sysfs_setup_compat(nvmem, config); >>           if (rval) > .