git: 2361a0056fc1 - main - mpi3mr: Replace can't happen DataLength == 0 with an assert

From: Warner Losh <imp_at_FreeBSD.org>
Date: Wed, 29 Nov 2023 01:55:45 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=2361a0056fc16b5e11df2aa948aaa633ac01d685

commit 2361a0056fc16b5e11df2aa948aaa633ac01d685
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-11-29 01:50:47 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-11-29 01:52:28 +0000

    mpi3mr: Replace can't happen DataLength == 0 with an assert
    
    Replace the test for DataLength == 0 with an assert. It can't happen,
    but an assert doesn't hurt. Emacs removed some trailing white space too.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D42807
---
 sys/dev/mpi3mr/mpi3mr_cam.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/sys/dev/mpi3mr/mpi3mr_cam.c b/sys/dev/mpi3mr/mpi3mr_cam.c
index 0b882b3a641e..3cef46f3f642 100644
--- a/sys/dev/mpi3mr/mpi3mr_cam.c
+++ b/sys/dev/mpi3mr/mpi3mr_cam.c
@@ -98,7 +98,6 @@ extern int
 mpi3mr_register_events(struct mpi3mr_softc *sc);
 extern void mpi3mr_add_sg_single(void *paddr, U8 flags, U32 length,
     bus_addr_t dma_addr);
-extern void mpi3mr_build_zero_len_sge(void *paddr);
 
 static U32 event_count;
 
@@ -147,6 +146,9 @@ static void mpi3mr_prepare_sgls(void *arg,
 
 	KASSERT(nsegs <= MPI3MR_SG_DEPTH && nsegs > 0,
 	    ("%s: bad SGE count: %d\n", device_get_nameunit(sc->mpi3mr_dev), nsegs));
+	KASSERT(scsiio_req->DataLength != 0,
+	    ("%s: Data segments (%d), but DataLength == 0\n",
+		device_get_nameunit(sc->mpi3mr_dev), nsegs));
 
 	simple_sgl_flags = MPI3_SGE_FLAGS_ELEMENT_TYPE_SIMPLE |
 	    MPI3_SGE_FLAGS_DLAS_SYSTEM;
@@ -157,13 +159,6 @@ static void mpi3mr_prepare_sgls(void *arg,
 
 	sg_local = (U8 *)&scsiio_req->SGL;
 
-	if (scsiio_req->DataLength == 0) {
-		/* XXX we don't ever get here when DataLength == 0, right? cm->data is NULL */
-		/* This whole if can likely be removed -- we handle it in mpi3mr_request_map */
-		mpi3mr_build_zero_len_sge(sg_local);
-		goto enqueue;
-	}
-	
 	sges_left = nsegs;
 
 	sges_in_segment = (sc->facts.op_req_sz -
@@ -214,7 +209,6 @@ fill_in_last_segment:
 		i++;
 	}
 
-enqueue:
 	/*
 	 * Now that we've created the sgls, we send the request to the device.
 	 * Unlike in Linux, dmaload isn't guaranteed to load every time, but
@@ -879,10 +873,10 @@ mpi3mr_scsiio_timeout(void *data)
 		return;
 
 	/*
-	 * task abort and target reset has failed. So issue Controller reset(soft reset) 
+	 * task abort and target reset has failed. So issue Controller reset(soft reset)
 	 * through OCR thread context
 	 */
-	trigger_reset_from_watchdog(sc, MPI3MR_TRIGGER_SOFT_RESET, MPI3MR_RESET_FROM_SCSIIO_TIMEOUT); 
+	trigger_reset_from_watchdog(sc, MPI3MR_TRIGGER_SOFT_RESET, MPI3MR_RESET_FROM_SCSIIO_TIMEOUT);
 
 	return;
 }
@@ -976,7 +970,7 @@ mpi3mr_action_scsiio(struct mpi3mr_cam_softc *cam_sc, union ccb *ccb)
 	}
 
 	if (targ->dev_handle == 0x0) {
-		mpi3mr_dprint(sc, MPI3MR_ERROR, "%s NULL handle for target 0x%x\n", 
+		mpi3mr_dprint(sc, MPI3MR_ERROR, "%s NULL handle for target 0x%x\n",
 		    __func__, csio->ccb_h.target_id);
 		mpi3mr_set_ccbstatus(ccb, CAM_DEV_NOT_THERE);
 		xpt_done(ccb);