struct usb_device *usb;
int rc;
+ /* Mark port as attached */
+ port->attached = 1;
+
/* Sanity checks */
assert ( port->usb == NULL );
static void usb_detached ( struct usb_port *port ) {
struct usb_device *usb = port->usb;
- /* Sanity checks */
- assert ( port->usb != NULL );
+ /* Mark port as detached */
+ port->attached = 0;
+
+ /* Do nothing if we have no USB device */
+ if ( ! usb )
+ return;
/* Unregister USB device */
unregister_usb ( usb );
}
/* Handle attached/detached device as applicable */
- if ( port->speed && ! port->usb ) {
+ if ( port->speed && ! port->attached ) {
/* Newly attached device */
return usb_attached ( port );
- } else if ( port->usb && ! port->speed ) {
+ } else if ( port->attached && ! port->speed ) {
/* Newly detached device */
usb_detached ( port );
return 0;
/* Detach all devices */
for ( i = 1 ; i <= hub->ports ; i++ ) {
port = usb_port ( hub, i );
- if ( port->usb )
+ if ( port->attached )
usb_detached ( port );
}
/* Sanity checks */
for ( i = 1 ; i <= hub->ports ; i++ ) {
port = usb_port ( hub, i );
+ assert ( ! port->attached );
assert ( port->usb == NULL );
assert ( list_empty ( &port->list ) );
}
unsigned int protocol;
/** Port speed */
unsigned int speed;
- /** Currently attached device (if any) */
+ /** Port has an attached device */
+ int attached;
+ /** Currently attached device (if in use)
+ *
+ * Note that this field will be NULL if the attached device
+ * has been freed (e.g. because there were no drivers found).
+ */
struct usb_device *usb;
/** List of changed ports */
struct list_head list;