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 X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 236ABC433E0 for ; Wed, 24 Mar 2021 15:18:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BA6C619B8 for ; Wed, 24 Mar 2021 15:18:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BA6C619B8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 287586B02D8; Wed, 24 Mar 2021 11:18:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 236A76B02D9; Wed, 24 Mar 2021 11:18:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AFED6B02DA; Wed, 24 Mar 2021 11:18:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0057.hostedemail.com [216.40.44.57]) by kanga.kvack.org (Postfix) with ESMTP id E58B06B02D8 for ; Wed, 24 Mar 2021 11:18:26 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 99508A745 for ; Wed, 24 Mar 2021 15:18:26 +0000 (UTC) X-FDA: 77955124212.11.1DF8517 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf02.hostedemail.com (Postfix) with ESMTP id 55EC04142C4A for ; Wed, 24 Mar 2021 15:18:16 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id l76so2750470pga.6 for ; Wed, 24 Mar 2021 08:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=Wy41lOcDMCqF1sv7i74oJ72JYgkzMqX69KL4UTQ3RaY=; b=gi4Zq9MNODzEniAx1PvyRTVY4L5pUwLMxbEGAbSMoNIdNX77rB/rRDvhKInxND0x+b UWYFSU0QNv5ZTVwAfqEmLJb2AZgIixB4SmhksptlKFNA/kOrdIXmpB35Ip8BPkW0n1l+ uH9fnYxLxLEgxoTt2knBGIdU1g7Mh8/HPnBtFvMPfzX0yY6pLmSE2YOSTafiE6tCe8bs iFDU1qVgY6w0BgC394S4QTdwtrudeIJPIRjVdzI3De7WAx2xuOtpyK/Ee/hAJNUdSdvi rr81Vxrw+Hfn7iVz8Zui81H6Netl8hWxJEehGGyS5LJ0ddrf9fue6/F0zJKHmBb5mH6c 3S0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=Wy41lOcDMCqF1sv7i74oJ72JYgkzMqX69KL4UTQ3RaY=; b=pb9VOK9Ph34cFY41fuNvMwVQbWIi77eKuuv29loLYzBDeB+uTXbIty3h7PHFNyQVDo XD+iP+VkNRd9pYb6mlVNCJl3KuGvoo9K4qS4Qe6qsgyoqiSwB3huETY1wiu9GH3Xj9n2 wkdJ3ot3TaWk9v7/EDMP8fb9C9ozK0WbXD0UJ/VJVfeEQ7430aXW5yFFahCIdEmZh12o +4SrpSbUcyLw7mSwj0SxpvfT4DMvlN6wOUDCofDH5c9q7x0gxpaoDVZgcgjAZQtH/HgB KLrwnzp8pmkFcwyrpWUUeNwRGYFpAY4VitEke3o7i1gWFkOJyyn678KYg0BMjC4geICn CBNQ== X-Gm-Message-State: AOAM5304+Wbf1+fAGplNClDylo518XNGaw/Pg19sJrUzTI5knKDxtA3P UzNJX+jgckTDEXkIysp6djY= X-Google-Smtp-Source: ABdhPJx5vSCPCDw5fhRbyz3+gnLHOxVcg3Y1Toojiu4kcopw/kEAkm+KFKuY5ei6SdgJrwPQmRHpog== X-Received: by 2002:a62:82cb:0:b029:1f6:213b:6590 with SMTP id w194-20020a6282cb0000b02901f6213b6590mr3612705pfd.17.1616599097674; Wed, 24 Mar 2021 08:18:17 -0700 (PDT) Received: from google.com ([2620:15c:211:201:7dfa:1e53:536:7976]) by smtp.gmail.com with ESMTPSA id v2sm2818164pjg.34.2021.03.24.08.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 08:18:16 -0700 (PDT) Date: Wed, 24 Mar 2021 08:18:14 -0700 From: Minchan Kim To: Dmitry Osipenko Cc: John Hubbard , Andrew Morton , linux-mm , LKML , gregkh@linuxfoundation.org, surenb@google.com, joaodias@google.com, willy@infradead.org Subject: Re: [PATCH v6] mm: cma: support sysfs Message-ID: References: <20210324010547.4134370-1-minchan@kernel.org> <5b1a9f6c-ea7b-6e90-1c77-a49a10896f08@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5b1a9f6c-ea7b-6e90-1c77-a49a10896f08@gmail.com> X-Stat-Signature: gfcqrsdf3m9pywpqh4bu4nnkiymgord8 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 55EC04142C4A Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=mail-pg1-f173.google.com; client-ip=209.85.215.173 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616599096-799429 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Mar 24, 2021 at 03:37:02PM +0300, Dmitry Osipenko wrote: > 24.03.2021 08:44, Minchan Kim =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > > On Tue, Mar 23, 2021 at 09:47:27PM -0700, John Hubbard wrote: > >> On 3/23/21 8:27 PM, Minchan Kim wrote: > >> ... > >>>>> +static int __init cma_sysfs_init(void) > >>>>> +{ > >>>>> + unsigned int i; > >>>>> + > >>>>> + cma_kobj_root =3D kobject_create_and_add("cma", mm_kobj); > >>>>> + if (!cma_kobj_root) > >>>>> + return -ENOMEM; > >>>>> + > >>>>> + for (i =3D 0; i < cma_area_count; i++) { > >>>>> + int err; > >>>>> + struct cma *cma; > >>>>> + struct cma_kobject *cma_kobj; > >>>>> + > >>>>> + cma_kobj =3D kzalloc(sizeof(*cma_kobj), GFP_KERNEL); > >>>>> + if (!cma_kobj) { > >>>>> + kobject_put(cma_kobj_root); > >>>>> + return -ENOMEM; > >>>> > >>>> This leaks little cma_kobj's all over the floor. :) > >>> > >>> I thought kobject_put(cma_kobj_root) should deal with it. No? > >>> > >> If this fails when i > 0, there will be cma_kobj instances that > >> were stashed in the cma_areas[] array. But this code only deletes > >> the most recently allocated cma_kobj, not anything allocated on > >> previous iterations of the loop. > >=20 > > Oh, I misunderstood that destroying of root kobject will release > > children recursively. Seems not true. Go back to old version. > >=20 > >=20 > > index 16c81c9cb9b7..418951a3f138 100644 > > --- a/mm/cma_sysfs.c > > +++ b/mm/cma_sysfs.c > > @@ -80,20 +80,19 @@ static struct kobj_type cma_ktype =3D { > > static int __init cma_sysfs_init(void) > > { > > unsigned int i; > > + int err; > > + struct cma *cma; > > + struct cma_kobject *cma_kobj; > >=20 > > cma_kobj_root =3D kobject_create_and_add("cma", mm_kobj); > > if (!cma_kobj_root) > > return -ENOMEM; > >=20 > > for (i =3D 0; i < cma_area_count; i++) { > > - int err; > > - struct cma *cma; > > - struct cma_kobject *cma_kobj; > > - > > cma_kobj =3D kzalloc(sizeof(*cma_kobj), GFP_KERNEL); > > if (!cma_kobj) { > > - kobject_put(cma_kobj_root); > > - return -ENOMEM; > > + err =3D -ENOMEM; > > + goto out; > > } > >=20 > > cma =3D &cma_areas[i]; > > @@ -103,11 +102,21 @@ static int __init cma_sysfs_init(void) > > cma_kobj_root, "%s", cma->= name); > > if (err) { > > kobject_put(&cma_kobj->kobj); > > - kobject_put(cma_kobj_root); > > - return err; > > + goto out; > > } > > } > >=20 > > return 0; > > +out: > > + while (--i >=3D 0) { > > + cma =3D &cma_areas[i]; > > + > > + kobject_put(&cma->kobj->kobj); > > + kfree(cma->kobj); > > + cma->kobj =3D NULL; > > + } > > + kobject_put(cma_kobj_root); > > + > > + return err; > > } > > subsys_initcall(cma_sysfs_init); >=20 > Since we don't care about the order in which kobjects are put, I'd writ= e it in this way, which I think looks cleaner: >=20 Hmm, preference matter. That kinds of goto error handling for unwinding i= s familiar in kernel code and simple enough for me. I don't think readbilit= y is bad enough to need another cleanup function at this moment. > static void cma_sysfs_cleanup(struct kobject *cma_kobj_root) > { > struct cma *cma =3D cma_areas; > unsigned int i; >=20 > for (i =3D 0; i < cma_area_count; i++, cma++) { > if (!cma->kobj) > break; >=20 > kobject_put(&cma->kobj->kobj); > } >=20 > kobject_put(cma_kobj_root); > } >=20 > static int __init cma_sysfs_init(void) > { > struct kobject *cma_kobj_root; > unsigned int i; >=20 > cma_kobj_root =3D kobject_create_and_add("cma", mm_kobj); > if (!cma_kobj_root) > return -ENOMEM; >=20 > for (i =3D 0; i < cma_area_count; i++) { > struct cma_kobject *cma_kobj; > struct cma *cma; > int err; >=20 > cma_kobj =3D kzalloc(sizeof(*cma_kobj), GFP_KERNEL); > if (!cma_kobj) { > cma_sysfs_cleanup(cma_kobj_root); > return -ENOMEM; > } >=20 > cma =3D &cma_areas[i]; > cma->kobj =3D cma_kobj; > cma_kobj->cma =3D cma; > err =3D kobject_init_and_add(&cma_kobj->kobj, &cma_ktype, > cma_kobj_root, "%s", cma->name); > if (err) { > cma_sysfs_cleanup(cma_kobj_root); > return err; > } > } >=20 > return 0; > } > subsys_initcall(cma_sysfs_init);