Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Move the code that expands the cd_devs array into a...



details:   https://anonhg.NetBSD.org/src/rev/1327974db877
branches:  trunk
changeset: 518566:1327974db877
user:      augustss <augustss%NetBSD.org@localhost>
date:      Sun Dec 02 02:40:57 2001 +0000

description:
Move the code that expands the cd_devs array into a subroutine.

diffstat:

 sys/kern/subr_autoconf.c |  67 +++++++++++++++++++++++++++--------------------
 1 files changed, 39 insertions(+), 28 deletions(-)

diffs (95 lines):

diff -r 9c21d854ef7c -r 1327974db877 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Sun Dec 02 02:26:26 2001 +0000
+++ b/sys/kern/subr_autoconf.c  Sun Dec 02 02:40:57 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.58 2001/11/12 15:21:46 lukem Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.59 2001/12/02 02:40:57 augustss Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.58 2001/11/12 15:21:46 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.59 2001/12/02 02:40:57 augustss Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -325,6 +325,42 @@
 }
 
 /*
+ * Expand the size of the cd_devs array if necessary.
+ */
+void
+config_makeroom(int n, struct cfdriver *cd)
+{
+       int old, new;
+       void **nsp;
+
+       if (n < cd->cd_ndevs)
+               return;
+
+       /*
+        * Need to expand the array.
+        */
+       old = cd->cd_ndevs;
+       if (old == 0)
+               new = MINALLOCSIZE / sizeof(void *);
+       else
+               new = old * 2;
+       while (new <= n)
+               new *= 2;
+       cd->cd_ndevs = new;
+       nsp = malloc(new * sizeof(void *), M_DEVBUF,
+           cold ? M_NOWAIT : M_WAITOK);        
+       if (nsp == 0)
+               panic("config_attach: %sing dev array",
+                   old != 0 ? "expand" : "creat");
+       memset(nsp + old, 0, (new - old) * sizeof(void *));
+       if (old != 0) {
+               memcpy(nsp, cd->cd_devs, old * sizeof(void *));
+               free(cd->cd_devs, M_DEVBUF);
+       }
+       cd->cd_devs = nsp;
+}
+
+/*
  * Attach a found device.  Allocates memory for device variables.
  */
 struct device *
@@ -395,32 +431,7 @@
        }
 
        /* put this device in the devices array */
-       if (dev->dv_unit >= cd->cd_ndevs) {
-               /*
-                * Need to expand the array.
-                */
-               int old = cd->cd_ndevs, new;
-               void **nsp;
-
-               if (old == 0)
-                       new = MINALLOCSIZE / sizeof(void *);
-               else
-                       new = old * 2;
-               while (new <= dev->dv_unit)
-                       new *= 2;
-               cd->cd_ndevs = new;
-               nsp = malloc(new * sizeof(void *), M_DEVBUF,
-                   cold ? M_NOWAIT : M_WAITOK);        
-               if (nsp == 0)
-                       panic("config_attach: %sing dev array",
-                           old != 0 ? "expand" : "creat");
-               memset(nsp + old, 0, (new - old) * sizeof(void *));
-               if (old != 0) {
-                       memcpy(nsp, cd->cd_devs, old * sizeof(void *));
-                       free(cd->cd_devs, M_DEVBUF);
-               }
-               cd->cd_devs = nsp;
-       }
+       config_makeroom(dev->dv_unit, cd);
        if (cd->cd_devs[dev->dv_unit])
                panic("config_attach: duplicate %s", dev->dv_xname);
        cd->cd_devs[dev->dv_unit] = dev;



Home | Main Index | Thread Index | Old Index