summaryrefslogtreecommitdiff
path: root/block/genhd.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/block/genhd.c b/block/genhd.c
index a9c516a8b37d..d252d29fe837 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -271,16 +271,17 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
/**
* register_blkdev - register a new block device
*
- * @major: the requested major device number [1..255]. If @major=0, try to
+ * @major: the requested major device number [1..255]. If @major = 0, try to
* allocate any unused major number.
* @name: the name of the new block device as a zero terminated string
*
* The @name must be unique within the system.
*
- * The return value depends on the @major input parameter.
+ * The return value depends on the @major input parameter:
+ *
* - if a major device number was requested in range [1..255] then the
* function returns zero on success, or a negative error code
- * - if any unused major number was requested with @major=0 parameter
+ * - if any unused major number was requested with @major = 0 parameter
* then the return value is the allocated major number in range
* [1..255] or a negative error code otherwise
*/
@@ -1060,8 +1061,19 @@ static struct attribute *disk_attrs[] = {
NULL
};
+static umode_t disk_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+ struct device *dev = container_of(kobj, typeof(*dev), kobj);
+ struct gendisk *disk = dev_to_disk(dev);
+
+ if (a == &dev_attr_badblocks.attr && !disk->bb)
+ return 0;
+ return a->mode;
+}
+
static struct attribute_group disk_attr_group = {
.attrs = disk_attrs,
+ .is_visible = disk_visible,
};
static const struct attribute_group *disk_attr_groups[] = {
@@ -1352,7 +1364,7 @@ struct kobject *get_disk(struct gendisk *disk)
owner = disk->fops->owner;
if (owner && !try_module_get(owner))
return NULL;
- kobj = kobject_get(&disk_to_dev(disk)->kobj);
+ kobj = kobject_get_unless_zero(&disk_to_dev(disk)->kobj);
if (kobj == NULL) {
module_put(owner);
return NULL;