Fix various Coverity-detected errors in nvme driver

This fixes several Coverity-detected errors in the nvme driver.

CIDs addressed: 1008344, 1009377, 1009380, 1193740, 1305470, 1403975,
1403980

Reviewed by:	imp@, vangyzen@
MFC after:	5 days
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D24532
This commit is contained in:
David Bright 2020-05-02 20:47:58 +00:00
parent b43a935cae
commit 4053f8ac4d
7 changed files with 24 additions and 17 deletions

View File

@ -138,7 +138,8 @@ nvme_attach(device_t dev)
ctrlr->config_hook.ich_func = nvme_ctrlr_start_config_hook;
ctrlr->config_hook.ich_arg = ctrlr;
config_intrhook_establish(&ctrlr->config_hook);
if (config_intrhook_establish(&ctrlr->config_hook) != 0)
return (ENOMEM);
return (0);
}

View File

@ -1335,6 +1335,7 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag,
struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg;
strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev),
sizeof(gnsid->cdev));
gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0';
gnsid->nsid = 0;
break;
}
@ -1619,12 +1620,12 @@ nvme_ctrlr_resume(struct nvme_controller *ctrlr)
goto fail;
/*
* Now that we're reset the hardware, we can restart the controller. Any
* Now that we've reset the hardware, we can restart the controller. Any
* I/O that was pending is requeued. Any admin commands are aborted with
* an error. Once we've restarted, take the controller out of reset.
*/
nvme_ctrlr_start(ctrlr, true);
atomic_cmpset_32(&ctrlr->is_resetting, 1, 0);
(void)atomic_cmpset_32(&ctrlr->is_resetting, 1, 0);
return (0);
fail:
@ -1635,6 +1636,6 @@ nvme_ctrlr_resume(struct nvme_controller *ctrlr)
*/
nvme_printf(ctrlr, "Failed to reset on resume, failing.\n");
nvme_ctrlr_fail(ctrlr);
atomic_cmpset_32(&ctrlr->is_resetting, 1, 0);
(void)atomic_cmpset_32(&ctrlr->is_resetting, 1, 0);
return (0);
}

View File

@ -87,6 +87,7 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag,
struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg;
strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev),
sizeof(gnsid->cdev));
gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0';
gnsid->nsid = ns->id;
break;
}

View File

@ -243,11 +243,9 @@ nvme_ctrlr_configure_intx(struct nvme_controller *ctrlr)
return (ENOMEM);
}
bus_setup_intr(ctrlr->dev, ctrlr->res,
if (bus_setup_intr(ctrlr->dev, ctrlr->res,
INTR_TYPE_MISC | INTR_MPSAFE, NULL, nvme_ctrlr_intx_handler,
ctrlr, &ctrlr->tag);
if (ctrlr->tag == NULL) {
ctrlr, &ctrlr->tag) != 0) {
nvme_printf(ctrlr, "unable to setup intx handler\n");
return (ENOMEM);
}

View File

@ -671,9 +671,12 @@ nvme_qpair_construct(struct nvme_qpair *qpair,
qpair->res = bus_alloc_resource_any(ctrlr->dev, SYS_RES_IRQ,
&qpair->rid, RF_ACTIVE);
bus_setup_intr(ctrlr->dev, qpair->res,
if (bus_setup_intr(ctrlr->dev, qpair->res,
INTR_TYPE_MISC | INTR_MPSAFE, NULL,
nvme_qpair_msix_handler, qpair, &qpair->tag);
nvme_qpair_msix_handler, qpair, &qpair->tag) != 0) {
nvme_printf(ctrlr, "unable to setup intx handler\n");
goto out;
}
if (qpair->id == 0) {
bus_describe_intr(ctrlr->dev, qpair->res, qpair->tag,
"admin");

View File

@ -146,16 +146,17 @@ static int
nvme_sysctl_timeout_period(SYSCTL_HANDLER_ARGS)
{
struct nvme_controller *ctrlr = arg1;
uint32_t oldval = ctrlr->timeout_period;
int error = sysctl_handle_int(oidp, &ctrlr->timeout_period, 0, req);
uint32_t newval = ctrlr->timeout_period;
int error = sysctl_handle_int(oidp, &newval, 0, req);
if (error)
if (error || (req->newptr == NULL))
return (error);
if (ctrlr->timeout_period > NVME_MAX_TIMEOUT_PERIOD ||
ctrlr->timeout_period < NVME_MIN_TIMEOUT_PERIOD) {
ctrlr->timeout_period = oldval;
if (newval > NVME_MAX_TIMEOUT_PERIOD ||
newval < NVME_MIN_TIMEOUT_PERIOD) {
return (EINVAL);
} else {
ctrlr->timeout_period = newval;
}
return (0);

View File

@ -100,7 +100,7 @@ nvme_ns_bio_test(void *arg)
idx = atomic_fetchadd_int(&io_test->td_idx, 1);
dev = io_test->ns->cdev;
offset = idx * 2048 * nvme_ns_get_sector_size(io_test->ns);
offset = idx * 2048ULL * nvme_ns_get_sector_size(io_test->ns);
while (1) {
@ -120,6 +120,8 @@ nvme_ns_bio_test(void *arg)
} else
csw = dev->si_devsw;
if (csw == NULL)
panic("Unable to retrieve device switch");
mtx = mtx_pool_find(mtxpool_sleep, bio);
mtx_lock(mtx);
(*csw->d_strategy)(bio);