From owner-svn-src-all@freebsd.org Sat May 2 20:48:00 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 56A2E2C3A3B; Sat, 2 May 2020 20:48:00 +0000 (UTC) (envelope-from dab@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49F1R41gZVz4g43; Sat, 2 May 2020 20:48:00 +0000 (UTC) (envelope-from dab@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 34B1D2784D; Sat, 2 May 2020 20:48:00 +0000 (UTC) (envelope-from dab@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 042Km0Qp068823; Sat, 2 May 2020 20:48:00 GMT (envelope-from dab@FreeBSD.org) Received: (from dab@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 042Klwcr068812; Sat, 2 May 2020 20:47:58 GMT (envelope-from dab@FreeBSD.org) Message-Id: <202005022047.042Klwcr068812@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dab set sender to dab@FreeBSD.org using -f From: David Bright Date: Sat, 2 May 2020 20:47:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360568 - head/sys/dev/nvme X-SVN-Group: head X-SVN-Commit-Author: dab X-SVN-Commit-Paths: head/sys/dev/nvme X-SVN-Commit-Revision: 360568 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 May 2020 20:48:00 -0000 Author: dab Date: Sat May 2 20:47:58 2020 New Revision: 360568 URL: https://svnweb.freebsd.org/changeset/base/360568 Log: 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 Modified: head/sys/dev/nvme/nvme.c head/sys/dev/nvme/nvme_ctrlr.c head/sys/dev/nvme/nvme_ns.c head/sys/dev/nvme/nvme_pci.c head/sys/dev/nvme/nvme_qpair.c head/sys/dev/nvme/nvme_sysctl.c head/sys/dev/nvme/nvme_test.c Modified: head/sys/dev/nvme/nvme.c ============================================================================== --- head/sys/dev/nvme/nvme.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme.c Sat May 2 20:47:58 2020 (r360568) @@ -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); } Modified: head/sys/dev/nvme/nvme_ctrlr.c ============================================================================== --- head/sys/dev/nvme/nvme_ctrlr.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme_ctrlr.c Sat May 2 20:47:58 2020 (r360568) @@ -1335,6 +1335,7 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_ 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 @@ fail: */ 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); } Modified: head/sys/dev/nvme/nvme_ns.c ============================================================================== --- head/sys/dev/nvme/nvme_ns.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme_ns.c Sat May 2 20:47:58 2020 (r360568) @@ -87,6 +87,7 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t a 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; } Modified: head/sys/dev/nvme/nvme_pci.c ============================================================================== --- head/sys/dev/nvme/nvme_pci.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme_pci.c Sat May 2 20:47:58 2020 (r360568) @@ -243,11 +243,9 @@ nvme_ctrlr_configure_intx(struct nvme_controller *ctrl 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); } Modified: head/sys/dev/nvme/nvme_qpair.c ============================================================================== --- head/sys/dev/nvme/nvme_qpair.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme_qpair.c Sat May 2 20:47:58 2020 (r360568) @@ -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"); Modified: head/sys/dev/nvme/nvme_sysctl.c ============================================================================== --- head/sys/dev/nvme/nvme_sysctl.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme_sysctl.c Sat May 2 20:47:58 2020 (r360568) @@ -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); Modified: head/sys/dev/nvme/nvme_test.c ============================================================================== --- head/sys/dev/nvme/nvme_test.c Sat May 2 20:14:59 2020 (r360567) +++ head/sys/dev/nvme/nvme_test.c Sat May 2 20:47:58 2020 (r360568) @@ -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);