linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan@kernel.org>
To: John Hubbard <jhubbard@nvidia.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	gregkh@linuxfoundation.org, surenb@google.com,
	joaodias@google.com, willy@infradead.org, digetx@gmail.com
Subject: Re: [PATCH v6] mm: cma: support sysfs
Date: Tue, 23 Mar 2021 22:44:26 -0700	[thread overview]
Message-ID: <YFrRugjVLlazTNPy@google.com> (raw)
In-Reply-To: <d224c6bd-f5b1-74f6-2afc-c3d5b0519ba4@nvidia.com>

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 = kobject_create_and_add("cma", mm_kobj);
> > > > +	if (!cma_kobj_root)
> > > > +		return -ENOMEM;
> > > > +
> > > > +	for (i = 0; i < cma_area_count; i++) {
> > > > +		int err;
> > > > +		struct cma *cma;
> > > > +		struct cma_kobject *cma_kobj;
> > > > +
> > > > +		cma_kobj = 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.

Oh, I misunderstood that destroying of root kobject will release
children recursively. Seems not true. Go back to old version.


index 16c81c9cb9b7..418951a3f138 100644
--- a/mm/cma_sysfs.c
+++ b/mm/cma_sysfs.c
@@ -80,20 +80,19 @@ static struct kobj_type cma_ktype = {
 static int __init cma_sysfs_init(void)
 {
        unsigned int i;
+       int err;
+       struct cma *cma;
+       struct cma_kobject *cma_kobj;

        cma_kobj_root = kobject_create_and_add("cma", mm_kobj);
        if (!cma_kobj_root)
                return -ENOMEM;

        for (i = 0; i < cma_area_count; i++) {
-               int err;
-               struct cma *cma;
-               struct cma_kobject *cma_kobj;
-
                cma_kobj = kzalloc(sizeof(*cma_kobj), GFP_KERNEL);
                if (!cma_kobj) {
-                       kobject_put(cma_kobj_root);
-                       return -ENOMEM;
+                       err = -ENOMEM;
+                       goto out;
                }

                cma = &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;
                }
        }

        return 0;
+out:
+       while (--i >= 0) {
+               cma = &cma_areas[i];
+
+               kobject_put(&cma->kobj->kobj);
+               kfree(cma->kobj);
+               cma->kobj = NULL;
+       }
+       kobject_put(cma_kobj_root);
+
+       return err;
 }
 subsys_initcall(cma_sysfs_init);





  reply	other threads:[~2021-03-24  5:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24  1:05 [PATCH v6] mm: cma: support sysfs Minchan Kim
2021-03-24  2:34 ` John Hubbard
2021-03-24  3:27   ` Minchan Kim
2021-03-24  4:47     ` John Hubbard
2021-03-24  5:44       ` Minchan Kim [this message]
2021-03-24  6:26         ` John Hubbard
2021-03-24  6:57           ` Minchan Kim
2021-03-24  7:10             ` John Hubbard
2021-03-24 12:37         ` Dmitry Osipenko
2021-03-24 15:18           ` Minchan Kim
2021-03-24 12:33 ` Dmitry Osipenko
2021-03-24 15:12   ` Minchan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YFrRugjVLlazTNPy@google.com \
    --to=minchan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=digetx@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhubbard@nvidia.com \
    --cc=joaodias@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=surenb@google.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).