genhd: Fix leaked module reference for NVME devices
authorJan Kara <jack@suse.cz>
Mon, 26 Feb 2018 12:01:37 +0000 (13:01 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 26 Feb 2018 16:48:42 +0000 (09:48 -0700)
Commit 8ddcd653257c "block: introduce GENHD_FL_HIDDEN" added handling of
hidden devices to get_gendisk() but forgot to drop module reference
which is also acquired by get_disk(). Drop the reference as necessary.

Arguably the function naming here is misleading as put_disk() is *not*
the counterpart of get_disk() but let's fix that in the follow up
commit since that will be more intrusive.

Fixes: 8ddcd653257c18a669fcb75ee42c37054908e0d6
CC: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c

index 88a53c1..5098bff 100644 (file)
@@ -817,7 +817,10 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
        }
 
        if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) {
+               struct module *owner = disk->fops->owner;
+
                put_disk(disk);
+               module_put(owner);
                disk = NULL;
        }
        return disk;