From nobody Wed Nov 30 22:31:33 2022 X-Original-To: dev-commits-src-all@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 4NMv7p1Lgzz4jCHR; Wed, 30 Nov 2022 22:31:34 +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 4NMv7p0rRCz455g; Wed, 30 Nov 2022 22:31:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847494; 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=6vtzWe8HPDbnGwroNb4t5+hY+Sywt+J+2l2LcsW5hQY=; b=S7511bPEKGLS3TjMAuffQC0abUxBKQz/zC4XtcsilxZSgCXJq2mdtZfr501khADZx/OiVS UwQN0Ac+V7JxTb0ODYtDu0xQPFiITg+fr4epGBcVptkN/4/vQf0AK2QIsrNAVzGooI3oqO AKlB91iLFtN/nzq0keQGgnd4OSDAggCF26kmFo8XD49YnKZnTHqWwfGOqXTlWqeR7RnLxc bqguCbmGprpOkN9ippsWMLjs6kx8SSZU9xATBzJmw0llf8MqKP+ScepdpgpjDdgc8OEJ1y bzEg2eE1IFD/iqDR0ag76hmILeQKDpoVmm36NC1GrTlOeoWtAfJhciJuKPR0OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847494; 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=6vtzWe8HPDbnGwroNb4t5+hY+Sywt+J+2l2LcsW5hQY=; b=mlGumOYwyWCvSDS/ZM0f3lYXay8/bFod60q5ZR2ypQ0/c4LsSB6GL0v7V2gf/pekog+Ouw AJVbArWY6lNYUzNVjZimWgqxL4mA+3R0GafHeW7Ntj3Q7+cxPL+WZWRqBFx0C9DFLnKuZx HI9W3mvfxvS7Np1sXMR66NFSmxatuteFxR81m5a7NR/+BG4dzhe0g49C86EUgc3ZHIKiaB U0m4pD4uTV+0Vk+4NqGpZl7EgOcnKLS1oVY4isUKoFOaP2XJ0KhUvQdUn39BgOONpb+L/C G7uXq8n1qTRC2VBZ31/+vvaoZGIoDY4BVPwMEvl/LQKhJHhizfArIsFLHOwwdA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669847494; a=rsa-sha256; cv=none; b=SHFkcYEc/mu7QDAa1xwNznLzombrL+cKcpNSw2oZJSxzg703hPF8P9DiDu6DMrvsIvsW8E GU22IPcsVlhDGIJq8vHg1/GEhBXF5DCNz7+oPXBWtf8QAJL91QE+Cu/79tTNc4f8Pepd4/ w6j0Z11yI5nQikKhDL74gfCHNQteNw2oHRGTBPEmpBa1se5X2LwpAFCCecDCt99TbR9URr e6WasJ6R9q9oSQeK/dMCWK7ssMWAytxl1/JYPgnARlcW8hkD4+Bs+wg3CuljpVyoVgYmIU Ysv5bNASEspjtpc/1KZyVWAkEeLAB0dcQJZrxEsOlrf/o86n9khf8o9VCIZk6g== 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 4NMv7n6wdYz1CrB; Wed, 30 Nov 2022 22:31:33 +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 2AUMVXpw024572; Wed, 30 Nov 2022 22:31:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AUMVXl9024571; Wed, 30 Nov 2022 22:31:33 GMT (envelope-from git) Date: Wed, 30 Nov 2022 22:31:33 GMT Message-Id: <202211302231.2AUMVXl9024571@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: f9ce8da86434 - main - stand/ofw: Refactor ofw parsedev List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: f9ce8da86434867e1e7172fb56a5504f91c98ce4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f9ce8da86434867e1e7172fb56a5504f91c98ce4 commit f9ce8da86434867e1e7172fb56a5504f91c98ce4 Author: Warner Losh AuthorDate: 2022-11-30 22:10:23 +0000 Commit: Warner Losh CommitDate: 2022-11-30 22:30:34 +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 --- 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