Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Jul 2015 16:39:38 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r285892 - head/sys/dev/proto
Message-ID:  <201507261639.t6QGdcvW028991@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sun Jul 26 16:39:37 2015
New Revision: 285892
URL: https://svnweb.freebsd.org/changeset/base/285892

Log:
  o   make sure the boundary is a power of 2, when not zero.
  o   don't convert 0 to ~0 just so that we can use MIN. ~0 is not a
      valid boundary. Introduce BNDRY_MIN that deals with 0 values
      that mean no boundary.

Modified:
  head/sys/dev/proto/proto_busdma.c

Modified: head/sys/dev/proto/proto_busdma.c
==============================================================================
--- head/sys/dev/proto/proto_busdma.c	Sun Jul 26 14:46:42 2015	(r285891)
+++ head/sys/dev/proto/proto_busdma.c	Sun Jul 26 16:39:37 2015	(r285892)
@@ -51,6 +51,9 @@ __FBSDID("$FreeBSD$");
 
 MALLOC_DEFINE(M_PROTO_BUSDMA, "proto_busdma", "DMA management data");
 
+#define	BNDRY_MIN(a, b)		\
+	(((a) == 0) ? (b) : (((b) == 0) ? (a) : MIN((a), (b))))
+
 struct proto_callback_bundle {
 	struct proto_busdma *busdma;
 	struct proto_md *md;
@@ -63,6 +66,11 @@ proto_busdma_tag_create(struct proto_bus
 {
 	struct proto_tag *tag;
 
+	/* Make sure that when a boundary is specified, it's a power of 2 */
+	if (ioc->u.tag.bndry != 0 &&
+	    (ioc->u.tag.bndry & (ioc->u.tag.bndry - 1)) != 0)
+		return (EINVAL);
+
 	/*
 	 * If nsegs is 1, ignore maxsegsz. What this means is that if we have
 	 * just 1 segment, then maxsz should be equal to maxsegsz. To keep it
@@ -71,16 +79,12 @@ proto_busdma_tag_create(struct proto_bus
 	if (ioc->u.tag.maxsegsz > ioc->u.tag.maxsz || ioc->u.tag.nsegs == 1)
 		ioc->u.tag.maxsegsz = ioc->u.tag.maxsz;
 
-	/* A bndry of 0 really means ~0, or no boundary. */
-	if (ioc->u.tag.bndry == 0)
-		ioc->u.tag.bndry = ~0U;
-
 	tag = malloc(sizeof(*tag), M_PROTO_BUSDMA, M_WAITOK | M_ZERO);
 	if (parent != NULL) {
 		tag->parent = parent;
 		LIST_INSERT_HEAD(&parent->children, tag, peers);
 		tag->align = MAX(ioc->u.tag.align, parent->align);
-		tag->bndry = MIN(ioc->u.tag.bndry, parent->bndry);
+		tag->bndry = BNDRY_MIN(ioc->u.tag.bndry, parent->bndry);
 		tag->maxaddr = MIN(ioc->u.tag.maxaddr, parent->maxaddr);
 		tag->maxsz = MIN(ioc->u.tag.maxsz, parent->maxsz);
 		tag->maxsegsz = MIN(ioc->u.tag.maxsegsz, parent->maxsegsz);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507261639.t6QGdcvW028991>