diff options
author | Marcel Moolenaar <marcel@FreeBSD.org> | 2015-07-26 16:39:37 +0000 |
---|---|---|
committer | Marcel Moolenaar <marcel@FreeBSD.org> | 2015-07-26 16:39:37 +0000 |
commit | b2ce196ca1af146f5aa010a519d79705c72137bb (patch) | |
tree | 42a3a1132539957da2a48964d0ac1869b41628c9 /sys/dev/proto | |
parent | dfded4478da01f9c5d139b4453537ad29a7dd911 (diff) | |
download | src-b2ce196ca1af146f5aa010a519d79705c72137bb.tar.gz src-b2ce196ca1af146f5aa010a519d79705c72137bb.zip |
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.
Notes
Notes:
svn path=/head/; revision=285892
Diffstat (limited to 'sys/dev/proto')
-rw-r--r-- | sys/dev/proto/proto_busdma.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/sys/dev/proto/proto_busdma.c b/sys/dev/proto/proto_busdma.c index 27fe45159d85..52f1146ffdd0 100644 --- a/sys/dev/proto/proto_busdma.c +++ b/sys/dev/proto/proto_busdma.c @@ -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_busdma *busdma, struct proto_tag *parent, { 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_busdma *busdma, struct proto_tag *parent, 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); |