git: c7f0b91ba269 - stable/13 - smapi: Store softc pointer in si_drv1 of cdev.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 20 May 2022 00:21:00 UTC
The branch stable/13 has been updated by jhb:

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

commit c7f0b91ba2693e50f32402e1094f51c6431b4768
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-05-05 23:35:19 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-05-19 22:01:50 +0000

    smapi: Store softc pointer in si_drv1 of cdev.
    
    Rather than fetching the softc using the device's unit number as an
    index into the devclass.
    
    Differential Revision:  https://reviews.freebsd.org/D35063
    
    (cherry picked from commit d4f988e1886fee0c89443b6937bf47b6439f80b0)
---
 sys/i386/bios/smapi.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/sys/i386/bios/smapi.c b/sys/i386/bios/smapi.c
index 5b82df87e980..653399e1ca58 100644
--- a/sys/i386/bios/smapi.c
+++ b/sys/i386/bios/smapi.c
@@ -102,16 +102,9 @@ extern int	smapi32_new(u_long, u_short,
 static int
 smapi_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
 {
-	struct smapi_softc *sc;
+	struct smapi_softc *sc = dev->si_drv1;
 	int error;
 
-	error = 0;
-	sc = devclass_get_softc(smapi_devclass, dev2unit(dev)); 
-        if (sc == NULL) {
-                error = ENXIO;
-                goto fail;
-        }
-
 	switch (cmd) {
 	case SMAPIOGHEADER:
 		bcopy((caddr_t)sc->header, data,
@@ -127,7 +120,6 @@ smapi_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct threa
 		error = ENOTTY;
 	}
 
-fail:
 	return (error);
 }
 
@@ -204,6 +196,7 @@ bad:
 static int
 smapi_attach (device_t dev)
 {
+	struct make_dev_args args;
 	struct smapi_softc *sc;
 	int error;
 
@@ -224,12 +217,17 @@ smapi_attach (device_t dev)
 					sc->header->prot32_segment +
 					sc->header->prot32_offset);
 
-        sc->cdev = make_dev(&smapi_cdevsw,
-			device_get_unit(sc->dev),
-			UID_ROOT, GID_WHEEL, 0600,
-			"%s%d",
+	make_dev_args_init(&args);
+	args.mda_devsw = &smapi_cdevsw;
+	args.mda_uid = UID_ROOT;
+	args.mda_gid = GID_WHEEL;
+	args.mda_mode = 0600;
+	args.mda_si_drv1 = sc;
+        error = make_dev_s(&args, &sc->cdev, "%s%d",
 			smapi_cdevsw.d_name,
 			device_get_unit(sc->dev));
+	if (error != 0)
+		goto bad;
 
 	device_printf(dev, "Version: %d.%02d, Length: %d, Checksum: 0x%02x\n",
 		bcd2bin(sc->header->version_major),