git: 98ee1305b692 - stable/14 - ugen: fix USB_IFACE_DRIVER_ACTIVE after detaching a driver

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

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

commit 98ee1305b6924675c1dc612dff5f912a5a0d84e1
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:11:37 +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
    
    (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 d8bc3a828282..c0af27d77e5d 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;