public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Jason Noakes <jjnoakes@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: kobject_init and the zeroed-out-memory requirement
Date: Sun, 5 Oct 2014 14:51:00 -0700	[thread overview]
Message-ID: <20141005215100.GA20426@kroah.com> (raw)
In-Reply-To: <CAN2+FEKsVyjV8v98R+V-xHseH1E2NKPquo6Z9nQc0M8d0Z620A@mail.gmail.com>

On Sun, Oct 05, 2014 at 04:47:42PM -0400, Jason Noakes wrote:
> > Is there any in-kernel code that does not properly zero out the memory
> > before calling kobject_init()?
> 
> I'm not sure. I didn't find any, but I've seen it bite people writing
> drivers more than once where I work, and the latest oops I just
> debugged a few days ago prompted me to address the issue and at least
> get the documentation updated.

No driver should be working with "raw" kobjects.

> >> Many other *_init kernel routines (cdev_init, kref_init, mutex_init,
> >> spin_lock_init, etc) do not have the same requirement - they work on fully
> >> uninitialized memory.
> >
> > They all do different things, you can't compare apples to oranges :)
> 
> Well, they are all named "_init", which to me implies that they
> initialize the object/memory passed in, which is true in all of the
> other cases I mentioned, but not for kobject_init. Perhaps it should
> have been called kobject_setup or something. But I digress...

kobject_init() has been there for a very long time, and yes, we don't
always have the best naming scheme in the kernel, that comes from
evolution over the years.

> >> Documentation/kobject.txt does not mention the requirement that the memory be
> >> zero-initialized before it is passed to kobject_init.
> >
> > Add a line of text to the kerneldoc for kobject_init to mention this?
> >
> > Or (a) is fine as well, if it makes you feel better, but if you do so,
> > just say that all memory for kobjects must be created with kzalloc() and
> > don't mention memset as that will cause people to try to reuse kobjects,
> > like they have in the past, and bad things will happen then.
> 
> Here is a patch updating the documentation (kobject.txt and
> kobject_init's usage documentation) so that the zeroed-out-memory
> requirement is explicit.
> 
> Signed-off-by: Jason J. Noakes <jjnoakes@gmail.com>

Care to resend this in a format I can apply it in (i.e. without this
discussion above the patch forcing me to edit the changelog)?

thanks,

greg k-h

  reply	other threads:[~2014-10-05 21:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAN2+FEJY29jDF2PkGAYcG_0z=VQ4T+y7Ro56aeqrhSPYQ6ZEdw@mail.gmail.com>
2014-10-05 20:05 ` Fwd: kobject_init and the zeroed-out-memory requirement Jason Noakes
2014-10-05 20:28 ` Greg KH
2014-10-05 20:47   ` Jason Noakes
2014-10-05 21:51     ` Greg KH [this message]
2014-10-05 22:13       ` Jason Noakes
2014-10-05 23:24         ` Greg KH
2014-10-06  2:09           ` Guenter Roeck
2014-10-06  3:25             ` Greg KH
2014-10-06  5:18               ` Guenter Roeck

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=20141005215100.GA20426@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=jjnoakes@gmail.com \
    --cc=linux-kernel@vger.kernel.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