From owner-svn-src-all@freebsd.org Sun Jul 26 16:39:39 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 014C99AB38A; Sun, 26 Jul 2015 16:39:39 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CB202B89; Sun, 26 Jul 2015 16:39:38 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6QGdcZv028992; Sun, 26 Jul 2015 16:39:38 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6QGdcvW028991; Sun, 26 Jul 2015 16:39:38 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201507261639.t6QGdcvW028991@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Sun, 26 Jul 2015 16:39:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285892 - head/sys/dev/proto X-SVN-Group: head 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.20 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: Sun, 26 Jul 2015 16:39:39 -0000 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);