diff options
author | Nitzan Carmi <nitzanc@mellanox.com> | 2018-01-04 17:56:13 +0200 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-01-08 16:56:57 +0100 |
commit | 85088c4a0f65f0be25a98164ec6bca02ac5cad04 (patch) | |
tree | ffe8e6a1d08ce51fc1d3f1197e3fecf5c13a91e7 | |
parent | 2b1b7e784a63f5ded4dda804e05e3f34b3880b25 (diff) | |
download | linux-stable-85088c4a0f65f0be25a98164ec6bca02ac5cad04.tar.gz linux-stable-85088c4a0f65f0be25a98164ec6bca02ac5cad04.tar.bz2 linux-stable-85088c4a0f65f0be25a98164ec6bca02ac5cad04.zip |
nvme: take refcount on transport module
The block device is backed by the transport so we must ensure that the
transport driver will not be removed until all references are released.
Otherwise, we might end up referencing freed memory.
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Nitzan Carmi <nitzanc@mellanox.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | drivers/nvme/host/core.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 609307ca9e4d..c8bcfe64e976 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1228,16 +1228,27 @@ static int nvme_open(struct block_device *bdev, fmode_t mode) #ifdef CONFIG_NVME_MULTIPATH /* should never be called due to GENHD_FL_HIDDEN */ if (WARN_ON_ONCE(ns->head->disk)) - return -ENXIO; + goto fail; #endif if (!kref_get_unless_zero(&ns->kref)) - return -ENXIO; + goto fail; + if (!try_module_get(ns->ctrl->ops->module)) + goto fail_put_ns; + return 0; + +fail_put_ns: + nvme_put_ns(ns); +fail: + return -ENXIO; } static void nvme_release(struct gendisk *disk, fmode_t mode) { - nvme_put_ns(disk->private_data); + struct nvme_ns *ns = disk->private_data; + + module_put(ns->ctrl->ops->module); + nvme_put_ns(ns); } static int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo) |