Changeset 205f0766 in mainline


Ignore:
Timestamp:
2011-10-12T19:41:53Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
90994fa
Parents:
6626bba9
Message:

usbhub: Implement device gone routine.

Fix error path.

Location:
uspace/drv/bus/usb/usbhub
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r6626bba9 r205f0766  
    8585int usb_hub_device_gone(usb_device_t *usb_dev)
    8686{
    87         return ENOTSUP;
     87        assert(usb_dev);
     88        usb_hub_dev_t *hub = usb_dev->driver_data;
     89        assert(hub);
     90        unsigned tries = 10;
     91        while (hub->running) {
     92                async_usleep(100000);
     93                if (!tries--) {
     94                        usb_log_error("Can't remove hub, still running.\n");
     95                        return EINPROGRESS;
     96                }
     97        }
     98
     99        assert(!hub->running);
     100        const int ret = ddf_fun_unbind(hub->hub_fun);
     101        if (ret != EOK) {
     102                usb_log_error("Failed to unbind '%s' function: %s.\n",
     103                   HUB_FNC_NAME, str_error(ret));
     104                return ret;
     105        }
     106        ddf_fun_destroy(hub->hub_fun);
     107        free(hub->ports);
     108        free(hub);
     109        usb_dev->driver_data = NULL;
     110        usb_log_info("USB hub driver, stopped and cleaned.\n");
     111        return EOK;
    88112}
    89113/*----------------------------------------------------------------------------*/
     
    126150        }
    127151
    128         //get port count and create attached_devs
     152        /* Get port count and create attached_devices. */
    129153        opResult = usb_hub_process_hub_specific_info(hub_info);
    130154        if (opResult != EOK) {
     
    157181            usb_hub_polling_terminated_callback, hub_info);
    158182        if (opResult != EOK) {
     183                /* Function is already bound */
     184                ddf_fun_unbind(hub_info->hub_fun);
    159185                ddf_fun_destroy(hub_info->hub_fun);
    160186                free(hub_info);
     
    163189                return opResult;
    164190        }
     191        hub_info->running = true;
    165192        usb_log_info("Controlling hub '%s' (%zu ports).\n",
    166193            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     
    225252        info->port_count = -1;
    226253        info->pending_ops_count = 0;
     254        info->running = false;
    227255        fibril_mutex_initialize(&info->pending_ops_mutex);
    228256        fibril_condvar_initialize(&info->pending_ops_cv);
     257        usb_dev->driver_data = info;
    229258
    230259        return info;
     
    489518        }
    490519        fibril_mutex_unlock(&hub->pending_ops_mutex);
    491 
    492         usb_device_destroy(hub->usb_device);
    493 
    494         free(hub->ports);
    495         free(hub);
     520        hub->running = false;
    496521}
    497522/**
  • uspace/drv/bus/usb/usbhub/usbhub.h

    r6626bba9 r205f0766  
    7575        /** Pointer to devman usbhub function. */
    7676        ddf_fun_t *hub_fun;
     77        /** Status indicator */
     78        bool running;
    7779};
    7880
Note: See TracChangeset for help on using the changeset viewer.