Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jun 2012 16:06:27 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r237272 - head/sys/dev/pci
Message-ID:  <201206191606.q5JG6Ron060041@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Jun 19 16:06:27 2012
New Revision: 237272
URL: http://svn.freebsd.org/changeset/base/237272

Log:
  Add a 'wmask' variable to hold the expression '(1ul << w->step) - 1' in
  pcib_grow_window().  This makes the code slightly easier to read and
  prevents the type of bug fixed in r237271.
  
  MFC after:	3 days

Modified:
  head/sys/dev/pci/pci_pci.c

Modified: head/sys/dev/pci/pci_pci.c
==============================================================================
--- head/sys/dev/pci/pci_pci.c	Tue Jun 19 15:15:35 2012	(r237271)
+++ head/sys/dev/pci/pci_pci.c	Tue Jun 19 16:06:27 2012	(r237272)
@@ -815,7 +815,7 @@ static int
 pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
     u_long start, u_long end, u_long count, u_int flags)
 {
-	u_long align, start_free, end_free, front, back;
+	u_long align, start_free, end_free, front, back, wmask;
 	int error, rid;
 
 	/*
@@ -828,6 +828,7 @@ pcib_grow_window(struct pcib_softc *sc, 
 		end = w->rman.rm_end;
 	if (start + count - 1 > end || start + count < start)
 		return (EINVAL);
+	wmask = (1ul << w->step) - 1;
 
 	/*
 	 * If there is no resource at all, just try to allocate enough
@@ -838,8 +839,8 @@ pcib_grow_window(struct pcib_softc *sc, 
 			flags &= ~RF_ALIGNMENT_MASK;
 			flags |= RF_ALIGNMENT_LOG2(w->step);
 		}
-		start &= ~((1ul << w->step) - 1);
-		end |= ((1ul << w->step) - 1);
+		start &= ~wmask;
+		end |= wmask;
 		count = roundup2(count, 1ul << w->step);
 		rid = w->reg;
 		w->res = bus_alloc_resource(sc->dev, type, &rid, start, end,
@@ -913,7 +914,7 @@ pcib_grow_window(struct pcib_softc *sc, 
 			if (bootverbose)
 				printf("\tfront candidate range: %#lx-%#lx\n",
 				    front, end_free);
-			front &= ~((1ul << w->step) - 1);
+			front &= ~wmask;
 			front = rman_get_start(w->res) - front;
 		} else
 			front = 0;
@@ -941,7 +942,7 @@ pcib_grow_window(struct pcib_softc *sc, 
 			if (bootverbose)
 				printf("\tback candidate range: %#lx-%#lx\n",
 				    start_free, back);
-			back |= (1ul << w->step) - 1;
+			back |= wmask;
 			back -= rman_get_end(w->res);
 		} else
 			back = 0;
@@ -1000,10 +1001,8 @@ updatewin:
 	/* Save the new window. */
 	w->base = rman_get_start(w->res);
 	w->limit = rman_get_end(w->res);
-	KASSERT((w->base & ((1ul << w->step) - 1)) == 0,
-	    ("start address is not aligned"));
-	KASSERT((w->limit & ((1ul << w->step) - 1)) == (1ul << w->step) - 1,
-	    ("end address is not aligned"));
+	KASSERT((w->base & wmask) == 0, ("start address is not aligned"));
+	KASSERT((w->limit & wmask) == wmask, ("end address is not aligned"));
 	pcib_write_windows(sc, w->mask);
 	return (0);
 }



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