From: Dan Williams Date: Thu, 27 Apr 2017 21:46:26 +0000 (-0700) Subject: block: hide badblocks attribute by default X-Git-Tag: MMI-PSA29.97-13-9~5704^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9438b3e080beccf6022138ea62192d55cc7dc4ed;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git block: hide badblocks attribute by default Commit 99e6608c9e74 "block: Add badblock management for gendisks" allowed for drivers like pmem and software-raid to advertise a list of bad media areas. However, it inadvertently added a 'badblocks' to all block devices. Lets clean this up by having the 'badblocks' attribute not be visible when the driver has not populated a 'struct badblocks' instance in the gendisk. Cc: Jens Axboe Cc: Christoph Hellwig Cc: Martin K. Petersen Reported-by: Vishal Verma Signed-off-by: Dan Williams Tested-by: Vishal Verma Signed-off-by: Jens Axboe --- diff --git a/block/genhd.c b/block/genhd.c index 510aac1486cb..9a2d01abfa3b 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1060,8 +1060,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[] = {