From: Dave Olien <dmo@osdl.org>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] 2.6.0-test4-mm2 drivers/char.c Oops on open()
Date: Thu, 28 Aug 2003 16:18:53 -0700 [thread overview]
Message-ID: <20030828231853.GA7192@osdl.org> (raw)
The raw.c character device Oopses dereferencing a NULL pointer in bd_claim()
This problem occurred after bd_claim() in block_dev.c was modified to "claim
the whole device when a partition is claimed".
raw_open() made the mistake of calling bd_claim BEFORE calling
blkdev_get(). At that time, the bdev->bd_contains field. has't been
initialized yet. Switching the order allows blkdev_get() to initialize
those fields before calling bd_claim().
Also fixed up some error return paths:
igrab() should never fail under these circumstances since the caller
already has a reference to that inode through the bdev at that time.
In the event of blkdev_get() failure or set_blocksize() failure, not
all the work to unwind from the error was done.
--- linux-2.6.0-test4-mm2_original/drivers/char/raw.c 2003-08-28 13:16:03.000000000 -0700
+++ linux-2.6.0-test4-mm2_raw/drivers/char/raw.c 2003-08-28 14:07:44.000000000 -0700
@@ -60,25 +60,25 @@
bdev = raw_devices[minor].binding;
err = -ENODEV;
if (bdev) {
- err = bd_claim(bdev, raw_open);
+ err = blkdev_get(bdev, filp->f_mode, 0, BDEV_RAW);
if (err)
goto out;
- err = -ENODEV;
- if (!igrab(bdev->bd_inode))
+ igrab(bdev->bd_inode);
+ err = bd_claim(bdev, raw_open);
+ if (err) {
+ blkdev_put(bdev, BDEV_RAW);
goto out;
- err = blkdev_get(bdev, filp->f_mode, 0, BDEV_RAW);
+ }
+ err = set_blocksize(bdev, bdev_hardsect_size(bdev));
if (err) {
bd_release(bdev);
+ blkdev_put(bdev, BDEV_RAW);
goto out;
- } else {
- err = set_blocksize(bdev, bdev_hardsect_size(bdev));
- if (err == 0) {
- filp->f_flags |= O_DIRECT;
- if (++raw_devices[minor].inuse == 1)
- filp->f_dentry->d_inode->i_mapping =
- bdev->bd_inode->i_mapping;
- }
}
+ filp->f_flags |= O_DIRECT;
+ if (++raw_devices[minor].inuse == 1)
+ filp->f_dentry->d_inode->i_mapping =
+ bdev->bd_inode->i_mapping;
}
filp->private_data = bdev;
out:
next reply other threads:[~2003-08-28 23:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-28 23:18 Dave Olien [this message]
2003-08-28 23:22 ` [PATCH] 2.6.0-test4-mm2 drivers/char.c ---> drivers/char/raw.c Dave Olien
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=20030828231853.GA7192@osdl.org \
--to=dmo@osdl.org \
--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