Changes in uspace/drv/bus/usb/usbmast/main.c [96fde65:065064e6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmast/main.c
r96fde65 r065064e6 82 82 void *arg); 83 83 84 /** Callback when a device is removed from the system. 85 * 86 * @param dev Representation of USB device. 87 * @return Error code. 88 */ 89 static 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 84 108 /** Callback when new device is attached and recognized as a mass storage. 85 109 * … … 94 118 95 119 /* Allocate softstate */ 96 dev->driver_data = mdev = malloc(sizeof(usbmast_dev_t));120 mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t)); 97 121 if (mdev == NULL) { 98 122 usb_log_error("Failed allocating softstate.\n"); … … 112 136 113 137 usb_log_debug("Get LUN count...\n"); 114 mdev->luns = usb_masstor_get_lun_count(mdev); 115 116 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++) { 117 147 rc = usbmast_fun_create(mdev, i); 118 148 if (rc != EOK) … … 122 152 return EOK; 123 153 error: 124 /* 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); 166 free(mdev); 125 167 return rc; 126 168 } … … 162 204 } 163 205 206 mfun->ddf_fun = fun; 164 207 mfun->mdev = mdev; 165 208 mfun->lun = lun; … … 212 255 213 256 free(fun_name); 257 mdev->luns[lun] = fun; 214 258 215 259 return EOK; … … 295 339 static usb_driver_ops_t usbmast_driver_ops = { 296 340 .device_add = usbmast_device_add, 341 .device_gone = usbmast_device_gone, 297 342 }; 298 343
Note:
See TracChangeset
for help on using the changeset viewer.