[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20071129110512.02ae44e1@gondolin.boeblingen.de.ibm.com>
Date: Thu, 29 Nov 2007 11:05:12 +0100
From: Cornelia Huck <cornelia.huck@...ibm.com>
To: Alan Stern <stern@...land.harvard.edu>
Cc: Greg KH <greg@...ah.com>, Kay Sievers <kay.sievers@...y.org>,
Kernel development list <linux-kernel@...r.kernel.org>,
Jonathan Corbet <corbet@....net>,
Randy Dunlap <randy.dunlap@...cle.com>
Subject: Re: [PATCH] kobject: make sure kobj->ktype is set before
kobject_init
On Wed, 28 Nov 2007 17:00:57 -0500 (EST),
Alan Stern <stern@...land.harvard.edu> wrote:
> On Wed, 28 Nov 2007, Greg KH wrote:
>
> > On Wed, Nov 28, 2007 at 03:42:00PM -0500, Alan Stern wrote:
> > > This patch (as1020) adds a check to kobject_init() to insure that the
> > > ktype field is not NULL. This is just for safety's sake; as far as I
> > > know there are no remaining places where the field is left unset. But
> > > ironically, kset_init() did fail to set it! The patch fixes that and
> > > removes some redundant initialization in kset_createa().
> > >
> > > The patch also fixes up elevator_init(), where ktype was set after
> > > calling kobject_init() instead of before.
> >
> > No, it's safe to set ktype after kobject_init, it was just not safe to
> > set the kset. As Kay pointed out, I just added a patch to my tree to
> > resolve this issue, and I'll go back and update the documentation now.
> >
> > I do like the "check for a ktype" warning, I'll go add that to my local
> > tree and see what breaks. Odds are, all the static kobjects will :(
>
> You have to be careful. The ktype check I wrote lives in
> kobject_init() -- that's why I had to make elevator_init() assign the
> ktype before calling kobject_init(). If you put the check into
> kobject_add() instead then you won't end up checking objects that get
> initialized but not added.
>
> Yes, nobody would deliberately use a kobject without adding it, but it
> could happen as the result of an failure between the _init and _add
> calls.
And if someone calls kobject_put() after kobject_init() to clean up,
their release function will not be called if they didn't set the ktype.
So the check really belongs into kobject_init() IMO.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists