nvme-pci: fix NULL pointer dereference in nvme_free_host_mem()
authorMinwoo Im <minwoo.im.dev@gmail.com>
Fri, 24 Nov 2017 18:03:00 +0000 (03:03 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 3 Feb 2018 16:39:10 +0000 (17:39 +0100)
commit95a7d23415b79c94b4809200f29f458520e9fc56
tree0c598108804e882f01ee1a03d521f38f299c4cc2
parentf268e508aeb20f09de9a258ac5d2e41983567775
nvme-pci: fix NULL pointer dereference in nvme_free_host_mem()

[ Upstream commit 7e5dd57ef3081ff6c03908d786ed5087f6fbb7ae ]

Following condition which will cause NULL pointer dereference will
occur in nvme_free_host_mem() when it tries to remove pci device via
nvme_remove() especially after a failure of host memory allocation for HMB.

    "(host_mem_descs == NULL) && (nr_host_mem_descs != 0)"

It's because __nr_host_mem_descs__ is not cleared to 0 unlike
__host_mem_descs__ is so.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvme/host/pci.c