vhost/nvme: Check for NULL nvme on public functions

Due to the check on line 153 in t_nvme_dev, Klocwork
thinks nvme can be null. Therefore, we must check that
it isn't null before dereferencing it. We can either
solve this the way I have here, or remove check
that causes to_nvme_dev to return null.

Change-Id: I86d4939664704ff1117a7c1b7dada7e1ae479c6f
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/406992
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
This commit is contained in:
Ben Walker 2018-04-09 10:38:49 -07:00 committed by Daniel Verkamp
parent 7da3afd1f7
commit 96fcdf93e7

View File

@ -150,10 +150,6 @@ static const struct spdk_vhost_dev_backend spdk_vhost_nvme_device_backend;
static struct spdk_vhost_nvme_dev *
to_nvme_dev(struct spdk_vhost_dev *vdev)
{
if (vdev == NULL) {
return NULL;
}
if (vdev->backend != &spdk_vhost_nvme_device_backend) {
SPDK_ERRLOG("%s: not a vhost-nvme device\n", vdev->name);
return NULL;
@ -886,6 +882,10 @@ spdk_vhost_nvme_start_device(struct spdk_vhost_dev *vdev, void *event_ctx)
struct spdk_vhost_nvme_ns *ns_dev;
uint32_t i;
if (nvme == NULL) {
return -1;
}
spdk_vhost_dev_mem_register(vdev);
nvme->mem = vdev->mem;
@ -980,6 +980,10 @@ spdk_vhost_nvme_stop_device(struct spdk_vhost_dev *vdev, void *event_ctx)
struct spdk_vhost_nvme_dev *nvme = to_nvme_dev(vdev);
struct spdk_vhost_dev_destroy_ctx *destroy_ctx;
if (nvme == NULL) {
return -1;
}
free_task_pool(nvme);
SPDK_NOTICELOG("Stopping Device %u, Path %s\n", vdev->vid, vdev->path);
@ -1010,6 +1014,10 @@ spdk_vhost_nvme_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_w
struct spdk_bdev *bdev;
uint32_t i;
if (nvme == NULL) {
return;
}
spdk_json_write_name(w, "namespaces");
spdk_json_write_object_begin(w);
@ -1199,6 +1207,10 @@ spdk_vhost_nvme_dev_add_ns(struct spdk_vhost_dev *vdev, const char *bdev_name)
struct spdk_bdev *bdev;
int rc = -1;
if (nvme == NULL) {
return -1;
}
if (nvme->num_ns == MAX_NAMESPACE) {
SPDK_ERRLOG("Can't support %d Namespaces\n", nvme->num_ns);
return -1;