nvme: require trid to be valid in nvme_ctrlr_probe

This is an internal NVMe driver function, so we don't need to allow for
the case where trid is NULL.  All callers already passed an address of a
local variable except the unit tests, which can be trivially fixed.

Fixes a static analyzer warning about trid being dereferenced in
nvme_transport_ctrlr_construct() before being checked for NULL in the
caller.

Change-Id: I2bfeb5c92a302093b7c7f2949adcd18baa11855a
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/408395
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2018-04-19 13:22:55 -07:00
parent 0692768e69
commit 3fa7c33ac1
2 changed files with 7 additions and 9 deletions

View File

@ -342,16 +342,14 @@ nvme_ctrlr_probe(const struct spdk_nvme_transport_id *trid, void *devhandle,
struct spdk_nvme_ctrlr *ctrlr;
struct spdk_nvme_ctrlr_opts opts;
assert(trid != NULL);
spdk_nvme_ctrlr_get_default_ctrlr_opts(&opts, sizeof(opts));
if (!probe_cb || probe_cb(cb_ctx, trid, &opts)) {
ctrlr = nvme_transport_ctrlr_construct(trid, &opts, devhandle);
if (ctrlr == NULL) {
if (trid != NULL) {
SPDK_ERRLOG("Failed to construct NVMe controller for SSD: %s\n", trid->traddr);
} else {
SPDK_ERRLOG("Failed to construct NVMe controller\n");
}
SPDK_ERRLOG("Failed to construct NVMe controller for SSD: %s\n", trid->traddr);
return -1;
}

View File

@ -730,21 +730,21 @@ static void
test_nvme_ctrlr_probe(void)
{
int rc = 0;
const struct spdk_nvme_transport_id *trid = NULL;
const struct spdk_nvme_transport_id trid = {};
void *devhandle = NULL;
void *cb_ctx = NULL;
struct spdk_nvme_ctrlr *dummy = NULL;
/* test when probe_cb returns false */
MOCK_SET(dummy_probe_cb, bool, false);
rc = nvme_ctrlr_probe(trid, devhandle, dummy_probe_cb, cb_ctx);
rc = nvme_ctrlr_probe(&trid, devhandle, dummy_probe_cb, cb_ctx);
CU_ASSERT(rc == 1);
/* probe_cb returns true but we can't construct a ctrl */
MOCK_SET(dummy_probe_cb, bool, true);
MOCK_SET_P(nvme_transport_ctrlr_construct,
struct spdk_nvme_ctrlr *, NULL);
rc = nvme_ctrlr_probe(trid, devhandle, dummy_probe_cb, cb_ctx);
rc = nvme_ctrlr_probe(&trid, devhandle, dummy_probe_cb, cb_ctx);
CU_ASSERT(rc == -1);
/* happy path */
@ -754,7 +754,7 @@ test_nvme_ctrlr_probe(void)
MOCK_SET_P(nvme_transport_ctrlr_construct,
struct spdk_nvme_ctrlr *, &ut_nvme_transport_ctrlr_construct);
TAILQ_INIT(&g_nvme_init_ctrlrs);
rc = nvme_ctrlr_probe(trid, devhandle, dummy_probe_cb, cb_ctx);
rc = nvme_ctrlr_probe(&trid, devhandle, dummy_probe_cb, cb_ctx);
CU_ASSERT(rc == 0);
dummy = TAILQ_FIRST(&g_nvme_init_ctrlrs);
CU_ASSERT(dummy == &ut_nvme_transport_ctrlr_construct);