git: 5740057b4388 - main - stand/uboot: Explain why we test for NULL here

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 13 Jan 2023 21:24:45 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=5740057b4388f116717b9614cd54cf2c755e6e7d

commit 5740057b4388f116717b9614cd54cf2c755e6e7d
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-01-13 21:19:47 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-13 21:22:38 +0000

    stand/uboot: Explain why we test for NULL here
    
    Most parsedev routines assume that idev is non-null and can always be
    set. Since we break from this pattern in uboot, explain why in a
    comment. devparse was invented to put a lot of common code in one place
    and to simplify the archsw.arch_getdev code and any dv_parsedev code
    called. However, uboot couldn't use devparse at the time because its
    device naming scheme slightly different parsing. So, we still use
    uboot_parsedev directly from uboot_getdev where dev could be NULL. Add a
    comment to this effect.
    
    The match functionality added for ofw likely could be used to clean up
    the multiple kludges that are here for uboot's device naming differences
    with the normal boot loader. This work will wait for the future.
    
    Sponsored by:           Netflix
    Reviewed by:            kevans
    Differential Revision:  https://reviews.freebsd.org/D38042
---
 stand/uboot/devicename.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/stand/uboot/devicename.c b/stand/uboot/devicename.c
index 075880baa59f..d5de86384369 100644
--- a/stand/uboot/devicename.c
+++ b/stand/uboot/devicename.c
@@ -148,6 +148,10 @@ uboot_parsedev(struct uboot_devdesc **dev, const char *devspec,
 		goto fail;
 	}
 	idev->dd.d_dev = dv;
+	/*
+	 * dev can be NULL, since uboot_getdev calls us directly, rather than via
+	 * dv_parsedev in devparse() which otherwise ensures that it can't be NULL.
+	 */
 	if (dev == NULL) {
 		free(idev);
 	} else {