From f4a00a2c06bc7802f52969cbdd19f4c680a7cd20 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 6 Feb 2008 23:33:39 -0800 Subject: Block: Fix whole_disk attribute bug The "whole_disk" attribute was not properly converted in the block device conversion earlier, and if the file is read, bad things can happen. This patch fixes this, making the attribute an empty one, preserving the original functionality. Many thanks to David Miller for finding this, and pointing me in the proper place within the block code to look. Acked-by: David S. Miller Cc: Kay Sievers Signed-off-by: Greg Kroah-Hartman --- fs/partitions/check.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'fs') diff --git a/fs/partitions/check.c b/fs/partitions/check.c index 739da701ae7..9a64045ff84 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c @@ -319,6 +319,14 @@ void delete_partition(struct gendisk *disk, int part) put_device(&p->dev); } +static ssize_t whole_disk_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return 0; +} +static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, + whole_disk_show, NULL); + void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags) { struct hd_struct *p; @@ -352,13 +360,8 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, device_add(&p->dev); partition_sysfs_add_subdir(p); p->dev.uevent_suppress = 0; - if (flags & ADDPART_FLAG_WHOLEDISK) { - static struct attribute addpartattr = { - .name = "whole_disk", - .mode = S_IRUSR | S_IRGRP | S_IROTH, - }; - err = sysfs_create_file(&p->dev.kobj, &addpartattr); - } + if (flags & ADDPART_FLAG_WHOLEDISK) + err = device_create_file(&p->dev, &dev_attr_whole_disk); /* suppress uevent if the disk supresses it */ if (!disk->dev.uevent_suppress) -- cgit v1.2.3 From 969affd276dec81a35a5ad10d4e05e62e93b380b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 7 Feb 2008 11:58:54 -0500 Subject: sysfs: remove BUG_ON() from sysfs_remove_group() It's possible that the caller of sysfs_remove_group messed up and passed in an attribute group that was not really registered to this kobject. But don't panic for such a foolish error, spit out a warning about what happened, and continue on our way safely. Cc: Roland Dreier Cc: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 0871c3dadce..47790491503 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -77,7 +77,12 @@ void sysfs_remove_group(struct kobject * kobj, if (grp->name) { sd = sysfs_get_dirent(dir_sd, grp->name); - BUG_ON(!sd); + if (!sd) { + printk(KERN_WARNING "sysfs group %p not found for " + "kobject '%s'\n", grp, kobject_name(kobj)); + WARN_ON(!sd); + return; + } } else sd = sysfs_get(dir_sd); -- cgit v1.2.3