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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EB13C433FE for ; Fri, 21 Oct 2022 08:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6FYEPHsnIanUnMIztpfhNbcXloyQZ79BYMd0BgbkoFM=; b=lYZA/qW3RCKgOuLjJ07Y07z+hX T8L5vVsRcJBYpOm7COfD9u5IzdYsyOAUBNi/8MN19RpxKRHwY21wSkPn2Di4n89p4LMovnH4O5osB O6MoPMyPUXIopUWnj5/Y4CBsDjC5T8NTOrvOpW3AQpBxXyzKo7QIexEixI1t7Ja/Tk5cKNK9/cUOd b57U+6F3TusxuUe3i510/D4o2ThOFh+o6sxfmC/uvDc0NJj/RWUrftRzdzqZGmDAg6cxIUcaA2KWw rMoIRPW8oO5FaIZClglkMi1D+ZZ6P39keaYqoWjHlI8UksbUThRt/D7Ea2COpUw7XNeuVSSHo6Jr/ 4rhsH+sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oln2U-006BlL-4D; Fri, 21 Oct 2022 08:05:58 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oln2R-006Bft-0t for linux-mtd@lists.infradead.org; Fri, 21 Oct 2022 08:05:57 +0000 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-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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221021_010555_278440_732DC003 X-CRM114-Status: GOOD ( 17.18 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.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) >> { > . ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/