usb_request.c (248247) | usb_request.c (250204) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/usb_request.c 248247 2013-03-13 15:42:04Z hselasky $ */ | 1/* $FreeBSD: head/sys/dev/usb/usb_request.c 250204 2013-05-03 09:23:06Z hselasky $ */ |
2/*- 3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 1261 unchanged lines hidden (view full) --- 1271 *------------------------------------------------------------------------*/ 1272usb_error_t 1273usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx, 1274 struct usb_config_descriptor **ppcd, struct malloc_type *mtype, 1275 uint8_t index) 1276{ 1277 struct usb_config_descriptor cd; 1278 struct usb_config_descriptor *cdesc; | 2/*- 3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 1261 unchanged lines hidden (view full) --- 1271 *------------------------------------------------------------------------*/ 1272usb_error_t 1273usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx, 1274 struct usb_config_descriptor **ppcd, struct malloc_type *mtype, 1275 uint8_t index) 1276{ 1277 struct usb_config_descriptor cd; 1278 struct usb_config_descriptor *cdesc; |
1279 uint16_t len; | 1279 uint32_t len; |
1280 usb_error_t err; 1281 1282 DPRINTFN(4, "index=%d\n", index); 1283 1284 *ppcd = NULL; 1285 1286 err = usbd_req_get_config_desc(udev, mtx, &cd, index); | 1280 usb_error_t err; 1281 1282 DPRINTFN(4, "index=%d\n", index); 1283 1284 *ppcd = NULL; 1285 1286 err = usbd_req_get_config_desc(udev, mtx, &cd, index); |
1287 if (err) { | 1287 if (err) |
1288 return (err); | 1288 return (err); |
1289 } | 1289 |
1290 /* get full descriptor */ 1291 len = UGETW(cd.wTotalLength); | 1290 /* get full descriptor */ 1291 len = UGETW(cd.wTotalLength); |
1292 if (len < sizeof(*cdesc)) { | 1292 if (len < (uint32_t)sizeof(*cdesc)) { |
1293 /* corrupt descriptor */ 1294 return (USB_ERR_INVAL); | 1293 /* corrupt descriptor */ 1294 return (USB_ERR_INVAL); |
1295 } else if (len > USB_CONFIG_MAX) { 1296 DPRINTF("Configuration descriptor was truncated\n"); 1297 len = USB_CONFIG_MAX; |
|
1295 } 1296 cdesc = malloc(len, mtype, M_WAITOK); | 1298 } 1299 cdesc = malloc(len, mtype, M_WAITOK); |
1297 if (cdesc == NULL) { | 1300 if (cdesc == NULL) |
1298 return (USB_ERR_NOMEM); | 1301 return (USB_ERR_NOMEM); |
1299 } | |
1300 err = usbd_req_get_desc(udev, mtx, NULL, cdesc, len, len, 0, 1301 UDESC_CONFIG, index, 3); 1302 if (err) { 1303 free(cdesc, mtype); 1304 return (err); 1305 } 1306 /* make sure that the device is not fooling us: */ 1307 USETW(cdesc->wTotalLength, len); --- 924 unchanged lines hidden --- | 1302 err = usbd_req_get_desc(udev, mtx, NULL, cdesc, len, len, 0, 1303 UDESC_CONFIG, index, 3); 1304 if (err) { 1305 free(cdesc, mtype); 1306 return (err); 1307 } 1308 /* make sure that the device is not fooling us: */ 1309 USETW(cdesc->wTotalLength, len); --- 924 unchanged lines hidden --- |