git: 5578ace4a174 - stable/13 - ugen: fix USB_IFACE_DRIVER_ACTIVE after detaching a driver

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Sat, 16 Mar 2024 15:16:36 UTC
The branch stable/13 has been updated by avg:

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

commit 5578ace4a174e6f6e4bce39f22472959cd4e745c
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2024-02-19 10:44:00 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2024-03-16 15:09:30 +0000

    ugen: fix USB_IFACE_DRIVER_ACTIVE after detaching a driver
    
    Previosuly, USB_IFACE_DRIVER_ACTIVE would report that the driver is
    active even after it detached.  That's because a device(9) still
    remains.
    
    So, add device_is_alive(9) check for more accurate reporting.
    
    Reviewed by:    markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43960
    
    (cherry picked from commit 8f374fa528d7643919bca1b4153dde03996305fe)
---
 sys/dev/usb/usb_generic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sys/dev/usb/usb_generic.c b/sys/dev/usb/usb_generic.c
index 1086e3daa0a6..6e5a00d37d4b 100644
--- a/sys/dev/usb/usb_generic.c
+++ b/sys/dev/usb/usb_generic.c
@@ -2377,12 +2377,10 @@ ugen_ioctl_post(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
 		break;
 
 	case USB_IFACE_DRIVER_ACTIVE:
-
 		n = *u.pint & 0xFF;
-
 		iface = usbd_get_iface(f->udev, n);
-
-		if (iface && iface->subdev)
+		if (iface != NULL && iface->subdev != NULL &&
+		    device_is_alive(iface->subdev))
 			error = 0;
 		else
 			error = ENXIO;