git: eae3c14a2846 - stable/13 - devclass_add_driver: Permit NULL to be passed in dcp.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 17 May 2022 23:38:10 UTC
The branch stable/13 has been updated by jhb:

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

commit eae3c14a28469f047362b96de876ee7d64694ae3
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-04-19 17:42:38 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-17 21:16:13 +0000

    devclass_add_driver: Permit NULL to be passed in dcp.
    
    This permits a driver module structure that doesn't want to store a
    pointer to the new driver's devclass.
    
    Reviewed by:    imp
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D34962
    
    (cherry picked from commit 5bdea8826bdd48e2221f1b436ce86021ede412f2)
---
 sys/kern/subr_bus.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 42657034550f..8b7bcbf4e3e0 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -1110,6 +1110,7 @@ int
 devclass_add_driver(devclass_t dc, driver_t *driver, int pass, devclass_t *dcp)
 {
 	driverlink_t dl;
+	devclass_t child_dc;
 	const char *parentname;
 
 	PDEBUG(("%s", DRIVERNAME(driver)));
@@ -1141,7 +1142,9 @@ devclass_add_driver(devclass_t dc, driver_t *driver, int pass, devclass_t *dcp)
 		parentname = driver->baseclasses[0]->name;
 	else
 		parentname = NULL;
-	*dcp = devclass_find_internal(driver->name, parentname, TRUE);
+	child_dc = devclass_find_internal(driver->name, parentname, TRUE);
+	if (dcp != NULL)
+		*dcp = child_dc;
 
 	dl->driver = driver;
 	TAILQ_INSERT_TAIL(&dc->drivers, dl, link);