git: 9bc5c28cc0c1 - stable/13 - kboot: move to using devparse

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:13:34 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=9bc5c28cc0c1c3f19224bc6dce1e0d9f32be3363

commit 9bc5c28cc0c1c3f19224bc6dce1e0d9f32be3363
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-12-02 18:10:06 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:40 +0000

    kboot: move to using devparse
    
    We can use devparse directly now. No need to invent a kboot_parsedev
    that just does what devparse does now that we've refactored.
    
    Sponsored by:           Netflix
    
    (cherry picked from commit 6f8e9f22739aa7f5fe997741e9f50a66385c9e0c)
---
 stand/kboot/main.c | 54 ++++++++++++++++++------------------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)

diff --git a/stand/kboot/main.c b/stand/kboot/main.c
index 23211ce9df4c..3b2c43c20a0f 100644
--- a/stand/kboot/main.c
+++ b/stand/kboot/main.c
@@ -49,49 +49,31 @@ static void kboot_kseg_get(int *nseg, void **ptr);
 
 extern int command_fdt_internal(int argc, char *argv[]);
 
+/*
+ * NB: getdev should likely be identical to this most places, except maybe
+ * we should move to storing the length of the platform devdesc.
+ */
 int
 kboot_getdev(void **vdev, const char *devspec, const char **path)
 {
-	int i, rv;
-	const char *devpath, *filepath;
-	struct devsw *dv;
-	struct devdesc *desc;
-
-	if (devspec == NULL) {
-		rv = kboot_getdev(vdev, getenv("currdev"), NULL);
-		if (rv == 0 && path != NULL)
+	int rv;
+	struct devdesc **dev = (struct devdesc **)vdev;
+
+	/*
+	 * If it looks like this is just a path and no device, go with the
+	 * current device.
+	 */
+	if (devspec == NULL || strchr(devspec, ':') == NULL) {
+		if (((rv = devparse(dev, getenv("currdev"), NULL)) == 0) &&
+		    (path != NULL))
 			*path = devspec;
 		return (rv);
 	}
-	if (strchr(devspec, ':') != NULL) {
-		devpath = devspec;
-		filepath = strchr(devspec, ':') + 1;
-	} else {
-		devpath = getenv("currdev");
-		filepath = devspec;
-	}
 
-	for (i = 0; (dv = devsw[i]) != NULL; i++) {
-		if (strncmp(dv->dv_name, devpath, strlen(dv->dv_name)) == 0)
-			goto found;
-	}
-	return (ENOENT);
-
-found:
-	if (path != NULL && filepath != NULL)
-		*path = filepath;
-	else if (path != NULL)
-		*path = strchr(devspec, ':') + 1;
-
-	if (vdev != NULL) {
-		desc = malloc(sizeof(*desc));
-		desc->d_dev = dv;
-		desc->d_unit = 0;
-		desc->d_opendata = strdup(devpath);
-		*vdev = desc;
-	}
-
-	return (0);
+	/*
+	 * Try to parse the device name off the beginning of the devspec
+	 */
+	return (devparse(dev, devspec, path));
 }
 
 int