mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland Dreier <roland@topspin.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] cdev_init: zero out cdev before kobject_init()
Date: Sun, 14 Nov 2004 17:11:47 -0800	[thread overview]
Message-ID: <52u0rrq5kc.fsf@topspin.com> (raw)

Right now, cdev_init() works in a way that is not very intuitive.  If
a driver passes an uninitialized struct cdev to cdev_init(), then an
uninitialized struct kobject will be passed to kobject_init(), which
does kset_get() on kobj->kset, which probably points off into space
and causes an oops.  Drivers can work around this by zeroing out their
struct cdev in advance (and indeed most if not all of the things
passed to cdev_init() come from BSS) but I think it makes more sense
for cdev_init() to live up to its name and actually work on an
uninitialized cdev.

Signed-off-by: Roland Dreier <roland@topspin.com>

Index: x/fs/char_dev.c
===================================================================
--- x.orig/fs/char_dev.c	2004-11-14 17:02:48.000000000 -0800
+++ x/fs/char_dev.c	2004-11-14 17:03:39.000000000 -0800
@@ -417,6 +417,7 @@
 
 void cdev_init(struct cdev *cdev, struct file_operations *fops)
 {
+	memset(cdev, 0, sizeof *cdev);	
 	INIT_LIST_HEAD(&cdev->list);
 	cdev->kobj.ktype = &ktype_cdev_default;
 	kobject_init(&cdev->kobj);

                 reply	other threads:[~2004-11-15  1:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=52u0rrq5kc.fsf@topspin.com \
    --to=roland@topspin.com \
    --cc=akpm@osdl.org \
    --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

Powered by JetHome