[patch] avoid bypassing sys/queue.h

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[patch] avoid bypassing sys/queue.h

Pierre-Yves Ritschard-2
Since I spotted a small manual TAILQ operation in rcs.h,
I decided to grep the source tree for other such cases.
Here's what I found and associated diffs.

For each file(s) modified I noted whether or not I was able
to confirm no binary change were made.

. Modified files:

M usr.bin/vi/common/api.c
M usr.bin/vi/common/line.c
M usr.bin/vi/common/main.c
M usr.bin/vi/common/put.c
M usr.bin/vi/ex/ex_global.c
M usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c
M usr.sbin/ypserv/ypserv/ypserv_db.c
M sys/adosfs/adutil.c
M sys/arch/hppa64/hppa64/autoconf.c
M sys/arch/macppc/stand/alloc.c
M sys/arch/mvme68k/dev/sbic.c
M sys/arch/mvme68k/dev/ssh.c
M sys/arch/sparc64/dev/fd.c
M sys/arch/sparc64/stand/ofwboot/alloc.c
M sys/arch/zaurus/zaurus/autoconf.c
M sys/dev/microcode/aic7xxx/aicasm_gram.y
M sys/dev/microcode/aic7xxx/aicasm_scan.l
M sys/netinet6/nd6.c
M sys/netinet6/nd6.h
M sys/netinet6/nd6_rtr.c
M sys/ufs/lfs/lfs_segment.c
M sys/xfs/xfs_node-bsd.c

. Some notes:

There's still weird stuff going on in sys/netatalk/ and a lot of
calls such as this one:

        if (dp->tqh_last == &TAILQ_NEXT(bp, b_freelist))

There's a nice explanation in  sys/kern/vfs_bio.c

        /*
         * We only calculate the head of the freelist when removing
         * the last element of the list as that is the only time that
         * it is needed (e.g. to reset the tail pointer).
         *
         * NB: This makes an assumption about how tailq's are implemented.
         */

Maybe the number of tests like the one above warrant something in
sys/queue.h but I'd like input on that.

. File specific notes:

src/usr.bin/vi/common/{api.c,put.c,main.c,line.c}:
src/usr.bin/vi/ex/ex_global.c:
        lots of CIRCLEQ operations were done manually.
        use CIRCLEQ_FOREACH, LIST_FIRST and LIST_FOREACH instead
        of manual versions.  md5 confirms no binary change.

src/usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c:
        remove unused LIST_FOREACH definition
        (sys/queue.h is #included anywhow)
        no binary change.

src/usr.sbin/ypserv/ypserv/ypserv_db.c:
        use CIRCLEQ_LAST instead of manually fetching cqh_last;
        md5 confirms no binary change.

src/sys/adosfs/adutil.c:
        switch to LIST_FOREACH. can't confirm.

src/sys/arch/hppa64/hppa64/autoconf.c:
        switch to TAILQ_FOREACH. can't confirm.

src/sys/arch/macppc/stand/alloc.c:
        switch to LIST_FOREACH, LIST_FIRST. can't confirm.

sys/arch/mvme68k/dev/{sbic.c,ssh.c}:
        minor TAILQ operations.
        side note, these files have weird 4 space based indenting.
        can't confirm.

sys/arch/sparc64/dev/fd.c:
sys/arch/sparc64/stand/ofwboot/alloc.c:
        small evolutions to LIST and TAILQ.  can't confirm.

sys/netinet6/{nd6.h,nd6.c,nd6_rtr.c}:
        many manual operations, this is not a no binary change diff
        since i changed a list cleanup loop.
        (switched to the "while head: remove_first;" method).

sys/xfs/xfs_node-bsd.c:
        unused LIST_FOREACH definition.
        same than the one in nnpfs_node-bsd.c
        no binary change.
Index: usr.bin/vi/common/api.c
===================================================================
RCS file: /space/release/cvs/src/usr.bin/vi/common/api.c,v
retrieving revision 1.12
diff -u -r1.12 api.c
--- usr.bin/vi/common/api.c 15 Apr 2003 08:08:02 -0000 1.12
+++ usr.bin/vi/common/api.c 23 Mar 2006 22:20:31 -0000
@@ -51,8 +51,7 @@
  gp = __global_list;
 
  /* Search the displayed list. */
- for (tsp = gp->dq.cqh_first;
-    tsp != (void *)&gp->dq; tsp = tsp->q.cqe_next)
+ CIRCLEQ_FOREACH(tsp, &gp->dq, q)
  if (name == NULL) {
  if (id == tsp->id)
  return (tsp);
@@ -60,8 +59,7 @@
  return (tsp);
 
  /* Search the hidden list. */
- for (tsp = gp->hq.cqh_first;
-    tsp != (void *)&gp->hq; tsp = tsp->q.cqe_next)
+ CIRCLEQ_FOREACH(tsp, &gp->hq, q)
  if (name == NULL) {
  if (id == tsp->id)
  return (tsp);
@@ -214,11 +212,11 @@
 {
  LMARK *mp;
 
- mp = sp->ep->marks.lh_first;
+ mp = LIST_FIRST(&sp->ep->marks);
  if (next)
- for (; mp != NULL; mp = mp->q.le_next)
+ LIST_FOREACH(mp, &sp->ep->marks, q)
  if (mp->name == *namep) {
- mp = mp->q.le_next;
+ mp = LIST_NEXT(mp, q);
  break;
  }
  if (mp == NULL)
Index: usr.bin/vi/common/line.c
===================================================================
RCS file: /space/release/cvs/src/usr.bin/vi/common/line.c,v
retrieving revision 1.7
diff -u -r1.7 line.c
--- usr.bin/vi/common/line.c 8 Jan 2006 21:05:39 -0000 1.7
+++ usr.bin/vi/common/line.c 23 Mar 2006 22:20:31 -0000
@@ -466,7 +466,7 @@
  */
  if (ep->c_nlines != OOBLNO)
  return (lno <= (F_ISSET(sp, SC_TINPUT) ?
-    ep->c_nlines + (((TEXT *)sp->tiq.cqh_last)->lno -
+    ep->c_nlines + (((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno -
     ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno) : ep->c_nlines));
 
  /* Go get the line. */
@@ -501,7 +501,7 @@
  if (ep->c_nlines != OOBLNO) {
  *lnop = ep->c_nlines;
  if (F_ISSET(sp, SC_TINPUT))
- *lnop += ((TEXT *)sp->tiq.cqh_last)->lno -
+ *lnop += ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno -
     ((TEXT *)CIRCLEQ_FIRST(&sp->tiq))->lno;
  return (0);
  }
@@ -529,8 +529,8 @@
 
  /* Return the value. */
  *lnop = (F_ISSET(sp, SC_TINPUT) &&
-    ((TEXT *)sp->tiq.cqh_last)->lno > lno ?
-    ((TEXT *)sp->tiq.cqh_last)->lno : lno);
+    ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno > lno ?
+    ((TEXT *)CIRCLEQ_LAST(&sp->tiq))->lno : lno);
  return (0);
 }
 
Index: usr.bin/vi/common/main.c
===================================================================
RCS file: /space/release/cvs/src/usr.bin/vi/common/main.c,v
retrieving revision 1.12
diff -u -r1.12 main.c
--- usr.bin/vi/common/main.c 8 Jan 2006 21:05:39 -0000 1.12
+++ usr.bin/vi/common/main.c 23 Mar 2006 22:20:31 -0000
@@ -464,7 +464,7 @@
 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
  { FREF *frp;
  /* Free FREF's. */
- while ((frp = gp->frefq.cqh_first) != (FREF *)&gp->frefq) {
+ while ((frp = CIRCLEQ_FIRST(&gp)) != CIRCLEQ_END(&gp->frefq)) {
  CIRCLEQ_REMOVE(&gp->frefq, frp, q);
  if (frp->name != NULL)
  free(frp->name);
Index: usr.bin/vi/common/put.c
===================================================================
RCS file: /space/release/cvs/src/usr.bin/vi/common/put.c,v
retrieving revision 1.8
diff -u -r1.8 put.c
--- usr.bin/vi/common/put.c 8 Jan 2006 21:05:39 -0000 1.8
+++ usr.bin/vi/common/put.c 23 Mar 2006 22:20:31 -0000
@@ -187,7 +187,7 @@
  * Last part of original line; check for space, reset
  * the pointer into the buffer.
  */
- ltp = cbp->textq.cqh_last;
+ ltp = CIRCLEQ_LAST(&cbp->textq);
  len = t - bp;
  ADD_SPACE_RET(sp, bp, blen, ltp->len + clen);
  t = bp + len;
Index: usr.bin/vi/ex/ex_global.c
===================================================================
RCS file: /space/release/cvs/src/usr.bin/vi/ex/ex_global.c,v
retrieving revision 1.8
diff -u -r1.8 ex_global.c
--- usr.bin/vi/ex/ex_global.c 8 Jan 2006 21:05:40 -0000 1.8
+++ usr.bin/vi/ex/ex_global.c 23 Mar 2006 22:20:31 -0000
@@ -236,7 +236,7 @@
  }
 
  /* If follows the last entry, extend the last entry's range. */
- if ((rp = ecp->rq.cqh_last) != (void *)&ecp->rq &&
+ if ((rp = CIRCLEQ_LAST(&ecp->rq)) != CIRCLEQ_END(&ecp->rq) &&
     rp->stop == start - 1) {
  ++rp->stop;
  continue;
Index: usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 nnpfs_node-bsd.c
--- usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c 5 Aug 2003 08:21:02 -0000 1.1.1.1
+++ usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c 24 Mar 2006 00:11:46 -0000
@@ -276,13 +276,6 @@
     return error;
 }
 
-#ifndef LIST_FOREACH
-#define LIST_FOREACH(var, head, field) \
- for ((var) = ((head)->lh_first); \
- (var); \
- (var) = ((var)->field.le_next))
-#endif
-
 void
 vattr2nnpfs_attr(const struct vattr *va, struct nnpfs_attr *xa)
 {
Index: usr.sbin/ypserv/ypserv/ypserv_db.c
===================================================================
RCS file: /space/release/cvs/src/usr.sbin/ypserv/ypserv/ypserv_db.c,v
retrieving revision 1.22
diff -u -r1.22 ypserv_db.c
--- usr.sbin/ypserv/ypserv/ypserv_db.c 21 Dec 2005 01:40:25 -0000 1.22
+++ usr.sbin/ypserv/ypserv/ypserv_db.c 24 Mar 2006 00:07:28 -0000
@@ -147,7 +147,7 @@
 static void
 ypdb_close_last(void)
 {
- struct opt_map *last = maps.cqh_last;
+ struct opt_map *last = CIRCLEQ_LAST(&maps);
 
  if (last == (void *)&maps) {
  yplog("  ypdb_close_last: LRU list is empty!");
Index: sys/adosfs/adutil.c
===================================================================
RCS file: /space/release/cvs/src/sys/adosfs/adutil.c,v
retrieving revision 1.15
diff -u -r1.15 adutil.c
--- sys/adosfs/adutil.c 19 Nov 2005 02:18:00 -0000 1.15
+++ sys/adosfs/adutil.c 23 Mar 2006 20:24:00 -0000
@@ -65,10 +65,8 @@
 
  hp = &VFSTOADOSFS(mp)->anodetab[AHASH(an)];
 
- for (;;)
- for (ap = hp->lh_first; ; ap = ap->link.le_next) {
- if (ap == NULL)
- return (NULL);
+ for (;;) {
+ LIST_FOREACH(ap, hp, link) {
  if (ABLKTOINO(ap->block) == an) {
  vp = ATOV(ap);
  simple_lock(&vp->v_interlock);
@@ -77,6 +75,9 @@
  break;
  }
  }
+ if (ap == NULL)
+ return (NULL);
+ }
  /* NOTREACHED */
 }
 
@@ -96,7 +97,7 @@
 
  hp = &amp->anodetab[AHASH(ap->block)];
 
- for (aq = hp->lh_first; aq ; aq = aq->link.le_next) {
+ LIST_FOREACH(aq, hp, link) {
  if (aq->block == ap->block) {
  lockmgr(&ap->a_lock, LK_RELEASE, NULL);
  return (EEXIST);
Index: sys/arch/hppa64/hppa64/autoconf.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/hppa64/hppa64/autoconf.c,v
retrieving revision 1.4
diff -u -r1.4 autoconf.c
--- sys/arch/hppa64/hppa64/autoconf.c 27 Dec 2005 18:31:09 -0000 1.4
+++ sys/arch/hppa64/hppa64/autoconf.c 23 Mar 2006 20:30:28 -0000
@@ -275,8 +275,7 @@
 #ifdef RAMDISK_HOOKS
  printf(" %s[a-p]", fakerdrootdev.dv_xname);
 #endif
- for (dv = alldevs.tqh_first; dv != NULL;
-    dv = dv->dv_list.tqe_next) {
+ TAILQ_FOREACH(dv, &alldevs, dv_list) {
  if (dv->dv_class == DV_DISK)
  printf(" %s[a-p]", dv->dv_xname);
 #ifdef NFSCLIENT
@@ -319,7 +318,7 @@
  goto gotdisk;
  }
 #endif
- for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
+ TAILQ_FOREACH(dv, &alldevs, dv_list) {
  if (dv->dv_class == DV_DISK &&
     strcmp(str, dv->dv_xname) == 0) {
 #ifdef RAMDISK_HOOKS
Index: sys/arch/macppc/stand/alloc.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/macppc/stand/alloc.c,v
retrieving revision 1.4
diff -u -r1.4 alloc.c
--- sys/arch/macppc/stand/alloc.c 15 Sep 2005 20:42:33 -0000 1.4
+++ sys/arch/macppc/stand/alloc.c 23 Mar 2006 20:44:32 -0000
@@ -114,15 +114,14 @@
 
 #ifdef ALLOC_FIRST_FIT
  /* scan freelist */
- for (f = freelist.lh_first; f != NULL && f->size < size;
-    f = f->list.le_next)
- /* noop */ ;
+ LIST_FOREACH(f, &freelist, list)
+ if (f->size >= size)
+ break;
  bestf = f;
  failed = (bestf == (struct fl *)0);
 #else
  /* scan freelist */
- f = freelist.lh_first;
- while (f != NULL) {
+ LIST_FOREACH(f, &freelist, list) {
  if (f->size >= size) {
  if (f->size == size) /* exact match */
  goto found;
@@ -133,7 +132,6 @@
  bestsize = f->size;
  }
  }
- f = f->list.le_next;
  }
 
  /* no match in freelist if bestsize unchanged */
@@ -201,13 +199,13 @@
  struct ml *m;
 
  /* Release chunks on freelist... */
- while ((m = freelist.lh_first) != NULL) {
+ for (; (m = LIST_FIRST(&freelist)) != NULL;) {
  LIST_REMOVE(m, list);
  OF_release(m, m->size);
  }
 
  /* ...and allocated list. */
- while ((m = allocatedlist.lh_first) != NULL) {
+ for (; (m = LIST_FIRST(&allocated)) != NULL;) {
  LIST_REMOVE(m, list);
  OF_release(m, m->size);
  }
Index: sys/arch/mvme68k/dev/sbic.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/mvme68k/dev/sbic.c,v
retrieving revision 1.17
diff -u -r1.17 sbic.c
--- sys/arch/mvme68k/dev/sbic.c 3 Dec 2005 18:09:37 -0000 1.17
+++ sys/arch/mvme68k/dev/sbic.c 23 Mar 2006 20:35:22 -0000
@@ -643,7 +643,7 @@
             dosched = 1;    /* start next command */
 
     } else
-    if ( dev->ready_list.tqh_last == &acb->chain.tqe_next ) {
+    if ( dev->ready_list.tqh_last == &TAILQ_NEXT(acb, chain)) {
 
         TAILQ_REMOVE(&dev->ready_list, acb, chain);
 
Index: sys/arch/mvme68k/dev/ssh.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/mvme68k/dev/ssh.c,v
retrieving revision 1.14
diff -u -r1.14 ssh.c
--- sys/arch/mvme68k/dev/ssh.c 3 Dec 2005 18:09:37 -0000 1.14
+++ sys/arch/mvme68k/dev/ssh.c 23 Mar 2006 20:39:35 -0000
@@ -391,7 +391,7 @@
  dosched = 1; /* start next command */
  --sc->sc_active;
  SSH_TRACE('d','a',stat,0)
- } else if (sc->ready_list.tqh_last == &acb->chain.tqe_next) {
+ } else if (sc->ready_list.tqh_last == &TAILQ_NEXT(acb, chain)) {
  TAILQ_REMOVE(&sc->ready_list, acb, chain);
  SSH_TRACE('d','r',stat,0)
  } else {
Index: sys/arch/sparc64/dev/fd.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/sparc64/dev/fd.c,v
retrieving revision 1.6
diff -u -r1.6 fd.c
--- sys/arch/sparc64/dev/fd.c 15 Mar 2006 20:20:41 -0000 1.6
+++ sys/arch/sparc64/dev/fd.c 23 Mar 2006 20:49:16 -0000
@@ -1078,7 +1078,7 @@
  struct fdc_softc *fdc;
  char *s;
 {
- struct fd_softc *fd = fdc->sc_drives.tqh_first;
+ struct fd_softc *fd = TAILQ_FIRST(&fdc->sc_drives);
  int n;
 
  /* Just print last status */
Index: sys/arch/sparc64/stand/ofwboot/alloc.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/sparc64/stand/ofwboot/alloc.c,v
retrieving revision 1.3
diff -u -r1.3 alloc.c
--- sys/arch/sparc64/stand/ofwboot/alloc.c 14 Mar 2002 03:16:01 -0000 1.3
+++ sys/arch/sparc64/stand/ofwboot/alloc.c 23 Mar 2006 20:49:16 -0000
@@ -112,15 +112,14 @@
 
 #ifdef ALLOC_FIRST_FIT
  /* scan freelist */
- for (f = freelist.lh_first; f != NULL && f->size < size;
-    f = f->list.le_next)
- /* noop */ ;
+ LIST_FOREACH(f, &freelist, list)
+ if (f->size >= size)
+ break;
  bestf = f;
  failed = (bestf == (struct fl *)0);
 #else
  /* scan freelist */
- f = freelist.lh_first;
- while (f != NULL) {
+ LIST_FOREACH(f, &freelist, list) {
  if (f->size >= size) {
  if (f->size == size) /* exact match */
  goto found;
@@ -131,7 +130,6 @@
  bestsize = f->size;
  }
  }
- f = f->list.le_next;
  }
 
  /* no match in freelist if bestsize unchanged */
@@ -201,13 +199,13 @@
  struct ml *m;
 
  /* Release chunks on freelist... */
- while ((m = freelist.lh_first) != NULL) {
+ for (; (m = TAILQ_FIRST(&freelist)) != NULL;) {
  LIST_REMOVE(m, list);
  OF_release(m, m->size);
  }
 
  /* ...and allocated list. */
- while ((m = allocatedlist.lh_first) != NULL) {
+ for (; (m = TAILQ_FIRST(&allocatedlist)) != NULL;) {
  LIST_REMOVE(m, list);
  OF_release(m, m->size);
  }
Index: sys/arch/zaurus/zaurus/autoconf.c
===================================================================
RCS file: /space/release/cvs/src/sys/arch/zaurus/zaurus/autoconf.c,v
retrieving revision 1.5
diff -u -r1.5 autoconf.c
--- sys/arch/zaurus/zaurus/autoconf.c 27 Dec 2005 18:31:11 -0000 1.5
+++ sys/arch/zaurus/zaurus/autoconf.c 23 Mar 2006 23:08:18 -0000
@@ -146,8 +146,7 @@
 
  if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
  printf("use one of:");
- for (dv = alldevs.tqh_first; dv != NULL;
-    dv = dv->dv_list.tqe_next) {
+ TAILQ_FOREACH(dv, &alldevs, dv_list) {
  if (dv->dv_class == DV_DISK)
  printf(" %s[a-p]", dv->dv_xname);
 #ifdef NFSCLIENT
@@ -177,7 +176,7 @@
  } else
  part = defpart;
 
- for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
+ TAILQ_FOREACH(dv, &alldevs, dv_list) {
  if (dv->dv_class == DV_DISK &&
     strcmp(str, dv->dv_xname) == 0) {
  majdev = findblkmajor(dv);
Index: sys/dev/microcode/aic7xxx/aicasm_gram.y
===================================================================
RCS file: /space/release/cvs/src/sys/dev/microcode/aic7xxx/aicasm_gram.y,v
retrieving revision 1.13
diff -u -r1.13 aicasm_gram.y
--- sys/dev/microcode/aic7xxx/aicasm_gram.y 28 Apr 2005 10:10:49 -0000 1.13
+++ sys/dev/microcode/aic7xxx/aicasm_gram.y 23 Mar 2006 22:56:23 -0000
@@ -1845,9 +1845,7 @@
  * expression are defined for this register.
  */
  if (symbol->info.rinfo->typecheck_masks != FALSE) {
- for(node = expression->referenced_syms.slh_first;
-    node != NULL;
-    node = node->links.sle_next) {
+ SLIST_FOREACH(node, &referenced_syms, links) {
  if ((node->symbol->type == MASK
   || node->symbol->type == FIELD
   || node->symbol->type == ENUM
@@ -1943,8 +1941,8 @@
 static int
 is_download_const(expression_t *immed)
 {
- if ((immed->referenced_syms.slh_first != NULL)
- && (immed->referenced_syms.slh_first->symbol->type == DOWNLOAD_CONST))
+ if (SLIST_FIRST(&immed->referenced_syms) != NULL)
+ && (SLIST_FIRST(&immed->referenced_syms)->symbol->type == DOWNLOAD_CONST))
  return (TRUE);
 
  return (FALSE);
Index: sys/dev/microcode/aic7xxx/aicasm_scan.l
===================================================================
RCS file: /space/release/cvs/src/sys/dev/microcode/aic7xxx/aicasm_scan.l,v
retrieving revision 1.9
diff -u -r1.9 aicasm_scan.l
--- sys/dev/microcode/aic7xxx/aicasm_scan.l 18 Sep 2004 19:51:53 -0000 1.9
+++ sys/dev/microcode/aic7xxx/aicasm_scan.l 23 Mar 2006 22:58:54 -0000
@@ -459,9 +459,7 @@
 
  if (newfile == NULL && type != SOURCE_FILE) {
                 path_entry_t include_dir;
-                for (include_dir = search_path.slh_first;
-                     include_dir != NULL;                
-                     include_dir = include_dir->links.sle_next) {
+ SLIST_FOREACH(include_dir, &search_path, links) {
  char fullname[PATH_MAX];
 
  if ((include_dir->quoted_includes_only == TRUE)
@@ -595,7 +593,7 @@
  if (yyfilename != NULL)
  free(yyfilename);
  yyfilename = NULL;
- include = include_stack.slh_first;
+ include = SLIST_FIRST(&include_stack);
  if (include != NULL) {
  yy_switch_to_buffer(include->buffer);
  yylineno = include->lineno;
Index: sys/netinet6/nd6.c
===================================================================
RCS file: /space/release/cvs/src/sys/netinet6/nd6.c,v
retrieving revision 1.70
diff -u -r1.70 nd6.c
--- sys/netinet6/nd6.c 21 Feb 2006 10:23:25 -0000 1.70
+++ sys/netinet6/nd6.c 24 Mar 2006 00:17:19 -0000
@@ -557,8 +557,7 @@
  }
 
  /* expire prefix list */
- pr = nd_prefix.lh_first;
- while (pr) {
+ for (pr = LIST_FIRST(&nd_prefix); pr != NULL;) {
  /*
  * check prefix lifetime.
  * since pltime is just for autoconf, pltime processing for
@@ -567,7 +566,7 @@
  if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME &&
     time_second - pr->ndpr_lastupdate > pr->ndpr_vltime) {
  struct nd_prefix *t;
- t = pr->ndpr_next;
+ t = LIST_NEXT(pr, ndpr_entry);
 
  /*
  * address expiration and prefix expiration are
@@ -577,7 +576,7 @@
  prelist_remove(pr);
  pr = t;
  } else
- pr = pr->ndpr_next;
+ pr = LIST_NEXT(pr, ndpr_entry);
  }
  splx(s);
 }
@@ -618,8 +617,8 @@
  }
 
  /* Nuke prefix list entries toward ifp */
- for (pr = nd_prefix.lh_first; pr; pr = npr) {
- npr = pr->ndpr_next;
+ for (pr = LIST_FIRST(&nd_prefix); pr != NULL; pr = npr) {
+ npr = LIST_NEXT(pr, ndpr_entry);
  if (pr->ndpr_ifp == ifp) {
  /*
  * Because if_detach() does *not* release prefixes
@@ -796,7 +795,7 @@
  * If the address matches one of our on-link prefixes, it should be a
  * neighbor.
  */
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  if (pr->ndpr_ifp != ifp)
  continue;
 
@@ -1301,7 +1300,7 @@
  */
  bzero(oprl, sizeof(*oprl));
  s = splsoftnet();
- pr = nd_prefix.lh_first;
+ pr = LIST_FIRST(&nd_prefix);
  while (pr && i < PRLSTSIZ) {
  struct nd_pfxrouter *pfr;
  int j;
@@ -1314,7 +1313,7 @@
  oprl->prefix[i].if_index = pr->ndpr_ifp->if_index;
  oprl->prefix[i].expire = pr->ndpr_expire;
 
- pfr = pr->ndpr_advrtrs.lh_first;
+ pfr = LIST_FIRST(&pr->ndpr_advrtrs);
  j = 0;
  while(pfr) {
  if (j < DRLSTSIZ) {
@@ -1332,13 +1331,13 @@
 #undef RTRADDR
  }
  j++;
- pfr = pfr->pfr_next;
+ pfr = LIST_NEXT(pfr, pfr_entry);
  }
  oprl->prefix[i].advrtrs = j;
  oprl->prefix[i].origin = PR_ORIG_RA;
 
  i++;
- pr = pr->ndpr_next;
+ pr = LIST_NEXT(pr, ndpr_entry);
  }
  splx(s);
 
@@ -1372,10 +1371,10 @@
  struct nd_prefix *pr, *next;
 
  s = splsoftnet();
- for (pr = nd_prefix.lh_first; pr; pr = next) {
+ for (pr = LIST_FIRST(&nd_prefix); pr; pr = next) {
  struct in6_ifaddr *ia, *ia_next;
 
- next = pr->ndpr_next;
+ next = LIST_NEXT(pr, ndpr_entry);
 
  if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
  continue; /* XXX */
@@ -2110,7 +2109,7 @@
  }
  l = 0;
 
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  u_short advrtrs;
  size_t advance;
  struct sockaddr_in6 *sin6;
@@ -2152,8 +2151,7 @@
  p->flags = pr->ndpr_stateflags;
  p->origin = PR_ORIG_RA;
  advrtrs = 0;
- for (pfr = pr->ndpr_advrtrs.lh_first; pfr;
-     pfr = pfr->pfr_next) {
+ LIST_FOREACH(pfr, &pr->ndpr_advrtrs, pfr_entry) {
  if ((void *)&sin6[advrtrs + 1] > (void *)pe) {
  advrtrs++;
  continue;
@@ -2170,8 +2168,7 @@
  }
  else {
  advrtrs = 0;
- for (pfr = pr->ndpr_advrtrs.lh_first; pfr;
-     pfr = pfr->pfr_next)
+ LIST_FOREACH(pfr, &pr->ndpr_advrtrs, pfr_entry)
  advrtrs++;
  }
 
Index: sys/netinet6/nd6.h
===================================================================
RCS file: /space/release/cvs/src/sys/netinet6/nd6.h,v
retrieving revision 1.25
diff -u -r1.25 nd6.h
--- sys/netinet6/nd6.h 8 Jul 2003 21:43:18 -0000 1.25
+++ sys/netinet6/nd6.h 24 Mar 2006 00:02:30 -0000
@@ -264,8 +264,6 @@
  int ndpr_refcnt; /* reference couter from addresses */
 };
 
-#define ndpr_next ndpr_entry.le_next
-
 #define ndpr_raf ndpr_flags
 #define ndpr_raf_onlink ndpr_flags.onlink
 #define ndpr_raf_auto ndpr_flags.autonomous
@@ -299,7 +297,6 @@
 
 struct nd_pfxrouter {
  LIST_ENTRY(nd_pfxrouter) pfr_entry;
-#define pfr_next pfr_entry.le_next
  struct nd_defrouter *router;
 };
 
Index: sys/netinet6/nd6_rtr.c
===================================================================
RCS file: /space/release/cvs/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.37
diff -u -r1.37 nd6_rtr.c
--- sys/netinet6/nd6_rtr.c 22 Mar 2006 14:37:45 -0000 1.37
+++ sys/netinet6/nd6_rtr.c 24 Mar 2006 00:18:15 -0000
@@ -509,7 +509,7 @@
  /*
  * Also delete all the pointers to the router in each prefix lists.
  */
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  struct nd_pfxrouter *pfxrtr;
  if ((pfxrtr = pfxrtr_lookup(pr, dr)) != NULL)
  pfxrtr_del(pfxrtr);
@@ -826,7 +826,7 @@
 {
  struct nd_pfxrouter *search;
 
- for (search = pr->ndpr_advrtrs.lh_first; search; search = search->pfr_next) {
+ LIST_FOREACH(search, &pr->ndpr_advrtrs, pfr_entry) {
  if (search->router == dr)
  break;
  }
@@ -866,7 +866,7 @@
 {
  struct nd_prefix *search;
 
- for (search = nd_prefix.lh_first; search; search = search->ndpr_next) {
+ LIST_FOREACH(search, &nd_prefix, ndpr_entry) {
  if (pr->ndpr_ifp == search->ndpr_ifp &&
     pr->ndpr_plen == search->ndpr_plen &&
     in6_are_prefix_equal(&pr->ndpr_prefix.sin6_addr,
@@ -930,7 +930,7 @@
 prelist_remove(pr)
  struct nd_prefix *pr;
 {
- struct nd_pfxrouter *pfr, *next;
+ struct nd_pfxrouter *pfr;
  int e, s;
 
  /* make sure to invalidate the prefix until it is really freed. */
@@ -962,9 +962,7 @@
  LIST_REMOVE(pr, ndpr_entry);
 
  /* free list of routers that adversed the prefix */
- for (pfr = pr->ndpr_advrtrs.lh_first; pfr; pfr = next) {
- next = pfr->pfr_next;
-
+ for (; (pfr = LIST_FIRST(&pr->ndpr_advrtrs)) != NULL;) {
  free(pfr, M_IP6NDP);
  }
  splx(s);
@@ -1276,7 +1274,7 @@
  * Check if there is a prefix that has a reachable advertising
  * router.
  */
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  if (pr->ndpr_raf_onlink && find_pfxlist_reachable_router(pr))
  break;
  }
@@ -1290,7 +1288,7 @@
  * Detach prefixes which have no reachable advertising
  * router, and attach other prefixes.
  */
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  /* XXX: a link-local prefix should never be detached */
  if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
  continue;
@@ -1311,7 +1309,7 @@
  }
  } else {
  /* there is no prefix that has a reachable router */
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
  continue;
 
@@ -1331,7 +1329,7 @@
  * interfaces.  Such cases will be handled in nd6_prefix_onlink,
  * so we don't have to care about them.
  */
- for (pr = nd_prefix.lh_first; pr; pr = pr->ndpr_next) {
+ LIST_FOREACH(pr, &nd_prefix, ndpr_entry) {
  int e;
 
  if (IN6_IS_ADDR_LINKLOCAL(&pr->ndpr_prefix.sin6_addr))
@@ -1438,7 +1436,7 @@
  * Although such a configuration is expected to be rare, we explicitly
  * allow it.
  */
- for (opr = nd_prefix.lh_first; opr; opr = opr->ndpr_next) {
+ LIST_FOREACH(opr, &nd_prefix, ndpr_entry) {
  if (opr == pr)
  continue;
 
@@ -1563,7 +1561,7 @@
  * If there's one, try to make the prefix on-link on the
  * interface.
  */
- for (opr = nd_prefix.lh_first; opr; opr = opr->ndpr_next) {
+ LIST_FOREACH(opr, &nd_prefix, ndpr_entry) {
  if (opr == pr)
  continue;
 
Index: sys/ufs/lfs/lfs_segment.c
===================================================================
RCS file: /space/release/cvs/src/sys/ufs/lfs/lfs_segment.c,v
retrieving revision 1.16
diff -u -r1.16 lfs_segment.c
--- sys/ufs/lfs/lfs_segment.c 5 Mar 2006 21:48:57 -0000 1.16
+++ sys/ufs/lfs/lfs_segment.c 23 Mar 2006 22:36:41 -0000
@@ -160,7 +160,7 @@
 /* BEGIN HACK */
 #define VN_OFFSET (((void *)&vp->v_mntvnodes.le_next) - (void *)vp)
 #define BACK_VP(VP) ((struct vnode *)(((void *)VP->v_mntvnodes.le_prev) - VN_OFFSET))
-#define BEG_OF_VLIST ((struct vnode *)(((void *)&mp->mnt_vnodelist.lh_first) - VN_OFFSET))
+#define BEG_OF_VLIST ((struct vnode *)(((void *)&TAILQ_FIRST(&mp->mnt_vnodelist)) - VN_OFFSET))
 
 /* Find last vnode. */
 loop: for (vp = LIST_FIRST(&mp->mnt_vnodelist);
@@ -541,7 +541,7 @@
 /* BEGIN HACK */
 #define BUF_OFFSET (((void *)&bp->b_vnbufs.le_next) - (void *)bp)
 #define BACK_BUF(BP) ((struct buf *)(((void *)BP->b_vnbufs.le_prev) - BUF_OFFSET))
-#define BEG_OF_LIST ((struct buf *)(((void *)&vp->v_dirtyblkhd.lh_first) - BUF_OFFSET))
+#define BEG_OF_LIST ((struct buf *)(((void *)&TAILQ_FIRST(&vp->v_dirtyblkhd)) - BUF_OFFSET))
 
 
 /*loop:       LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {*/
Index: sys/xfs/xfs_node-bsd.c
===================================================================
RCS file: /space/release/cvs/src/sys/xfs/xfs_node-bsd.c,v
retrieving revision 1.8
diff -u -r1.8 xfs_node-bsd.c
--- sys/xfs/xfs_node-bsd.c 8 Nov 2003 19:17:28 -0000 1.8
+++ sys/xfs/xfs_node-bsd.c 23 Mar 2006 23:57:01 -0000
@@ -275,13 +275,6 @@
     return error;
 }
 
-#ifndef LIST_FOREACH
-#define LIST_FOREACH(var, head, field) \
- for ((var) = ((head)->lh_first); \
- (var); \
- (var) = ((var)->field.le_next))
-#endif
-
 void
 vattr2xfs_attr(const struct vattr *va, struct xfs_attr *xa)
 {