Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt Use strlist(9).



details:   https://anonhg.NetBSD.org/src/rev/06c98d50882a
branches:  trunk
changeset: 958903:06c98d50882a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Jan 24 15:43:22 2021 +0000

description:
Use strlist(9).

diffstat:

 sys/dev/fdt/fdt_subr.c |  33 +++++++++++----------------------
 1 files changed, 11 insertions(+), 22 deletions(-)

diffs (70 lines):

diff -r d5c0d4bb8595 -r 06c98d50882a sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c    Sun Jan 24 15:43:09 2021 +0000
+++ b/sys/dev/fdt/fdt_subr.c    Sun Jan 24 15:43:22 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.38 2020/07/16 16:39:18 jmcneill Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.39 2021/01/24 15:43:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.38 2020/07/16 16:39:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.39 2021/01/24 15:43:22 thorpej Exp $");
 
 #include "opt_fdt.h"
 
@@ -502,42 +502,31 @@
 const char *
 fdtbus_get_string_index(int phandle, const char *prop, u_int index)
 {
-       const char *names, *name;
-       int len, cur;
+       const char *names;
+       int len;
 
        if ((len = OF_getproplen(phandle, prop)) < 0)
                return NULL;
 
        names = fdtbus_get_string(phandle, prop);
 
-       for (name = names, cur = 0; len > 0;
-            len -= strlen(name) + 1, name += strlen(name) + 1, cur++) {
-               if (index == cur)
-                       return name;
-       }
-
-       return NULL;
+       return strlist_string(names, len, index);
 }
 
 int
 fdtbus_get_index(int phandle, const char *prop, const char *name, u_int *idx)
 {
        const char *p;
-       size_t pl;
-       u_int index;
-       int len;
+       int len, index;
 
        p = fdtbus_get_prop(phandle, prop, &len);
        if (p == NULL || len <= 0)
                return -1;
 
-       for (index = 0; len > 0;
-           pl = strlen(p) + 1, len -= pl, p += pl, index++) {
-               if (strcmp(p, name) == 0) {
-                       *idx = index;
-                       return 0;
-               }
-       }
+       index = strlist_index(p, len, name);
+       if (index == -1)
+               return -1;
 
-       return -1;
+       *idx = index;
+       return 0;
 }



Home | Main Index | Thread Index | Old Index