[PATCH 2/5] block: protect bdevname from null pointer bdev
From: Dmitry Monakhov
Date: Thu Apr 06 2017 - 08:03:59 EST
Some callers (usually error paths) call bdevname with null bdev.
Signed-off-by: Dmitry Monakhov <dmonakhov@xxxxxxxxxx>
---
block/partition-generic.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 7afb990..284de18 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -46,6 +46,8 @@ char *disk_name(struct gendisk *hd, int partno, char *buf)
const char *bdevname(struct block_device *bdev, char *buf)
{
+ if (unlikely(!bdev))
+ return snprintf(buf, BDEVNAME_SIZE, "unknown-block(null)");
return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
}
--
2.9.3