From nobody Tue Jan 24 22:13:23 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 4P1h7S0XXBz3bgM0; Tue, 24 Jan 2023 22:13:24 +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 4P1h7R4Zn5z3GNn; Tue, 24 Jan 2023 22:13:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598403; 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=bg10cy59EeEfnLSPsI8c8Fz2PhE9Y8HDiADq5V7a1QU=; b=SogiE2jmePQbaWxKjhIfzTLx7morJ1YcPV5Mn3fABvBoL6zE670DqRdauhEJys6nn5s0fc N15yh7/9kwxX79nsxeodRSlX2ZsashwsBi3o8p1nLoB186tF3Ydgz/anIvqU6P0L2UY+Uj THJD0toc25RRuVFaD2pbsEITkb2tc3S5+PwtEpERUd/sxP6czwPUg1YCM5asUzBRhXgw/M kMnjGIwpr5HAPCJbgNcJ0SniBqMIROoSGAJAQNlnSMEwVJOf9VaRAbxORLYU4ytdQ16NJX jBSh2c/3ymQaOgHO723aKcwgzaqOsmv2DJMsR7FmS4whJtW8dDO84tmOkcIMqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598403; 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=bg10cy59EeEfnLSPsI8c8Fz2PhE9Y8HDiADq5V7a1QU=; b=xTRGo+Bv6EgaLOIbLkc72rwGdRd2VIRgUpcOKB8WRl2EDoxEc1swq7JrybRjzZPsNR1G4P v39mub5jeaVxycfcepx1DSleKIDiypzte7zycAiBsBZYtFIoZu5Y6rsR4FHkxIdWGpOww2 /LrHWVJBQ8RFqUsX+v+rN6FVbXhUD1bTnDxVuKm/HJjJr/Zo75Chuy0lAe0dmprzalbHvK kzXVuGBcvjIsDCvYF0XC6nHjPa7d+RPqwYvDnmYXkrIn+XMORTqXmwcCXQiEcOZv7c4xB5 8XcjcR1HA+ssbxtV4Hob46kB9dY1t/2qrBepzHWYBIOBh2gBBPMgMUcfvn5L4A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598403; a=rsa-sha256; cv=none; b=q8nNr3ul//upbCNlLJcHrLLM/JjpqjNyJ7bDOJ/Zc5IYMmVT0zgUB0SSLF0BOJefkxTg4m 86U91/U3nCGFWI+2nvWTXR1JNKm7v70CHRzJ1c8DoJyNrjL5vS9ka3kUUhHpXCJul7vOz3 f/5ktnX+AsVHcdWR+fBf0anexdRFC8BeEm3z/B861zhi7p78oogUW7AfsqOEvmCP0CvSWn 20N/6whDCwCtmciAj9IbojtpMFnv9rRN4cA8XMyVEGOB6RNQUMl0iOTGuUPsENkBxFdJNw 3sc+Fg7/0uUHcLOmcFZPh0XkfsJyOTZfPS/3S4pbMdnn8ADvTwRtgRb6csadHg== 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 4P1h7R3hk4zQh5; Tue, 24 Jan 2023 22:13:23 +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 30OMDNqb088360; Tue, 24 Jan 2023 22:13:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMDNRK088359; Tue, 24 Jan 2023 22:13:23 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:23 GMT Message-Id: <202301242213.30OMDNRK088359@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: 31cf842a96da - stable/13 - stand: create devinit 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: 31cf842a96da02e198590d93f7577c1621035d7b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=31cf842a96da02e198590d93f7577c1621035d7b commit 31cf842a96da02e198590d93f7577c1621035d7b Author: Warner Losh AuthorDate: 2022-11-30 22:09:29 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:39 +0000 stand: create devinit devinit() marches through all the devices, calling the inint routines if any exist. Replace all the identical copies of this code. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37349 (cherry picked from commit 66012c8fc4f92b80a61405dc7e206617e9f08920) --- stand/efi/loader/main.c | 4 +--- stand/i386/loader/main.c | 9 +-------- stand/i386/zfsboot/zfsboot.c | 4 +--- stand/libsa/dev.c | 18 ++++++++++++++++++ stand/libsa/libsa.3 | 8 ++++++++ stand/libsa/stand.h | 1 + stand/powerpc/ofw/main.c | 7 +------ stand/userboot/userboot/main.c | 8 +------- 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index 5edc06c9e0d5..85c545e0e72f 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -991,9 +991,7 @@ main(int argc, CHAR16 *argv[]) "failures\n", i); } - for (i = 0; devsw[i] != NULL; i++) - if (devsw[i]->dv_init != NULL) - (devsw[i]->dv_init)(); + devinit(); /* * Detect console settings two different ways: one via the command diff --git a/stand/i386/loader/main.c b/stand/i386/loader/main.c index 15d1c312b278..861e08e7569c 100644 --- a/stand/i386/loader/main.c +++ b/stand/i386/loader/main.c @@ -96,8 +96,6 @@ ptov(uintptr_t x) int main(void) { - int i; - /* Pick up arguments */ kargs = (void *)__args; initial_howto = kargs->howto; @@ -244,12 +242,7 @@ main(void) import_geli_boot_data(gbdata); #endif /* LOADER_GELI_SUPPORT */ - /* - * March through the device switch probing for things. - */ - for (i = 0; devsw[i] != NULL; i++) - if (devsw[i]->dv_init != NULL) - (devsw[i]->dv_init)(); + devinit(); printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, bios_extmem / 1024); diff --git a/stand/i386/zfsboot/zfsboot.c b/stand/i386/zfsboot/zfsboot.c index ea390b6ea7a6..1d64ace063e0 100644 --- a/stand/i386/zfsboot/zfsboot.c +++ b/stand/i386/zfsboot/zfsboot.c @@ -211,9 +211,7 @@ main(void) env_setenv("currdev", EV_VOLATILE, "", i386_setcurrdev, env_nounset); - for (i = 0; devsw[i] != NULL; i++) - if (devsw[i]->dv_init != NULL) - (devsw[i]->dv_init)(); + devinit(); /* XXX assumes this will be a disk, but it looks likely give above */ disk_parsedev((struct devdesc **)&devdesc, boot_devname + 4, NULL); diff --git a/stand/libsa/dev.c b/stand/libsa/dev.c index c0bcce07718b..158b4d69381b 100644 --- a/stand/libsa/dev.c +++ b/stand/libsa/dev.c @@ -149,3 +149,21 @@ devparse(struct devdesc **dev, const char *devspec, const char **path) free(idev); return (0); } + +int +devinit(void) +{ + int err = 0; + + /* + * March through the device switch probing for things. + */ + for (int i = 0; devsw[i] != NULL; i++) { + if (devsw[i]->dv_init != NULL) { + if ((devsw[i]->dv_init)() != 0) { + err++; + } + } + } + return (err); +} diff --git a/stand/libsa/libsa.3 b/stand/libsa/libsa.3 index 210f54a5aa6a..fcfd22cbf0d0 100644 --- a/stand/libsa/libsa.3 +++ b/stand/libsa/libsa.3 @@ -537,6 +537,14 @@ is non-NULL, then a pointer to the remainder of the .Dv devdesc string after the device specification is written. .It Xo +.Ft int +.Fn devinit void +Calls all the +.Fa dv_init +routines in the +.Dv devsw +array, returning the number of routines that returned an error. +.It Xo .Ft void .Fn twiddle void .Xc diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h index 6e52325ec166..660337db6980 100644 --- a/stand/libsa/stand.h +++ b/stand/libsa/stand.h @@ -188,6 +188,7 @@ struct devdesc { char *devformat(struct devdesc *d); int devparse(struct devdesc **, const char *, const char **); +int devinit(void); struct open_file { int f_flags; /* see F_* below */ diff --git a/stand/powerpc/ofw/main.c b/stand/powerpc/ofw/main.c index 81195d3f2444..177e665a4dc7 100644 --- a/stand/powerpc/ofw/main.c +++ b/stand/powerpc/ofw/main.c @@ -182,12 +182,7 @@ main(int (*openfirm)(void *)) /* Set up currdev variable to have hooks in place. */ env_setenv("currdev", EV_VOLATILE, "", ofw_setcurrdev, env_nounset); - /* - * March through the device switch probing for things. - */ - for (i = 0; devsw[i] != NULL; i++) - if (devsw[i]->dv_init != NULL) - (devsw[i]->dv_init)(); + devinit(); printf("\n%s", bootprog_info); printf("Memory: %lldKB\n", memsize() / 1024); diff --git a/stand/userboot/userboot/main.c b/stand/userboot/userboot/main.c index 9ede0cd360e9..6ec5c5ddbbb6 100644 --- a/stand/userboot/userboot/main.c +++ b/stand/userboot/userboot/main.c @@ -206,13 +206,7 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks) * Initialise the block cache. Set the upper limit. */ bcache_init(32768, 512); - /* - * March through the device switch probing for things. - */ - for (i = 0; devsw[i] != NULL; i++) - if (devsw[i]->dv_init != NULL) - (devsw[i]->dv_init)(); - + devinit(); extract_currdev(); /*