Changeset 3002434 in mainline


Ignore:
Timestamp:
2011-10-14T12:19:42Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc29622
Parents:
87037cc9
Message:

usbmast: Implement device_gone.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmast/main.c

    r87037cc9 r3002434  
    8282    void *arg);
    8383
     84/** Callback when a device is removed from the system.
     85 *
     86 * @param dev Representation of USB device.
     87 * @return Error code.
     88 */
     89static int usbmast_device_gone(usb_device_t *dev)
     90{
     91        usbmast_dev_t *mdev = dev->driver_data;
     92        assert(mdev);
     93
     94        for (size_t i = 0; i < mdev->lun_count; ++i) {
     95                const int rc = ddf_fun_unbind(mdev->luns[i]);
     96                if (rc != EOK) {
     97                        usb_log_error("Failed to unbind LUN function %zu: "
     98                            "%s\n", i, str_error(rc));
     99                        return rc;
     100                }
     101                ddf_fun_destroy(mdev->luns[i]);
     102                mdev->luns[i] = NULL;
     103        }
     104        free(mdev->luns);
     105        free(mdev);
     106        return EOK;
     107}
     108
    84109/** Callback when new device is attached and recognized as a mass storage.
    85110 *
     
    128153        return EOK;
    129154error:
    130         /* XXX Destroy functions */
     155        /* Destroy functions */
     156        for (size_t i = 0; i < mdev->lun_count; ++i) {
     157                if (mdev->luns[i] == NULL)
     158                        continue;
     159                const int rc = ddf_fun_unbind(mdev->luns[i]);
     160                if (rc != EOK) {
     161                        usb_log_warning("Failed to unbind LUN function %zu: "
     162                            "%s.\n", i, str_error(rc));
     163                }
     164                ddf_fun_destroy(mdev->luns[i]);
     165        }
     166        free(mdev->luns);
     167        free(mdev);
    131168        return rc;
    132169}
     
    303340static usb_driver_ops_t usbmast_driver_ops = {
    304341        .device_add = usbmast_device_add,
     342        .device_gone = usbmast_device_gone,
    305343};
    306344
Note: See TracChangeset for help on using the changeset viewer.