From f0fba398fec65ff5a2e1bf8ae62718ec0450abaf Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 6 Nov 2017 17:53:53 +0000 Subject: block: avoid null pointer dereference on null disk It is possible that the pointer disk can be null and hence we can get a null pointer deference when accessing disk->flags. Add a null pointer check to avoid the dereference. Detected by CoverityScan, CID#1461133 ("Explicit null dereferenced") Fixes: 8ddcd653257c ("block: introduce GENHD_FL_HIDDEN") Reviewed-by: Christoph Hellwig Signed-off-by: Colin Ian King Signed-off-by: Jens Axboe --- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'block/genhd.c') diff --git a/block/genhd.c b/block/genhd.c index 3de1671631bf..997e598f3b86 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -798,7 +798,7 @@ struct gendisk *get_gendisk(dev_t devt, int *partno) spin_unlock_bh(&ext_devt_lock); } - if (unlikely(disk->flags & GENHD_FL_HIDDEN)) { + if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) { put_disk(disk); disk = NULL; } -- cgit v1.2.3-70-g09d2