From nobody Wed Nov 30 22:31:32 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NMv7n1qXRz4jCR9; Wed, 30 Nov 2022 22:31:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NMv7n0lysz453G; Wed, 30 Nov 2022 22:31:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yMIiDy+tTrJiWOfCWbXo01JdIQgCNc3lThCAP3wzyYM=; b=AUOFrIMSynJgd4O11NTZ7TZeHtarZQb5YYwRlb5BAt+C5WBhRC1omKIHwG+0zX5XM4amKB eAEQ5Jh9onKUSsDCKnDr1VGXkwS8vwAgRm0NtB1/oKmJ0pWg1R4fp1oNC/9+E87L/r9Kjv W4wiI/fGKy4fOoLyQQdE2u8ou1mWT9VU2n9k4Z9q3AbYx6RTQTKlOPckwEf7U34HF2aUwO g0QCFbTzuwVd2NMnwLG5Mq3kun16frQ0QCqcMFklcktsTMFJVuOG1fUf4a6XU05zHLPo55 rkwM2FkSVTkWX2XnYTI185595YpWN++QTGCt+ZT34QbFu1iJSB80Tdx438XLTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yMIiDy+tTrJiWOfCWbXo01JdIQgCNc3lThCAP3wzyYM=; b=ceIfGuUi+T4DuJSZ3A3IgogwkAGBggGffOOjxGkGwijbhsbQogj/HQEMGz/BXkLiZlruQY Jq/fAvfVR51Hh9Bs2bxEN6fx6HndUgmXf9um8HmXNz+eUF4jeSVeUI5dZzADdlb/Zuxr6A hCaM1qzQX1oYBu+xrhTwsDZKNzhAaeVBa5wlDxqTJGom+JVLMdyRViw/5S0jVDjrJ9QQWW AWsEfVvlKHAufss6zIutJ3vjRGaCfN5X7gGyQM9OoXkiJwusecn0/hWwGm93WEMGGO4ssf lPCd8q3QLZVEOdV1ucCQAWa5n7OQ4SSrmD7GKLsZbBp87J3gEQnYkOxeZM0uoQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669847493; a=rsa-sha256; cv=none; b=JoE/ZsdeusZgu2TqHQ2U4+MI7eDxvUk6I7+AD+ANgRdFmsywb+DX69FiR+Ikq6JqkoeTfC Jh0CaVVdguQcW1OiR0brqBX38O8mODdlk6MwGB9ZVxzo4+O+p/qt5e/kokhnmkzIAQWIWv XE0roTuYNdklyI/9GyyG4ixkmLiVtF/Oqwy2Qm0rYvtzLVSy5LK0xuACeMW7WTEMI8BG80 96tfeuixNNAp5x+FfUfnM/0a505vThbeTWykP4EyG4KAgR7U4ff3Aoy+XOJDwbjPTMx8he G4vAtiy4GGdnqOx3tfoXCVAygy1AbpWE/VMMvDVVWpcmKtCoRtdKAORgp19qPQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NMv7m6kYvzDgy; Wed, 30 Nov 2022 22:31:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AUMVWqv023781; Wed, 30 Nov 2022 22:31:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AUMVWnN023771; Wed, 30 Nov 2022 22:31:32 GMT (envelope-from git) Date: Wed, 30 Nov 2022 22:31:32 GMT Message-Id: <202211302231.2AUMVWnN023771@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 854001759e59 - main - stand/ofw: Use devparse List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 854001759e59172a2760d3a77f37a287f92053b3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=854001759e59172a2760d3a77f37a287f92053b3 commit 854001759e59172a2760d3a77f37a287f92053b3 Author: Warner Losh AuthorDate: 2022-11-30 22:10:18 +0000 Commit: Warner Losh CommitDate: 2022-11-30 22:30:33 +0000 stand/ofw: Use devparse Retire the custom parsedev routine and use the standard devparse. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37559 --- stand/libofw/devicename.c | 93 ++++++----------------------------------------- 1 file changed, 12 insertions(+), 81 deletions(-) diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c index 6ed2343ee7bd..7d488608c3f8 100644 --- a/stand/libofw/devicename.c +++ b/stand/libofw/devicename.c @@ -32,9 +32,7 @@ __FBSDID("$FreeBSD$"); #include "bootstrap.h" #include "libofw.h" -static int ofw_parsedev(struct ofw_devdesc **, const char *, const char **); - -/* +/* * Point (dev) at an allocated device specifier for the device matching the * path in (devspec). If it contains an explicit device specification, * use that. If not, use the default device. @@ -42,24 +40,24 @@ static int ofw_parsedev(struct ofw_devdesc **, const char *, const char **); int ofw_getdev(void **vdev, const char *devspec, const char **path) { - struct ofw_devdesc **dev = (struct ofw_devdesc **)vdev; + struct devdesc **dev = (struct devdesc **)vdev; int rv; /* - * If it looks like this is just a path and no device, go with the current - * device. + * If it looks like this is just a path and no device, go with the + * current device. */ if (devspec == NULL || strpbrk(devspec, ":@") == NULL) { - if (((rv = ofw_parsedev(dev, getenv("currdev"), NULL)) == 0) && - (path != NULL)) + rv = devparse(dev, getenv("currdev"), NULL); + if (rv == 0 && path != NULL) *path = devspec; - return(rv); + return (rv); } - + /* * Try to parse the device name off the beginning of the devspec */ - return(ofw_parsedev(dev, devspec, path)); + return (devparse(dev, devspec, path)); } /* @@ -94,80 +92,13 @@ ofw_path_to_handle(const char *ofwpath, const char *want_type, const char **path return ((phandle_t)-1); } -/* - * Point (dev) at an allocated device specifier matching the string version - * at the beginning of (devspec). Return a pointer to the remaining - * text in (path). - */ -static int -ofw_parsedev(struct ofw_devdesc **dev, const char *devspec, const char **path) -{ - struct ofw_devdesc *idev; - struct devsw *dv; - phandle_t handle; - const char *p; - const char *s; - char *ep; - char name[256]; - char type[64]; - int err; - int len; - int i; - - /* XXX next step: use devparse -- don't forget to hack ofw_disk like you did ofw_net */ - for (p = s = devspec; *s != '\0'; p = s) { - if ((s = strchr(p + 1, '/')) == NULL) - s = strchr(p, '\0'); - len = s - devspec; - bcopy(devspec, name, len); - name[len] = '\0'; - if ((handle = OF_finddevice(name)) == -1) { - bcopy(name, type, len); - type[len] = '\0'; - } else if (OF_getprop(handle, "device_type", type, sizeof(type)) == -1) - continue; - for (i = 0; (dv = devsw[i]) != NULL; i++) { - if (strncmp(dv->dv_name, type, strlen(dv->dv_name)) == 0) - goto found; - } - } - return(ENOENT); - -found: - if (path != NULL) - *path = s; - idev = malloc(sizeof(struct ofw_devdesc)); - if (idev == NULL) { - printf("ofw_parsedev: malloc failed\n"); - return ENOMEM; - } - idev->dd.d_dev = dv; - if (dv->dv_parsedev != NULL) { - p = devspec + strlen(dv->dv_name); - free(idev); - err = dv->dv_parsedev((struct devdesc **)&idev, devspec, path); - if (err != 0) { - return (err); - } - } else { - strcpy(idev->d_path, name); - } - - if (dev == NULL) { - free(idev); - } else { - *dev = idev; - } - return(0); -} - int ofw_setcurrdev(struct env_var *ev, int flags, const void *value) { - struct ofw_devdesc *ncurr; - int rv; + struct devdesc *ncurr; + int rv; - if ((rv = ofw_parsedev(&ncurr, value, NULL)) != 0) + if ((rv = devparse(&ncurr, value, NULL)) != 0) return (rv); free(ncurr);