svn commit: r354054 - head/sys/cam/nvme

Brooks Davis brooks at FreeBSD.org
Thu Oct 24 22:23:54 UTC 2019


Author: brooks
Date: Thu Oct 24 22:23:53 2019
New Revision: 354054
URL: https://svnweb.freebsd.org/changeset/base/354054

Log:
  nda(4): Remove unnecessary union and avoid Clang -Wsizeof-array-divwarning
  
  Clang trunk recently gained this new warning, and complains about the
  sizeof(trim->data) / sizeof(struct nvme_dsm_range) expression, since
  the left hand side's element type (char) does not match the right hand
  side's type. The byte buffer is unnecessary so we can remove it to clean
  up the code and fix the warning at the same time.
  
  No functional change.
  
  Submitted by:	James Clarke <jrtc27 at jrtc27.com>
  Reviewed by:	imp
  Sponsored by:	DARPA, AFRL
  Differential Revision:	https://reviews.freebsd.org/D21912

Modified:
  head/sys/cam/nvme/nvme_da.c

Modified: head/sys/cam/nvme/nvme_da.c
==============================================================================
--- head/sys/cam/nvme/nvme_da.c	Thu Oct 24 22:07:45 2019	(r354053)
+++ head/sys/cam/nvme/nvme_da.c	Thu Oct 24 22:23:53 2019	(r354054)
@@ -129,12 +129,11 @@ struct nda_softc {
 };
 
 struct nda_trim_request {
-	union {
-		struct nvme_dsm_range dsm;
-		uint8_t		data[NVME_MAX_DSM_TRIM];
-	};
+	struct nvme_dsm_range	dsm[NVME_MAX_DSM_TRIM / sizeof(struct nvme_dsm_range)];
 	TAILQ_HEAD(, bio) bps;
 };
+_Static_assert(NVME_MAX_DSM_TRIM % sizeof(struct nvme_dsm_range) == 0,
+    "NVME_MAX_DSM_TRIM must be an integral number of ranges");
 
 /* Need quirk table */
 
@@ -957,9 +956,8 @@ ndastart(struct cam_periph *periph, union ccb *start_c
 			}
 			TAILQ_INIT(&trim->bps);
 			bp1 = bp;
-			ents = sizeof(trim->data) / sizeof(struct nvme_dsm_range);
-			ents = min(ents, nda_max_trim_entries);
-			dsm_range = &trim->dsm;
+			ents = min(nitems(trim->dsm), nda_max_trim_entries);
+			dsm_range = trim->dsm;
 			dsm_end = dsm_range + ents;
 			do {
 				TAILQ_INSERT_TAIL(&trim->bps, bp1, bio_queue);
@@ -977,8 +975,8 @@ ndastart(struct cam_periph *periph, union ccb *start_c
 				/* XXX -- Could limit based on total payload size */
 			} while (bp1 != NULL);
 			start_ccb->ccb_trim = trim;
-			nda_nvme_trim(softc, &start_ccb->nvmeio, &trim->dsm,
-			    dsm_range - &trim->dsm);
+			nda_nvme_trim(softc, &start_ccb->nvmeio, trim->dsm,
+			    dsm_range - trim->dsm);
 			start_ccb->ccb_state = NDA_CCB_TRIM;
 			softc->trim_count++;
 			softc->trim_ranges += ranges;


More information about the svn-src-all mailing list