Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2249994rwi; Fri, 21 Oct 2022 01:20:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fyVX2qdRBPjcoifQh6csQ2EJ1TCcW4gYni32+irOPn9JvgBnMLr1CaTbZgogSliUnHCoL X-Received: by 2002:a65:6bd3:0:b0:42b:9117:b9d1 with SMTP id e19-20020a656bd3000000b0042b9117b9d1mr15191146pgw.238.1666340443555; Fri, 21 Oct 2022 01:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666340443; cv=none; d=google.com; s=arc-20160816; b=uM0T/mOOn5so2jSsiiZcFHCeRgCsBZTkeJJGpLwVVijWSbbMNjBEGABAJCh9iSBgt3 /T/afu7hCAt2JqfcRR9Kp7OjZz5ybM2g3ylhU5SC5pZeXbeVe0uIvkxbvbkfXkj66Lbi dlo1GMYIyGEZr8yMfWWI6BkEj4DTFQ7rPBJ6XRmJmrxnyiRcwAfpu4YoQ3GXtqaMjnog aWYXI+uM2RiPSexckJK343zRObUHp1XlRdwEbz6DxzKamx+raRBmhuuZezD2fz3ZFaZb 05UWanHslIurk1fDCDBPobMFZ/ap7m1RgzBxj8XaIw2WTTjbw3nZYksLMKx+ZTtvjaTt wt+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=TbkWa8UpOuwWbaKsXoVj1MqIDQZJ376yxEpng9yYR/s=; b=TIMqq2WANfcDpPgLNRjxxJvVu0hb8WFxEjlrnbw5dbwWo8Nv6w4Fjxdy+Qi7rSLtjb T4lFi8L7M/jYZqgW6Vvq2FAfrhvigD7aQdhEG9aZ8NBHdZobgGkinmNqW8fFtVoFNu7X cGjtCEUjjWRiD24XxKvvjc//mZU1vyQTDLYcR14yyQ7XPDUB4fnOYdfXSCSJuaynWlBM 0QzzTk9sjiMKhS1lIGhhp3PzbksNhBQWDTKN411VmZzafJ+8Tb5DrIIsutlXFVpmFrWP KmOgAJJ2g5m44FBq5gpATJy22fwEDWpyVGO023DrCrrsWyBOeXKEC9aHv/IMJQvQY9q/ fIZA== 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 p8-20020a17090a868800b00206012b593csi6258869pjn.33.2022.10.21.01.20.31; Fri, 21 Oct 2022 01:20:43 -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 S229925AbiJUIFy (ORCPT + 99 others); Fri, 21 Oct 2022 04:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbiJUIFw (ORCPT ); Fri, 21 Oct 2022 04:05:52 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BE81EA563 for ; Fri, 21 Oct 2022 01:05:49 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mtxjn0wbFzmVCy; Fri, 21 Oct 2022 16:01:01 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:05:20 +0800 Received: from [10.174.178.174] (10.174.178.174) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:05:19 +0800 Subject: Re: [PATCH 01/11] kset: fix documentation for kset_register() To: Luben Tuikov , , , , , , , , CC: , , , , , , , , , , , , , References: <20221021022102.2231464-1-yangyingliang@huawei.com> <20221021022102.2231464-2-yangyingliang@huawei.com> From: Yang Yingliang Message-ID: <10d887c4-7db0-8958-f661-bd52e6c8b4af@huawei.com> Date: Fri, 21 Oct 2022 16:05:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.178.174] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500007.china.huawei.com (7.185.36.183) 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,URIBL_BLOCKED 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 On 2022/10/21 13:34, Luben Tuikov wrote: > On 2022-10-20 22:20, Yang Yingliang wrote: >> kset_register() is currently used in some places without calling >> kset_put() in error path, because the callers think it should be >> kset internal thing to do, but the driver core can not know what >> caller doing with that memory at times. The memory could be freed >> both in kset_put() and error path of caller, if it is called in >> kset_register(). >> >> So make the function documentation more explicit about calling >> kset_put() in the error path of caller. >> >> Signed-off-by: Yang Yingliang >> --- >> lib/kobject.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/lib/kobject.c b/lib/kobject.c >> index a0b2dbfcfa23..6da04353d974 100644 >> --- a/lib/kobject.c >> +++ b/lib/kobject.c >> @@ -834,6 +834,9 @@ EXPORT_SYMBOL_GPL(kobj_sysfs_ops); >> /** >> * kset_register() - Initialize and add a kset. >> * @k: kset. >> + * >> + * If this function returns an error, kset_put() must be called to >> + * properly clean up the memory associated with the object. >> */ > And I'd continue the sentence, with " ... with the object, > for instance the memory for the kset.kobj.name when kobj_set_name(&kset.kobj, format, ...) > was called before calling kset_register()." kobject_cleanup() not only frees name, but aslo calls ->release() to free another resources. > > This makes it clear what we want to make sure is freed, in case of an early error > from kset_register(). How about like this: If this function returns an error, kset_put() must be called to clean up the name of kset object and other memory associated with the object. > > Regards, > Luben > >> int kset_register(struct kset *k) >> { > .