Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Factor out a common functionality into a subroutine.



details:   https://anonhg.NetBSD.org/src/rev/81a9f6e9880b
branches:  trunk
changeset: 481516:81a9f6e9880b
user:      enami <enami%NetBSD.org@localhost>
date:      Tue Feb 01 05:28:01 2000 +0000

description:
Factor out a common functionality into a subroutine.

diffstat:

 sys/kern/kern_subr.c |  51 +++++++++++++++++++++++----------------------------
 1 files changed, 23 insertions(+), 28 deletions(-)

diffs (110 lines):

diff -r 34a1454c6640 -r 81a9f6e9880b sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c      Tue Feb 01 05:26:12 2000 +0000
+++ b/sys/kern/kern_subr.c      Tue Feb 01 05:28:01 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_subr.c,v 1.55 2000/01/25 09:23:59 enami Exp $     */
+/*     $NetBSD: kern_subr.c,v 1.56 2000/02/01 05:28:01 enami Exp $     */
 
 /*-
  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@@ -109,6 +109,7 @@
 /* XXX these should eventually move to subr_autoconf.c */
 static int findblkmajor __P((const char *));
 static const char *findblkname __P((int));
+static struct device *finddevice __P((const char *));
 static struct device *getdisk __P((char *, int, int, dev_t *, int));
 static struct device *parsedisk __P((char *, int, int, dev_t *));
 static int getstr __P((char *, int));
@@ -749,10 +750,7 @@
                 * If it's a network interface, we can bail out
                 * early.
                 */
-               for (dv = alldevs.tqh_first; dv != NULL;
-                   dv = dv->dv_list.tqe_next)
-                       if (strcmp(dv->dv_xname, rootspec) == 0)
-                               break;
+               dv = finddevice(rootspec);
                if (dv != NULL && dv->dv_class == DV_IFNET) {
                        rootdv = dv;
                        goto haveroot;
@@ -767,13 +765,7 @@
                memset(buf, 0, sizeof(buf));
                sprintf(buf, "%s%d", rootdevname, DISKUNIT(rootdev));
 
-               for (dv = alldevs.tqh_first; dv != NULL;
-                   dv = dv->dv_list.tqe_next) {
-                       if (strcmp(buf, dv->dv_xname) == 0) {
-                               rootdv = dv;
-                               break;
-                       }
-               }
+               rootdv = finddevice(buf);
                if (rootdv == NULL) {
                        printf("device %s (0x%x) not configured\n",
                            buf, rootdev);
@@ -838,14 +830,8 @@
                memset(buf, 0, sizeof(buf));
                sprintf(buf, "%s%d", dumpdevname, DISKUNIT(dumpdev));
 
-               for (dv = alldevs.tqh_first; dv != NULL;
-                   dv = dv->dv_list.tqe_next) {
-                       if (strcmp(buf, dv->dv_xname) == 0) {
-                               dumpdv = dv;
-                               break;
-                       }
-               }
-               if (dv == NULL) {
+               dumpdv = finddevice(buf);
+               if (dumpdv == NULL) {
                        /*
                         * Device not configured.
                         */
@@ -895,6 +881,19 @@
 }
 
 static struct device *
+finddevice(name)
+       const char *name;
+{
+       struct device *dv;
+
+       for (dv = TAILQ_FIRST(&alldevs); dv != NULL;
+           dv = TAILQ_NEXT(dv, dv_list))
+               if (strcmp(dv->dv_xname, name) == 0)
+                       break;
+       return (dv);
+}
+
+static struct device *
 getdisk(str, len, defpart, devp, isdump)
        char *str;
        int len, defpart;
@@ -964,9 +963,9 @@
                }
 #endif
 
-       for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
-               if (dv->dv_class == DV_DISK &&
-                   strcmp(str, dv->dv_xname) == 0) {
+       dv = finddevice(str);
+       if (dv != NULL) {
+               if (dv->dv_class == DV_DISK) {
 #ifdef MEMORY_DISK_HOOKS
  gotdisk:
 #endif
@@ -974,14 +973,10 @@
                        if (majdev < 0)
                                panic("parsedisk");
                        *devp = MAKEDISKDEV(majdev, dv->dv_unit, part);
-                       break;
                }
 
-               if (dv->dv_class == DV_IFNET &&
-                   strcmp(str, dv->dv_xname) == 0) {
+               if (dv->dv_class == DV_IFNET)
                        *devp = NODEV;
-                       break;
-               }
        }
 
        *cp = c;



Home | Main Index | Thread Index | Old Index