Deleted Added
sdiff udiff text old ( 250204 ) new ( 250207 )
full compact
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:

--- 1245 unchanged lines hidden (view full) ---

1255 if (UGETW(d->wTotalLength) < (uint16_t)sizeof(*d)) {
1256 err = USB_ERR_INVAL;
1257 }
1258done:
1259 return (err);
1260}
1261
1262/*------------------------------------------------------------------------*
1263 * usbd_req_get_config_desc_full
1264 *
1265 * This function gets the complete USB configuration descriptor and
1266 * ensures that "wTotalLength" is correct.
1267 *
1268 * Returns:
1269 * 0: Success
1270 * Else: Failure
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 uint32_t len;
1280 usb_error_t err;
1281
1282 DPRINTFN(4, "index=%d\n", index);
1283

--- 7 unchanged lines hidden (view full) ---

1291 len = UGETW(cd.wTotalLength);
1292 if (len < (uint32_t)sizeof(*cdesc)) {
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;
1298 }
1299 cdesc = malloc(len, mtype, M_WAITOK);
1300 if (cdesc == NULL)
1301 return (USB_ERR_NOMEM);
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);
1310
1311 *ppcd = cdesc;
1312
1313 return (0); /* success */

--- 920 unchanged lines hidden ---