From nobody Tue Jan 24 22:13:32 2023 X-Original-To: dev-commits-src-branches@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 4P1h7c5KNYz3bgPW; Tue, 24 Jan 2023 22:13:32 +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 4P1h7c4j5cz3HB1; Tue, 24 Jan 2023 22:13:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598412; 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=9X2wUCeX4G45xEXTlCtTnL+GoUxhF6tXmsQUo/A3tuQ=; b=ZBJaItUPU/RzkgpnApdCUsM7I6351i+qn2AS0PBnVb2h3YqZqNrWEssRRmZADppMQJ6INK 0NExiPpPqVp8NtaAeR/RQNx2LFBi2xACZpanYgiaVsMVLSyrdANZ1m21GIKz07L/8O2qj+ azyNJSu/64fikHs1QycArkqNEb/jQo7WnB2L/8/eyuXZo7I11y9l6GhkcyYYozWn2FxfGy CxROIxNdalRUli6Yx4B73XLmLztrpwTmLg8sOncJp/7FtD+OtdNqlCxhzAzIcJX46II0Ja tWkYhMdiMLieeMzlRUOo4q9dARnhFX0jVZ5YtL4WU0B27SwQyKcQxrrx8QbR3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598412; 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=9X2wUCeX4G45xEXTlCtTnL+GoUxhF6tXmsQUo/A3tuQ=; b=R2nAJuYozRKJHvXdhsX5kLSXJ9RZTdEVE09j1xYNlJAA7NC6CVn7o80lxkACHpgJ7u7O8A r9cgNXUihlNcJkZISFO7i8aAHCmnp3YZxgBqy6r8W2K3SmJ0yCB4QK6PLfz/ZJ/QsgHNRD DwCk8/wf+KdwmmsfFTkDYT1UcUJxY0MsUMJAtC4B9p/LGCqWwH9pC+tQGAvjFvwy9Eo/1O iAPWTSO/gs8Ophoj1zNeazYyPKyI319qCGhhL//++gMGn2zYZxolcY9vCSEZB2GuzsCfh+ RVMMNa8hXT+GjM8aD8BND4HR3syGNufdFsvduunsMPINvJXMgEJsDclEM1WEVg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598412; a=rsa-sha256; cv=none; b=IbuLMH/9ihalCruNLdEvpFrqQ4vYgsziVc0JLMQmSBtGbuUTZqvXQ15VUpUKFRzJEmT0+w T6qLG/Ncw7kR3Q8P72DzUDi2e2CtUJwttB3YxR/HiAs5JR2S3MdU9DAclH4wGbaeXl3o6D 6bfh40EXrKiuktsPoFXBI6RpMceyvUuUJHQIfmsJ7i5HrbRYCNYIqExuJ5D52F6E+TKWuP pQTh9ljNtOhZgpRnBB07gCZ4buo3h5rZ0srgkwWYTYI50BZSXOnDs+PUsuZjbkuSToqZmJ pJ/LtApSKTb17IwZQ8OJ8zt82WwxSr0LeBjxRG/PVgeuioM1Mo4evNKCre2ylg== 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 4P1h7c3phVzQYp; Tue, 24 Jan 2023 22:13: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 30OMDWMh088565; Tue, 24 Jan 2023 22:13:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMDWfO088564; Tue, 24 Jan 2023 22:13:32 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:32 GMT Message-Id: <202301242213.30OMDWfO088564@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 7ece24fe1680 - stable/13 - stand/ofw: Refactor ofw parsedev List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 7ece24fe1680fe849667eab6ae4e84d93f364dbd Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7ece24fe1680fe849667eab6ae4e84d93f364dbd commit 7ece24fe1680fe849667eab6ae4e84d93f364dbd Author: Warner Losh AuthorDate: 2022-11-30 22:10:23 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:40 +0000 stand/ofw: Refactor ofw parsedev Both ofw_disk and ofw_net use the same parsedev routine, except for the string passed in to match the ofw device node's type. Create a routine to do that and connect these two users up to that. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37560 (cherry picked from commit f9ce8da86434867e1e7172fb56a5504f91c98ce4) --- stand/libofw/devicename.c | 23 +++++++++++++++++++++++ stand/libofw/libofw.h | 2 ++ stand/libofw/ofw_disk.c | 18 +----------------- stand/libofw/ofw_net.c | 18 +----------------- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c index 7d488608c3f8..77a53ccd90ce 100644 --- a/stand/libofw/devicename.c +++ b/stand/libofw/devicename.c @@ -105,3 +105,26 @@ ofw_setcurrdev(struct env_var *ev, int flags, const void *value) return (mount_currdev(ev, flags, value)); } + +int +ofw_common_parsedev(struct devdesc **dev, const char *devspec, const char **path, + const char *ofwtype) +{ + const char *rem_path; + struct ofw_devdesc *idev; + + if (ofw_path_to_handle(devspec, ofwtype, &rem_path) == -1) + return (ENOENT); + idev = malloc(sizeof(struct ofw_devdesc)); + if (idev == NULL) { + printf("ofw_parsedev: malloc failed\n"); + return ENOMEM; + }; + strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1, + sizeof(idev->d_path))); + if (dev != NULL) + *dev = &idev->dd; + if (path != NULL) + *path = rem_path; + return 0; +} diff --git a/stand/libofw/libofw.h b/stand/libofw/libofw.h index ce7e6e986029..dc520d741290 100644 --- a/stand/libofw/libofw.h +++ b/stand/libofw/libofw.h @@ -63,6 +63,8 @@ extern int ofw_autoload(void); void ofw_memmap(int); phandle_t ofw_path_to_handle(const char *ofwpath, const char *want_type, const char **path); +int ofw_common_parsedev(struct devdesc **dev, const char *devspec, const char **path, + const char *ofwtype); struct preloaded_file; struct file_format; diff --git a/stand/libofw/ofw_disk.c b/stand/libofw/ofw_disk.c index ae2776ee4689..ae36ca8be4b9 100644 --- a/stand/libofw/ofw_disk.c +++ b/stand/libofw/ofw_disk.c @@ -234,21 +234,5 @@ ofwd_fmtdev(struct devdesc *idev) static int ofwd_parsedev(struct devdesc **dev, const char *devspec, const char **path) { - const char *rem_path; - struct ofw_devdesc *idev; - - if (ofw_path_to_handle(devspec, ofwdisk.dv_name, &rem_path) == -1) - return (ENOENT); - idev = malloc(sizeof(struct ofw_devdesc)); - if (idev == NULL) { - printf("ofw_parsedev: malloc failed\n"); - return ENOMEM; - }; - strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1, - sizeof(idev->d_path))); - if (dev != NULL) - *dev = &idev->dd; - if (path != NULL) - *path = rem_path; - return 0; + return (ofw_common_parsedev(dev, devspec, path, ofwdisk.dv_name)); } diff --git a/stand/libofw/ofw_net.c b/stand/libofw/ofw_net.c index 59b9f8de7efb..0a2e7e2a8714 100644 --- a/stand/libofw/ofw_net.c +++ b/stand/libofw/ofw_net.c @@ -308,23 +308,7 @@ static int ofwnd_init(void) static int ofwnd_parsedev(struct devdesc **dev, const char *devspec, const char **path) { - const char *rem_path; - struct ofw_devdesc *idev; - - if (ofw_path_to_handle(devspec, ofw_netdev.dv_name, &rem_path) == -1) - return (ENOENT); - idev = malloc(sizeof(struct ofw_devdesc)); - if (idev == NULL) { - printf("ofw_parsedev: malloc failed\n"); - return ENOMEM; - }; - strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1, - sizeof(idev->d_path))); - if (dev != NULL) - *dev = &idev->dd; - if (path != NULL) - *path = rem_path; - return 0; + return (ofw_common_parsedev(dev, devspec, path, ofw_netdev.dv_name)); } static bool