From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDAEC433FE for ; Fri, 21 Oct 2022 08:05:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbiJUIFz (ORCPT ); Fri, 21 Oct 2022 04:05:55 -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 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) >> { > .