git: 45dc8e3c2c62 - main - nvdimm: Use devclass_lookup to find devclasses.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 06 May 2022 21:44:11 UTC
The branch main has been updated by jhb:

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

commit 45dc8e3c2c625040433f53d1ab987be68e17e4d3
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-05-06 21:41:42 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-06 21:41:42 +0000

    nvdimm: Use devclass_lookup to find devclasses.
    
    To avoid hardcoding the nvdimm driver name, move nvdimm_find_by_handle
    below the definition of nvdimm_driver.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D35062
---
 sys/dev/nvdimm/nvdimm.c      | 43 ++++++++++++++++++++++---------------------
 sys/dev/nvdimm/nvdimm_e820.c |  2 +-
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/sys/dev/nvdimm/nvdimm.c b/sys/dev/nvdimm/nvdimm.c
index a5692fc65857..730fd49fef27 100644
--- a/sys/dev/nvdimm/nvdimm.c
+++ b/sys/dev/nvdimm/nvdimm.c
@@ -301,27 +301,6 @@ read_labels(struct nvdimm_dev *nv)
 	return (0);
 }
 
-struct nvdimm_dev *
-nvdimm_find_by_handle(nfit_handle_t nv_handle)
-{
-	struct nvdimm_dev *res;
-	device_t *dimms;
-	int i, error, num_dimms;
-
-	res = NULL;
-	error = devclass_get_devices(nvdimm_devclass, &dimms, &num_dimms);
-	if (error != 0)
-		return (NULL);
-	for (i = 0; i < num_dimms; i++) {
-		if (nvdimm_root_get_device_handle(dimms[i]) == nv_handle) {
-			res = device_get_softc(dimms[i]);
-			break;
-		}
-	}
-	free(dimms, M_TEMP);
-	return (res);
-}
-
 static int
 nvdimm_probe(device_t dev)
 {
@@ -468,6 +447,28 @@ static driver_t	nvdimm_driver = {
 	sizeof(struct nvdimm_dev),
 };
 
+struct nvdimm_dev *
+nvdimm_find_by_handle(nfit_handle_t nv_handle)
+{
+	struct nvdimm_dev *res;
+	device_t *dimms;
+	int i, error, num_dimms;
+
+	res = NULL;
+	error = devclass_get_devices(devclass_find(nvdimm_driver.name), &dimms,
+	    &num_dimms);
+	if (error != 0)
+		return (NULL);
+	for (i = 0; i < num_dimms; i++) {
+		if (nvdimm_root_get_device_handle(dimms[i]) == nv_handle) {
+			res = device_get_softc(dimms[i]);
+			break;
+		}
+	}
+	free(dimms, M_TEMP);
+	return (res);
+}
+
 DRIVER_MODULE(nvdimm, nvdimm_acpi_root, nvdimm_driver, nvdimm_devclass, NULL,
     NULL);
 MODULE_DEPEND(nvdimm, acpi, 1, 1, 1);
diff --git a/sys/dev/nvdimm/nvdimm_e820.c b/sys/dev/nvdimm/nvdimm_e820.c
index 66bdff937dc5..97f825004ed0 100644
--- a/sys/dev/nvdimm/nvdimm_e820.c
+++ b/sys/dev/nvdimm/nvdimm_e820.c
@@ -367,7 +367,7 @@ nvdimm_e820_chainevh(struct module *m, int e, void *arg __unused)
 
 	switch (e) {
 	case MOD_UNLOAD:
-		dc = nvdimm_e820_devclass;
+		dc = devclass_find(nvdimm_e820_driver.name);
 		maxunit = devclass_get_maxunit(dc);
 		for (i = 0; i < maxunit; i++) {
 			dev = devclass_get_device(dc, i);