config.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. #include <linux/usb.h>
  2. #include <linux/usb/ch9.h>
  3. #include <linux/module.h>
  4. #include <linux/init.h>
  5. #include <linux/slab.h>
  6. #include <linux/device.h>
  7. #include <asm/byteorder.h>
  8. #include "usb.h"
  9. #include "hcd.h"
  10. #define USB_MAXALTSETTING 128 /* Hard limit */
  11. #define USB_MAXENDPOINTS 30 /* Hard limit */
  12. #define USB_MAXCONFIG 8 /* Arbitrary limit */
  13. static inline const char *plural(int n)
  14. {
  15. return (n == 1 ? "" : "s");
  16. }
  17. static int find_next_descriptor(unsigned char *buffer, int size,
  18. int dt1, int dt2, int *num_skipped)
  19. {
  20. struct usb_descriptor_header *h;
  21. int n = 0;
  22. unsigned char *buffer0 = buffer;
  23. /* Find the next descriptor of type dt1 or dt2 */
  24. while (size > 0) {
  25. h = (struct usb_descriptor_header *) buffer;
  26. if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2)
  27. break;
  28. buffer += h->bLength;
  29. size -= h->bLength;
  30. ++n;
  31. }
  32. /* Store the number of descriptors skipped and return the
  33. * number of bytes skipped */
  34. if (num_skipped)
  35. *num_skipped = n;
  36. return buffer - buffer0;
  37. }
  38. static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
  39. int asnum, struct usb_host_interface *ifp, int num_ep,
  40. unsigned char *buffer, int size)
  41. {
  42. unsigned char *buffer0 = buffer;
  43. struct usb_endpoint_descriptor *d;
  44. struct usb_host_endpoint *endpoint;
  45. int n, i, j;
  46. d = (struct usb_endpoint_descriptor *) buffer;
  47. buffer += d->bLength;
  48. size -= d->bLength;
  49. if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE)
  50. n = USB_DT_ENDPOINT_AUDIO_SIZE;
  51. else if (d->bLength >= USB_DT_ENDPOINT_SIZE)
  52. n = USB_DT_ENDPOINT_SIZE;
  53. else {
  54. dev_warn(ddev, "config %d interface %d altsetting %d has an "
  55. "invalid endpoint descriptor of length %d, skipping\n",
  56. cfgno, inum, asnum, d->bLength);
  57. goto skip_to_next_endpoint_or_interface_descriptor;
  58. }
  59. i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK;
  60. if (i >= 16 || i == 0) {
  61. dev_warn(ddev, "config %d interface %d altsetting %d has an "
  62. "invalid endpoint with address 0x%X, skipping\n",
  63. cfgno, inum, asnum, d->bEndpointAddress);
  64. goto skip_to_next_endpoint_or_interface_descriptor;
  65. }
  66. /* Only store as many endpoints as we have room for */
  67. if (ifp->desc.bNumEndpoints >= num_ep)
  68. goto skip_to_next_endpoint_or_interface_descriptor;
  69. endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints];
  70. ++ifp->desc.bNumEndpoints;
  71. memcpy(&endpoint->desc, d, n);
  72. INIT_LIST_HEAD(&endpoint->urb_list);
  73. /* Fix up bInterval values outside the legal range. Use 32 ms if no
  74. * proper value can be guessed. */
  75. i = 0; /* i = min, j = max, n = default */
  76. j = 255;
  77. if (usb_endpoint_xfer_int(d)) {
  78. i = 1;
  79. switch (to_usb_device(ddev)->speed) {
  80. case USB_SPEED_HIGH:
  81. /* Many device manufacturers are using full-speed
  82. * bInterval values in high-speed interrupt endpoint
  83. * descriptors. Try to fix those and fall back to a
  84. * 32 ms default value otherwise. */
  85. n = fls(d->bInterval*8);
  86. if (n == 0)
  87. n = 9; /* 32 ms = 2^(9-1) uframes */
  88. j = 16;
  89. break;
  90. default: /* USB_SPEED_FULL or _LOW */
  91. /* For low-speed, 10 ms is the official minimum.
  92. * But some "overclocked" devices might want faster
  93. * polling so we'll allow it. */
  94. n = 32;
  95. break;
  96. }
  97. } else if (usb_endpoint_xfer_isoc(d)) {
  98. i = 1;
  99. j = 16;
  100. switch (to_usb_device(ddev)->speed) {
  101. case USB_SPEED_HIGH:
  102. n = 9; /* 32 ms = 2^(9-1) uframes */
  103. break;
  104. default: /* USB_SPEED_FULL */
  105. n = 6; /* 32 ms = 2^(6-1) frames */
  106. break;
  107. }
  108. }
  109. if (d->bInterval < i || d->bInterval > j) {
  110. dev_warn(ddev, "config %d interface %d altsetting %d "
  111. "endpoint 0x%X has an invalid bInterval %d, "
  112. "changing to %d\n",
  113. cfgno, inum, asnum,
  114. d->bEndpointAddress, d->bInterval, n);
  115. endpoint->desc.bInterval = n;
  116. }
  117. /* Some buggy low-speed devices have Bulk endpoints, which is
  118. * explicitly forbidden by the USB spec. In an attempt to make
  119. * them usable, we will try treating them as Interrupt endpoints.
  120. */
  121. if (to_usb_device(ddev)->speed == USB_SPEED_LOW &&
  122. usb_endpoint_xfer_bulk(d)) {
  123. dev_warn(ddev, "config %d interface %d altsetting %d "
  124. "endpoint 0x%X is Bulk; changing to Interrupt\n",
  125. cfgno, inum, asnum, d->bEndpointAddress);
  126. endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;
  127. endpoint->desc.bInterval = 1;
  128. if (le16_to_cpu(endpoint->desc.wMaxPacketSize) > 8)
  129. endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
  130. }
  131. /* Skip over any Class Specific or Vendor Specific descriptors;
  132. * find the next endpoint or interface descriptor */
  133. endpoint->extra = buffer;
  134. i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
  135. USB_DT_INTERFACE, &n);
  136. endpoint->extralen = i;
  137. if (n > 0)
  138. dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
  139. n, plural(n), "endpoint");
  140. return buffer - buffer0 + i;
  141. skip_to_next_endpoint_or_interface_descriptor:
  142. i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
  143. USB_DT_INTERFACE, NULL);
  144. return buffer - buffer0 + i;
  145. }
  146. void usb_release_interface_cache(struct kref *ref)
  147. {
  148. struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref);
  149. int j;
  150. for (j = 0; j < intfc->num_altsetting; j++) {
  151. struct usb_host_interface *alt = &intfc->altsetting[j];
  152. kfree(alt->endpoint);
  153. kfree(alt->string);
  154. }
  155. kfree(intfc);
  156. }
  157. static int usb_parse_interface(struct device *ddev, int cfgno,
  158. struct usb_host_config *config, unsigned char *buffer, int size,
  159. u8 inums[], u8 nalts[])
  160. {
  161. unsigned char *buffer0 = buffer;
  162. struct usb_interface_descriptor *d;
  163. int inum, asnum;
  164. struct usb_interface_cache *intfc;
  165. struct usb_host_interface *alt;
  166. int i, n;
  167. int len, retval;
  168. int num_ep, num_ep_orig;
  169. d = (struct usb_interface_descriptor *) buffer;
  170. buffer += d->bLength;
  171. size -= d->bLength;
  172. if (d->bLength < USB_DT_INTERFACE_SIZE)
  173. goto skip_to_next_interface_descriptor;
  174. /* Which interface entry is this? */
  175. intfc = NULL;
  176. inum = d->bInterfaceNumber;
  177. for (i = 0; i < config->desc.bNumInterfaces; ++i) {
  178. if (inums[i] == inum) {
  179. intfc = config->intf_cache[i];
  180. break;
  181. }
  182. }
  183. if (!intfc || intfc->num_altsetting >= nalts[i])
  184. goto skip_to_next_interface_descriptor;
  185. /* Check for duplicate altsetting entries */
  186. asnum = d->bAlternateSetting;
  187. for ((i = 0, alt = &intfc->altsetting[0]);
  188. i < intfc->num_altsetting;
  189. (++i, ++alt)) {
  190. if (alt->desc.bAlternateSetting == asnum) {
  191. dev_warn(ddev, "Duplicate descriptor for config %d "
  192. "interface %d altsetting %d, skipping\n",
  193. cfgno, inum, asnum);
  194. goto skip_to_next_interface_descriptor;
  195. }
  196. }
  197. ++intfc->num_altsetting;
  198. memcpy(&alt->desc, d, USB_DT_INTERFACE_SIZE);
  199. /* Skip over any Class Specific or Vendor Specific descriptors;
  200. * find the first endpoint or interface descriptor */
  201. alt->extra = buffer;
  202. i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
  203. USB_DT_INTERFACE, &n);
  204. alt->extralen = i;
  205. if (n > 0)
  206. dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
  207. n, plural(n), "interface");
  208. buffer += i;
  209. size -= i;
  210. /* Allocate space for the right(?) number of endpoints */
  211. num_ep = num_ep_orig = alt->desc.bNumEndpoints;
  212. alt->desc.bNumEndpoints = 0; /* Use as a counter */
  213. if (num_ep > USB_MAXENDPOINTS) {
  214. dev_warn(ddev, "too many endpoints for config %d interface %d "
  215. "altsetting %d: %d, using maximum allowed: %d\n",
  216. cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS);
  217. num_ep = USB_MAXENDPOINTS;
  218. }
  219. if (num_ep > 0) {
  220. /* Can't allocate 0 bytes */
  221. len = sizeof(struct usb_host_endpoint) * num_ep;
  222. alt->endpoint = kzalloc(len, GFP_KERNEL);
  223. if (!alt->endpoint)
  224. return -ENOMEM;
  225. }
  226. /* Parse all the endpoint descriptors */
  227. n = 0;
  228. while (size > 0) {
  229. if (((struct usb_descriptor_header *) buffer)->bDescriptorType
  230. == USB_DT_INTERFACE)
  231. break;
  232. retval = usb_parse_endpoint(ddev, cfgno, inum, asnum, alt,
  233. num_ep, buffer, size);
  234. if (retval < 0)
  235. return retval;
  236. ++n;
  237. buffer += retval;
  238. size -= retval;
  239. }
  240. if (n != num_ep_orig)
  241. dev_warn(ddev, "config %d interface %d altsetting %d has %d "
  242. "endpoint descriptor%s, different from the interface "
  243. "descriptor's value: %d\n",
  244. cfgno, inum, asnum, n, plural(n), num_ep_orig);
  245. return buffer - buffer0;
  246. skip_to_next_interface_descriptor:
  247. i = find_next_descriptor(buffer, size, USB_DT_INTERFACE,
  248. USB_DT_INTERFACE, NULL);
  249. return buffer - buffer0 + i;
  250. }
  251. static int usb_parse_configuration(struct device *ddev, int cfgidx,
  252. struct usb_host_config *config, unsigned char *buffer, int size)
  253. {
  254. unsigned char *buffer0 = buffer;
  255. int cfgno;
  256. int nintf, nintf_orig;
  257. int i, j, n;
  258. struct usb_interface_cache *intfc;
  259. unsigned char *buffer2;
  260. int size2;
  261. struct usb_descriptor_header *header;
  262. int len, retval;
  263. u8 inums[USB_MAXINTERFACES], nalts[USB_MAXINTERFACES];
  264. unsigned iad_num = 0;
  265. memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
  266. if (config->desc.bDescriptorType != USB_DT_CONFIG ||
  267. config->desc.bLength < USB_DT_CONFIG_SIZE) {
  268. dev_err(ddev, "invalid descriptor for config index %d: "
  269. "type = 0x%X, length = %d\n", cfgidx,
  270. config->desc.bDescriptorType, config->desc.bLength);
  271. return -EINVAL;
  272. }
  273. cfgno = config->desc.bConfigurationValue;
  274. buffer += config->desc.bLength;
  275. size -= config->desc.bLength;
  276. nintf = nintf_orig = config->desc.bNumInterfaces;
  277. if (nintf > USB_MAXINTERFACES) {
  278. dev_warn(ddev, "config %d has too many interfaces: %d, "
  279. "using maximum allowed: %d\n",
  280. cfgno, nintf, USB_MAXINTERFACES);
  281. nintf = USB_MAXINTERFACES;
  282. }
  283. /* Go through the descriptors, checking their length and counting the
  284. * number of altsettings for each interface */
  285. n = 0;
  286. for ((buffer2 = buffer, size2 = size);
  287. size2 > 0;
  288. (buffer2 += header->bLength, size2 -= header->bLength)) {
  289. if (size2 < sizeof(struct usb_descriptor_header)) {
  290. dev_warn(ddev, "config %d descriptor has %d excess "
  291. "byte%s, ignoring\n",
  292. cfgno, size2, plural(size2));
  293. break;
  294. }
  295. header = (struct usb_descriptor_header *) buffer2;
  296. if ((header->bLength > size2) || (header->bLength < 2)) {
  297. dev_warn(ddev, "config %d has an invalid descriptor "
  298. "of length %d, skipping remainder of the config\n",
  299. cfgno, header->bLength);
  300. break;
  301. }
  302. if (header->bDescriptorType == USB_DT_INTERFACE) {
  303. struct usb_interface_descriptor *d;
  304. int inum;
  305. d = (struct usb_interface_descriptor *) header;
  306. if (d->bLength < USB_DT_INTERFACE_SIZE) {
  307. dev_warn(ddev, "config %d has an invalid "
  308. "interface descriptor of length %d, "
  309. "skipping\n", cfgno, d->bLength);
  310. continue;
  311. }
  312. inum = d->bInterfaceNumber;
  313. if (inum >= nintf_orig)
  314. dev_warn(ddev, "config %d has an invalid "
  315. "interface number: %d but max is %d\n",
  316. cfgno, inum, nintf_orig - 1);
  317. /* Have we already encountered this interface?
  318. * Count its altsettings */
  319. for (i = 0; i < n; ++i) {
  320. if (inums[i] == inum)
  321. break;
  322. }
  323. if (i < n) {
  324. if (nalts[i] < 255)
  325. ++nalts[i];
  326. } else if (n < USB_MAXINTERFACES) {
  327. inums[n] = inum;
  328. nalts[n] = 1;
  329. ++n;
  330. }
  331. } else if (header->bDescriptorType ==
  332. USB_DT_INTERFACE_ASSOCIATION) {
  333. if (iad_num == USB_MAXIADS) {
  334. dev_warn(ddev, "found more Interface "
  335. "Association Descriptors "
  336. "than allocated for in "
  337. "configuration %d\n", cfgno);
  338. } else {
  339. config->intf_assoc[iad_num] =
  340. (struct usb_interface_assoc_descriptor
  341. *)header;
  342. iad_num++;
  343. }
  344. } else if (header->bDescriptorType == USB_DT_DEVICE ||
  345. header->bDescriptorType == USB_DT_CONFIG)
  346. dev_warn(ddev, "config %d contains an unexpected "
  347. "descriptor of type 0x%X, skipping\n",
  348. cfgno, header->bDescriptorType);
  349. } /* for ((buffer2 = buffer, size2 = size); ...) */
  350. size = buffer2 - buffer;
  351. config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0);
  352. if (n != nintf)
  353. dev_warn(ddev, "config %d has %d interface%s, different from "
  354. "the descriptor's value: %d\n",
  355. cfgno, n, plural(n), nintf_orig);
  356. else if (n == 0)
  357. dev_warn(ddev, "config %d has no interfaces?\n", cfgno);
  358. config->desc.bNumInterfaces = nintf = n;
  359. /* Check for missing interface numbers */
  360. for (i = 0; i < nintf; ++i) {
  361. for (j = 0; j < nintf; ++j) {
  362. if (inums[j] == i)
  363. break;
  364. }
  365. if (j >= nintf)
  366. dev_warn(ddev, "config %d has no interface number "
  367. "%d\n", cfgno, i);
  368. }
  369. /* Allocate the usb_interface_caches and altsetting arrays */
  370. for (i = 0; i < nintf; ++i) {
  371. j = nalts[i];
  372. if (j > USB_MAXALTSETTING) {
  373. dev_warn(ddev, "too many alternate settings for "
  374. "config %d interface %d: %d, "
  375. "using maximum allowed: %d\n",
  376. cfgno, inums[i], j, USB_MAXALTSETTING);
  377. nalts[i] = j = USB_MAXALTSETTING;
  378. }
  379. len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
  380. config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
  381. if (!intfc)
  382. return -ENOMEM;
  383. kref_init(&intfc->ref);
  384. }
  385. /* Skip over any Class Specific or Vendor Specific descriptors;
  386. * find the first interface descriptor */
  387. config->extra = buffer;
  388. i = find_next_descriptor(buffer, size, USB_DT_INTERFACE,
  389. USB_DT_INTERFACE, &n);
  390. config->extralen = i;
  391. if (n > 0)
  392. dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
  393. n, plural(n), "configuration");
  394. buffer += i;
  395. size -= i;
  396. /* Parse all the interface/altsetting descriptors */
  397. while (size > 0) {
  398. retval = usb_parse_interface(ddev, cfgno, config,
  399. buffer, size, inums, nalts);
  400. if (retval < 0)
  401. return retval;
  402. buffer += retval;
  403. size -= retval;
  404. }
  405. /* Check for missing altsettings */
  406. for (i = 0; i < nintf; ++i) {
  407. intfc = config->intf_cache[i];
  408. for (j = 0; j < intfc->num_altsetting; ++j) {
  409. for (n = 0; n < intfc->num_altsetting; ++n) {
  410. if (intfc->altsetting[n].desc.
  411. bAlternateSetting == j)
  412. break;
  413. }
  414. if (n >= intfc->num_altsetting)
  415. dev_warn(ddev, "config %d interface %d has no "
  416. "altsetting %d\n", cfgno, inums[i], j);
  417. }
  418. }
  419. return 0;
  420. }
  421. /* hub-only!! ... and only exported for reset/reinit path.
  422. * otherwise used internally on disconnect/destroy path
  423. */
  424. void usb_destroy_configuration(struct usb_device *dev)
  425. {
  426. int c, i;
  427. if (!dev->config)
  428. return;
  429. if (dev->rawdescriptors) {
  430. for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
  431. kfree(dev->rawdescriptors[i]);
  432. kfree(dev->rawdescriptors);
  433. dev->rawdescriptors = NULL;
  434. }
  435. for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
  436. struct usb_host_config *cf = &dev->config[c];
  437. kfree(cf->string);
  438. for (i = 0; i < cf->desc.bNumInterfaces; i++) {
  439. if (cf->intf_cache[i])
  440. kref_put(&cf->intf_cache[i]->ref,
  441. usb_release_interface_cache);
  442. }
  443. }
  444. kfree(dev->config);
  445. dev->config = NULL;
  446. }
  447. /*
  448. * Get the USB config descriptors, cache and parse'em
  449. *
  450. * hub-only!! ... and only in reset path, or usb_new_device()
  451. * (used by real hubs and virtual root hubs)
  452. *
  453. * NOTE: if this is a WUSB device and is not authorized, we skip the
  454. * whole thing. A non-authorized USB device has no
  455. * configurations.
  456. */
  457. int usb_get_configuration(struct usb_device *dev)
  458. {
  459. struct device *ddev = &dev->dev;
  460. int ncfg = dev->descriptor.bNumConfigurations;
  461. int result = 0;
  462. unsigned int cfgno, length;
  463. unsigned char *buffer;
  464. unsigned char *bigbuffer;
  465. struct usb_config_descriptor *desc;
  466. cfgno = 0;
  467. if (dev->authorized == 0) /* Not really an error */
  468. goto out_not_authorized;
  469. result = -ENOMEM;
  470. if (ncfg > USB_MAXCONFIG) {
  471. dev_warn(ddev, "too many configurations: %d, "
  472. "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
  473. dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
  474. }
  475. if (ncfg < 1) {
  476. dev_err(ddev, "no configurations\n");
  477. return -EINVAL;
  478. }
  479. length = ncfg * sizeof(struct usb_host_config);
  480. dev->config = kzalloc(length, GFP_KERNEL);
  481. if (!dev->config)
  482. goto err2;
  483. length = ncfg * sizeof(char *);
  484. dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
  485. if (!dev->rawdescriptors)
  486. goto err2;
  487. buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
  488. if (!buffer)
  489. goto err2;
  490. desc = (struct usb_config_descriptor *)buffer;
  491. result = 0;
  492. for (; cfgno < ncfg; cfgno++) {
  493. /* We grab just the first descriptor so we know how long
  494. * the whole configuration is */
  495. result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
  496. buffer, USB_DT_CONFIG_SIZE);
  497. if (result < 0) {
  498. dev_err(ddev, "unable to read config index %d "
  499. "descriptor/%s: %d\n", cfgno, "start", result);
  500. dev_err(ddev, "chopping to %d config(s)\n", cfgno);
  501. dev->descriptor.bNumConfigurations = cfgno;
  502. break;
  503. } else if (result < 4) {
  504. dev_err(ddev, "config index %d descriptor too short "
  505. "(expected %i, got %i)\n", cfgno,
  506. USB_DT_CONFIG_SIZE, result);
  507. result = -EINVAL;
  508. goto err;
  509. }
  510. length = max((int) le16_to_cpu(desc->wTotalLength),
  511. USB_DT_CONFIG_SIZE);
  512. /* Now that we know the length, get the whole thing */
  513. bigbuffer = kmalloc(length, GFP_KERNEL);
  514. if (!bigbuffer) {
  515. result = -ENOMEM;
  516. goto err;
  517. }
  518. result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
  519. bigbuffer, length);
  520. if (result < 0) {
  521. dev_err(ddev, "unable to read config index %d "
  522. "descriptor/%s\n", cfgno, "all");
  523. kfree(bigbuffer);
  524. goto err;
  525. }
  526. if (result < length) {
  527. dev_warn(ddev, "config index %d descriptor too short "
  528. "(expected %i, got %i)\n", cfgno, length, result);
  529. length = result;
  530. }
  531. dev->rawdescriptors[cfgno] = bigbuffer;
  532. result = usb_parse_configuration(&dev->dev, cfgno,
  533. &dev->config[cfgno], bigbuffer, length);
  534. if (result < 0) {
  535. ++cfgno;
  536. goto err;
  537. }
  538. }
  539. result = 0;
  540. err:
  541. kfree(buffer);
  542. out_not_authorized:
  543. dev->descriptor.bNumConfigurations = cfgno;
  544. err2:
  545. if (result == -ENOMEM)
  546. dev_err(ddev, "out of memory\n");
  547. return result;
  548. }