Changeset 25696fea in mainline for uspace/drv/bus/usb/usbmast/main.c


Ignore:
Timestamp:
2011-10-15T20:05:00Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
22ceff3a
Parents:
1ccc32f (diff), 721d4b6e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

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

    r1ccc32f r25696fea  
    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        return EOK;
     106}
     107
    84108/** Callback when new device is attached and recognized as a mass storage.
    85109 *
     
    87111 * @return Error code.
    88112 */
    89 static int usbmast_add_device(usb_device_t *dev)
     113static int usbmast_device_add(usb_device_t *dev)
    90114{
    91115        int rc;
     
    94118
    95119        /* Allocate softstate */
    96         mdev = ddf_dev_data_alloc(dev->ddf_dev, sizeof(usbmast_dev_t));
     120        mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t));
    97121        if (mdev == NULL) {
    98122                usb_log_error("Failed allocating softstate.\n");
     
    103127        mdev->usb_dev = dev;
    104128
    105         usb_log_info("Initializing mass storage `%s'.\n",
    106             dev->ddf_dev->name);
     129        usb_log_info("Initializing mass storage `%s'.\n", dev->ddf_dev->name);
    107130        usb_log_debug(" Bulk in endpoint: %d [%zuB].\n",
    108131            dev->pipes[BULK_IN_EP].pipe->endpoint_no,
     
    113136
    114137        usb_log_debug("Get LUN count...\n");
    115         mdev->luns = usb_masstor_get_lun_count(mdev);
    116 
    117         for (i = 0; i < mdev->luns; i++) {
     138        mdev->lun_count = usb_masstor_get_lun_count(mdev);
     139        mdev->luns = calloc(mdev->lun_count, sizeof(ddf_fun_t*));
     140        if (mdev->luns == NULL) {
     141                rc = ENOMEM;
     142                usb_log_error("Failed allocating luns table.\n");
     143                goto error;
     144        }
     145
     146        for (i = 0; i < mdev->lun_count; i++) {
    118147                rc = usbmast_fun_create(mdev, i);
    119148                if (rc != EOK)
     
    123152        return EOK;
    124153error:
    125         /* XXX Destroy functions */
     154        /* Destroy functions */
     155        for (size_t i = 0; i < mdev->lun_count; ++i) {
     156                if (mdev->luns[i] == NULL)
     157                        continue;
     158                const int rc = ddf_fun_unbind(mdev->luns[i]);
     159                if (rc != EOK) {
     160                        usb_log_warning("Failed to unbind LUN function %zu: "
     161                            "%s.\n", i, str_error(rc));
     162                }
     163                ddf_fun_destroy(mdev->luns[i]);
     164        }
     165        free(mdev->luns);
    126166        return rc;
    127167}
     
    163203        }
    164204
     205        mfun->ddf_fun = fun;
    165206        mfun->mdev = mdev;
    166207        mfun->lun = lun;
     
    213254
    214255        free(fun_name);
     256        mdev->luns[lun] = fun;
    215257
    216258        return EOK;
     
    295337/** USB mass storage driver ops. */
    296338static usb_driver_ops_t usbmast_driver_ops = {
    297         .add_device = usbmast_add_device,
     339        .device_add = usbmast_device_add,
     340        .device_gone = usbmast_device_gone,
    298341};
    299342
Note: See TracChangeset for help on using the changeset viewer.