From: Oleg Drokin <green@namesys.com>
To: mochel@osdl.org, linux-kernel@vger.kernel.org
Subject: Problem in using kobjects for block devices and partitions
Date: Sat, 23 Nov 2002 15:22:23 +0300 [thread overview]
Message-ID: <20021123152223.A17314@namesys.com> (raw)
Hello!
Problem code is in register_disk, and though it was included at the end of
November, but problems started to appear very recently.
At the beginning of register_disk() we see this snippet:
s = strchr(disk->kobj.name, '/');
if (s)
*s = '!';
kobject_register(&disk->kobj);
disk_sysfs_symlinks(disk);
And now kobject_register() frees disk structure if registration was
unsuccesful, so doing anything else with this structure is not very
nice thing. This is especially observable if you turn on SLAB poisoning,
then it will die during disk_sysfs_symlinks (actually two levels deeper).
I think here we should at least check return value of kobject_register
and print something useful. This won't help much against crashing since
accessing /proc/partition afterwards will still kill the box (in case
of SLAB poisoning, otherwise some other unpredictable stuff will happen).
It seems that making register_disk() to return error back to caller
does not makes much sence either, since struct gendisk is already destroyed
and we cannot get it off the lists that easily.
May be it was just a bad decision to destroy whole structure of underlying
object when kobject creation have failed?
Anyway at least below patch is a good thing to easy problem diagnostics
when kobject_register() fails during registering block devices (e.g. because
some of them have same base name).
Bye,
Oleg
===== fs/partitions/check.c 1.88 vs edited =====
--- 1.88/fs/partitions/check.c Thu Nov 21 06:08:39 2002
+++ edited/fs/partitions/check.c Sat Nov 23 15:17:28 2002
@@ -400,13 +400,23 @@
struct block_device *bdev;
char *s;
int j;
+ int error;
+ /* In case of error disk structure will be freed, so we cannot
+ dereference it. Let's save some useful info so that we can
+ print meaningful error message. */
+ int minor=disk->first_minor, major=disk->major;
strncpy(disk->kobj.name,disk->disk_name,KOBJ_NAME_LEN);
/* ewww... some of these buggers have / in name... */
s = strchr(disk->kobj.name, '/');
if (s)
*s = '!';
- kobject_register(&disk->kobj);
+
+ error = kobject_register(&disk->kobj);
+ if ( error ) {
+ printk(KERN_ERR "%s: Failed to create kernel object for disk major %d, first minor %d. Reason: %d\n", __FUNCTION__, major, minor, error );
+ return;
+ }
disk_sysfs_symlinks(disk);
if (disk->flags & GENHD_FL_CD)
next reply other threads:[~2002-11-23 12:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-23 12:22 Oleg Drokin [this message]
2002-11-25 22:27 ` Problem in using kobjects for block devices and partitions Patrick Mochel
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=20021123152223.A17314@namesys.com \
--to=green@namesys.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.