From: Jason Gunthorpe <jgg@ziepe.ca>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Matthew Wilcox <willy@infradead.org>,
Wang Hai <wanghai38@huawei.com>,
cl@linux.com, penberg@kernel.org, rientjes@google.com,
iamjoonsoo.kim@lge.com, akpm@linux-foundation.org,
khlebnikov@yandex-team.ru, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: kobject_init_and_add is easy to misuse
Date: Wed, 3 Jun 2020 21:23:16 -0300 [thread overview]
Message-ID: <20200604002316.GM6578@ziepe.ca> (raw)
In-Reply-To: <1591217780.13983.56.camel@HansenPartnership.com>
On Wed, Jun 03, 2020 at 01:56:20PM -0700, James Bottomley wrote:
> The store of state_in_sysfs is already done in kobject_add_internal().
> It's an existing flag people already use to tell if the kobject has
> been exposed in sysfs. However, it's set after the sysfs directory
> creation succeeds. This is the code with some debugging removed:
>
> error = create_dir(kobj);
> if (error) {
> kobj_kset_leave(kobj);
> kobject_put(parent);
> kobj->parent = NULL;
> ...
> } else
> kobj->state_in_sysfs = 1;
I was thinking most probably this will need a lock or a
smp_store_release() ..
> > It feels more robust to stick with the put though..
>
> possibly ... like I said, the only concern with the put path is that
> ->release has state expectations that aren't met if
> kobject_init_and_add fails.
Certainly error unwind bugs related to put and release will exist, but
I suspect switching to kfree won't solve them, just move them to the
next function that fails and needs a put based unwind?
At least the patches I reviewed for RDM a from Wang Hai were all
correct and didn't seem to have release based errors.
Jason
next prev parent reply other threads:[~2020-06-04 0:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 11:50 [PATCH] mm/slub: fix a memory leak in sysfs_slab_add() Wang Hai
2020-06-02 12:10 ` kobject_init_and_add is easy to misuse Matthew Wilcox
2020-06-02 13:48 ` Konstantin Khlebnikov
2020-06-02 14:04 ` Greg Kroah-Hartman
2020-06-02 14:57 ` Matthew Wilcox
2020-06-02 15:25 ` James Bottomley
2020-06-02 17:36 ` Greg Kroah-Hartman
2020-06-02 19:54 ` James Bottomley
2020-06-02 20:07 ` Greg Kroah-Hartman
2020-06-02 21:51 ` James Bottomley
2020-06-03 0:04 ` James Bottomley
2020-06-03 0:22 ` Jason Gunthorpe
2020-06-03 18:04 ` James Bottomley
2020-06-03 18:36 ` Jason Gunthorpe
2020-06-03 19:02 ` James Bottomley
2020-06-03 19:30 ` Jason Gunthorpe
2020-06-03 20:56 ` James Bottomley
2020-06-04 0:23 ` Jason Gunthorpe [this message]
2020-06-02 19:46 ` Jason Gunthorpe
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=20200604002316.GM6578@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=gregkh@linuxfoundation.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=khlebnikov@yandex-team.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=wanghai38@huawei.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).