From: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
To: Michael Kelley <mikelley@microsoft.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"boqun.feng" <boqun.feng@gmail.com>,
kimbrownkd <kimbrownkd@gmail.com>
Subject: Re: [PATCH 1/1] genirq: Properly pair kobject_del with kobject_add
Date: Sat, 3 Aug 2019 09:15:55 +0200 [thread overview]
Message-ID: <20190803071555.GB24757@kroah.com> (raw)
In-Reply-To: <MWHPR21MB078463AB854A336842118405D7D90@MWHPR21MB0784.namprd21.prod.outlook.com>
On Fri, Aug 02, 2019 at 08:19:37PM +0000, Michael Kelley wrote:
> From: gregkh@linuxfoundation.org <gregkh@linuxfoundation.org> Sent: Thursday, August 1, 2019 11:34 PM
> > On Thu, Aug 01, 2019 at 11:53:53PM +0000, Michael Kelley wrote:
> > > If alloc_descs fails before irq_sysfs_init has run, free_desc in the
> > > cleanup path will call kobject_del even though the kobject has not
> > > been added with kobject_add. Fix this by making the call to
> > > kobject_del conditional on whether irq_sysfs_init has run.
> > >
> > > This problem surfaced because commit aa30f47cf666
> > > ("kobject: Add support for default attribute groups to kobj_type")
> > > makes kobject_del stricter about pairing with kobject_add. If the
> > > pairing is incorrrect, a WARNING and backtrace occur in
> > > sysfs_remove_group because there is no parent.
> > >
> > > Fixes: ecb3f394c5db ("genirq: Expose interrupt information through sysfs")
> > > Signed-off-by: Michael Kelley <mikelley@microsoft.com>
> > > ---
> > > kernel/irq/irqdesc.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
> > > index 9484e88..5447760 100644
> > > --- a/kernel/irq/irqdesc.c
> > > +++ b/kernel/irq/irqdesc.c
> > > @@ -438,7 +438,8 @@ static void free_desc(unsigned int irq)
> > > * The sysfs entry must be serialized against a concurrent
> > > * irq_sysfs_init() as well.
> > > */
> > > - kobject_del(&desc->kobj);
> > > + if (irq_kobj_base)
> > > + kobject_del(&desc->kobj);
> >
> > But now you leak the memory of desc as there is no chance it could be
> > freed, because the kobject release function is never called :(
>
> In the alloc_descs error path, when irq_kobj_base is still NULL, the
> kobject code sequence is:
> kobject_init() [as called by alloc_desc]
> kobject_put() [as called by delayed_free_desc]
>
> So I don't think anything leaks.
>
> If irq_kobj_base is not NULL, the kobject code sequence is:
> kobject_init() [as called by alloc_desc]
> kobject_add() [as called by irq_sysfs_add]
> kobject_del() [as called by free_desc]
> kobject_put() [as called by delayed_free_desc]
>
> Again, everything is paired up properly.
>
> >
> > Relying on irq_kobj_base to be present or not seems like an odd test
> > here.
> >
>
> It's the same test that is used in irq_sysfs_add to decide whether to
> call kobject_add. So it makes everything paired up and symmetrical.
Ugh, that's a tangled mess and totally not obvious at all. I'm sure
there's a good reason for all of that, and I really don't want to know
:)
Anyway, yes, you are right, the patch is fine, sorry for the noise.
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
greg k-h
next prev parent reply other threads:[~2019-08-03 7:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1564703564-4116-1-git-send-email-mikelley@microsoft.com>
2019-08-02 6:34 ` gregkh
[not found] ` <MWHPR21MB078463AB854A336842118405D7D90@MWHPR21MB0784.namprd21.prod.outlook.com>
2019-08-03 7:15 ` gregkh [this message]
2019-08-03 7:43 ` Thomas Gleixner
2019-08-19 14:01 ` [tip:irq/urgent] genirq: Properly pair kobject_del() with kobject_add() tip-bot for Michael Kelley
[not found] ` <20190819212758.6D03D22CEC@mail.kernel.org>
2019-08-19 21:58 ` Michael Kelley
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=20190803071555.GB24757@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=boqun.feng@gmail.com \
--cc=kimbrownkd@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=tglx@linutronix.de \
/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
Powered by JetHome