aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb/uvc/uvc_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/usb/uvc/uvc_driver.c')
-rw-r--r--drivers/media/usb/uvc/uvc_driver.c97
1 files changed, 49 insertions, 48 deletions
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index fd387bf3f02d..2469b49b2b30 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -216,7 +216,7 @@ static struct uvc_format_desc uvc_fmts[] = {
216 */ 216 */
217 217
218struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, 218struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
219 __u8 epaddr) 219 u8 epaddr)
220{ 220{
221 struct usb_host_endpoint *ep; 221 struct usb_host_endpoint *ep;
222 unsigned int i; 222 unsigned int i;
@@ -230,7 +230,7 @@ struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
230 return NULL; 230 return NULL;
231} 231}
232 232
233static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16]) 233static struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16])
234{ 234{
235 unsigned int len = ARRAY_SIZE(uvc_fmts); 235 unsigned int len = ARRAY_SIZE(uvc_fmts);
236 unsigned int i; 236 unsigned int i;
@@ -243,9 +243,9 @@ static struct uvc_format_desc *uvc_format_by_guid(const __u8 guid[16])
243 return NULL; 243 return NULL;
244} 244}
245 245
246static __u32 uvc_colorspace(const __u8 primaries) 246static u32 uvc_colorspace(const u8 primaries)
247{ 247{
248 static const __u8 colorprimaries[] = { 248 static const u8 colorprimaries[] = {
249 0, 249 0,
250 V4L2_COLORSPACE_SRGB, 250 V4L2_COLORSPACE_SRGB,
251 V4L2_COLORSPACE_470_SYSTEM_M, 251 V4L2_COLORSPACE_470_SYSTEM_M,
@@ -267,14 +267,14 @@ static __u32 uvc_colorspace(const __u8 primaries)
267 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold 267 * continued fraction decomposition. Using 8 and 333 for n_terms and threshold
268 * respectively seems to give nice results. 268 * respectively seems to give nice results.
269 */ 269 */
270void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator, 270void uvc_simplify_fraction(u32 *numerator, u32 *denominator,
271 unsigned int n_terms, unsigned int threshold) 271 unsigned int n_terms, unsigned int threshold)
272{ 272{
273 uint32_t *an; 273 u32 *an;
274 uint32_t x, y, r; 274 u32 x, y, r;
275 unsigned int i, n; 275 unsigned int i, n;
276 276
277 an = kmalloc(n_terms * sizeof *an, GFP_KERNEL); 277 an = kmalloc_array(n_terms, sizeof(*an), GFP_KERNEL);
278 if (an == NULL) 278 if (an == NULL)
279 return; 279 return;
280 280
@@ -318,21 +318,21 @@ void uvc_simplify_fraction(uint32_t *numerator, uint32_t *denominator,
318 * to compute numerator / denominator * 10000000 using 32 bit fixed point 318 * to compute numerator / denominator * 10000000 using 32 bit fixed point
319 * arithmetic only. 319 * arithmetic only.
320 */ 320 */
321uint32_t uvc_fraction_to_interval(uint32_t numerator, uint32_t denominator) 321u32 uvc_fraction_to_interval(u32 numerator, u32 denominator)
322{ 322{
323 uint32_t multiplier; 323 u32 multiplier;
324 324
325 /* Saturate the result if the operation would overflow. */ 325 /* Saturate the result if the operation would overflow. */
326 if (denominator == 0 || 326 if (denominator == 0 ||
327 numerator/denominator >= ((uint32_t)-1)/10000000) 327 numerator/denominator >= ((u32)-1)/10000000)
328 return (uint32_t)-1; 328 return (u32)-1;
329 329
330 /* Divide both the denominator and the multiplier by two until 330 /* Divide both the denominator and the multiplier by two until
331 * numerator * multiplier doesn't overflow. If anyone knows a better 331 * numerator * multiplier doesn't overflow. If anyone knows a better
332 * algorithm please let me know. 332 * algorithm please let me know.
333 */ 333 */
334 multiplier = 10000000; 334 multiplier = 10000000;
335 while (numerator > ((uint32_t)-1)/multiplier) { 335 while (numerator > ((u32)-1)/multiplier) {
336 multiplier /= 2; 336 multiplier /= 2;
337 denominator /= 2; 337 denominator /= 2;
338 } 338 }
@@ -391,7 +391,7 @@ static struct uvc_streaming *uvc_stream_by_id(struct uvc_device *dev, int id)
391 391
392static int uvc_parse_format(struct uvc_device *dev, 392static int uvc_parse_format(struct uvc_device *dev,
393 struct uvc_streaming *streaming, struct uvc_format *format, 393 struct uvc_streaming *streaming, struct uvc_format *format,
394 __u32 **intervals, unsigned char *buffer, int buflen) 394 u32 **intervals, unsigned char *buffer, int buflen)
395{ 395{
396 struct usb_interface *intf = streaming->intf; 396 struct usb_interface *intf = streaming->intf;
397 struct usb_host_interface *alts = intf->cur_altsetting; 397 struct usb_host_interface *alts = intf->cur_altsetting;
@@ -401,7 +401,7 @@ static int uvc_parse_format(struct uvc_device *dev,
401 unsigned int width_multiplier = 1; 401 unsigned int width_multiplier = 1;
402 unsigned int interval; 402 unsigned int interval;
403 unsigned int i, n; 403 unsigned int i, n;
404 __u8 ftype; 404 u8 ftype;
405 405
406 format->type = buffer[2]; 406 format->type = buffer[2];
407 format->index = buffer[3]; 407 format->index = buffer[3];
@@ -423,7 +423,7 @@ static int uvc_parse_format(struct uvc_device *dev,
423 423
424 if (fmtdesc != NULL) { 424 if (fmtdesc != NULL) {
425 strlcpy(format->name, fmtdesc->name, 425 strlcpy(format->name, fmtdesc->name,
426 sizeof format->name); 426 sizeof(format->name));
427 format->fcc = fmtdesc->fcc; 427 format->fcc = fmtdesc->fcc;
428 } else { 428 } else {
429 uvc_printk(KERN_INFO, "Unknown video format %pUl\n", 429 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
@@ -466,7 +466,7 @@ static int uvc_parse_format(struct uvc_device *dev,
466 return -EINVAL; 466 return -EINVAL;
467 } 467 }
468 468
469 strlcpy(format->name, "MJPEG", sizeof format->name); 469 strlcpy(format->name, "MJPEG", sizeof(format->name));
470 format->fcc = V4L2_PIX_FMT_MJPEG; 470 format->fcc = V4L2_PIX_FMT_MJPEG;
471 format->flags = UVC_FMT_FLAG_COMPRESSED; 471 format->flags = UVC_FMT_FLAG_COMPRESSED;
472 format->bpp = 0; 472 format->bpp = 0;
@@ -484,13 +484,13 @@ static int uvc_parse_format(struct uvc_device *dev,
484 484
485 switch (buffer[8] & 0x7f) { 485 switch (buffer[8] & 0x7f) {
486 case 0: 486 case 0:
487 strlcpy(format->name, "SD-DV", sizeof format->name); 487 strlcpy(format->name, "SD-DV", sizeof(format->name));
488 break; 488 break;
489 case 1: 489 case 1:
490 strlcpy(format->name, "SDL-DV", sizeof format->name); 490 strlcpy(format->name, "SDL-DV", sizeof(format->name));
491 break; 491 break;
492 case 2: 492 case 2:
493 strlcpy(format->name, "HD-DV", sizeof format->name); 493 strlcpy(format->name, "HD-DV", sizeof(format->name));
494 break; 494 break;
495 default: 495 default:
496 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming " 496 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming "
@@ -501,7 +501,7 @@ static int uvc_parse_format(struct uvc_device *dev,
501 } 501 }
502 502
503 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz", 503 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
504 sizeof format->name); 504 sizeof(format->name));
505 505
506 format->fcc = V4L2_PIX_FMT_DV; 506 format->fcc = V4L2_PIX_FMT_DV;
507 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM; 507 format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;
@@ -510,7 +510,7 @@ static int uvc_parse_format(struct uvc_device *dev,
510 510
511 /* Create a dummy frame descriptor. */ 511 /* Create a dummy frame descriptor. */
512 frame = &format->frame[0]; 512 frame = &format->frame[0];
513 memset(&format->frame[0], 0, sizeof format->frame[0]); 513 memset(&format->frame[0], 0, sizeof(format->frame[0]));
514 frame->bFrameIntervalType = 1; 514 frame->bFrameIntervalType = 1;
515 frame->dwDefaultFrameInterval = 1; 515 frame->dwDefaultFrameInterval = 1;
516 frame->dwFrameInterval = *intervals; 516 frame->dwFrameInterval = *intervals;
@@ -658,8 +658,8 @@ static int uvc_parse_streaming(struct uvc_device *dev,
658 int _buflen, buflen = alts->extralen; 658 int _buflen, buflen = alts->extralen;
659 unsigned int nformats = 0, nframes = 0, nintervals = 0; 659 unsigned int nformats = 0, nframes = 0, nintervals = 0;
660 unsigned int size, i, n, p; 660 unsigned int size, i, n, p;
661 __u32 *interval; 661 u32 *interval;
662 __u16 psize; 662 u16 psize;
663 int ret = -EINVAL; 663 int ret = -EINVAL;
664 664
665 if (intf->cur_altsetting->desc.bInterfaceSubClass 665 if (intf->cur_altsetting->desc.bInterfaceSubClass
@@ -677,7 +677,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
677 return -EINVAL; 677 return -EINVAL;
678 } 678 }
679 679
680 streaming = kzalloc(sizeof *streaming, GFP_KERNEL); 680 streaming = kzalloc(sizeof(*streaming), GFP_KERNEL);
681 if (streaming == NULL) { 681 if (streaming == NULL) {
682 usb_driver_release_interface(&uvc_driver.driver, intf); 682 usb_driver_release_interface(&uvc_driver.driver, intf);
683 return -EINVAL; 683 return -EINVAL;
@@ -827,8 +827,8 @@ static int uvc_parse_streaming(struct uvc_device *dev,
827 goto error; 827 goto error;
828 } 828 }
829 829
830 size = nformats * sizeof *format + nframes * sizeof *frame 830 size = nformats * sizeof(*format) + nframes * sizeof(*frame)
831 + nintervals * sizeof *interval; 831 + nintervals * sizeof(*interval);
832 format = kzalloc(size, GFP_KERNEL); 832 format = kzalloc(size, GFP_KERNEL);
833 if (format == NULL) { 833 if (format == NULL) {
834 ret = -ENOMEM; 834 ret = -ENOMEM;
@@ -836,7 +836,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,
836 } 836 }
837 837
838 frame = (struct uvc_frame *)&format[nformats]; 838 frame = (struct uvc_frame *)&format[nformats];
839 interval = (__u32 *)&frame[nframes]; 839 interval = (u32 *)&frame[nframes];
840 840
841 streaming->format = format; 841 streaming->format = format;
842 streaming->nformats = nformats; 842 streaming->nformats = nformats;
@@ -930,7 +930,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
930 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE; 930 entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE;
931 931
932 entity->bNrInPins = num_inputs; 932 entity->bNrInPins = num_inputs;
933 entity->baSourceID = (__u8 *)(&entity->pads[num_pads]); 933 entity->baSourceID = (u8 *)(&entity->pads[num_pads]);
934 934
935 return entity; 935 return entity;
936} 936}
@@ -995,14 +995,14 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,
995 unit->extension.bNumControls = buffer[20]; 995 unit->extension.bNumControls = buffer[20];
996 memcpy(unit->baSourceID, &buffer[22], p); 996 memcpy(unit->baSourceID, &buffer[22], p);
997 unit->extension.bControlSize = buffer[22+p]; 997 unit->extension.bControlSize = buffer[22+p];
998 unit->extension.bmControls = (__u8 *)unit + sizeof(*unit); 998 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
999 unit->extension.bmControlsType = (__u8 *)unit + sizeof(*unit) 999 unit->extension.bmControlsType = (u8 *)unit + sizeof(*unit)
1000 + n; 1000 + n;
1001 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n); 1001 memcpy(unit->extension.bmControls, &buffer[23+p], 2*n);
1002 1002
1003 if (buffer[24+p+2*n] != 0) 1003 if (buffer[24+p+2*n] != 0)
1004 usb_string(udev, buffer[24+p+2*n], unit->name, 1004 usb_string(udev, buffer[24+p+2*n], unit->name,
1005 sizeof unit->name); 1005 sizeof(unit->name));
1006 else 1006 else
1007 sprintf(unit->name, "Extension %u", buffer[3]); 1007 sprintf(unit->name, "Extension %u", buffer[3]);
1008 1008
@@ -1022,7 +1022,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1022 struct usb_interface *intf; 1022 struct usb_interface *intf;
1023 struct usb_host_interface *alts = dev->intf->cur_altsetting; 1023 struct usb_host_interface *alts = dev->intf->cur_altsetting;
1024 unsigned int i, n, p, len; 1024 unsigned int i, n, p, len;
1025 __u16 type; 1025 u16 type;
1026 1026
1027 switch (buffer[2]) { 1027 switch (buffer[2]) {
1028 case UVC_VC_HEADER: 1028 case UVC_VC_HEADER:
@@ -1101,7 +1101,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1101 1101
1102 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) { 1102 if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) {
1103 term->camera.bControlSize = n; 1103 term->camera.bControlSize = n;
1104 term->camera.bmControls = (__u8 *)term + sizeof *term; 1104 term->camera.bmControls = (u8 *)term + sizeof(*term);
1105 term->camera.wObjectiveFocalLengthMin = 1105 term->camera.wObjectiveFocalLengthMin =
1106 get_unaligned_le16(&buffer[8]); 1106 get_unaligned_le16(&buffer[8]);
1107 term->camera.wObjectiveFocalLengthMax = 1107 term->camera.wObjectiveFocalLengthMax =
@@ -1112,17 +1112,17 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1112 } else if (UVC_ENTITY_TYPE(term) == 1112 } else if (UVC_ENTITY_TYPE(term) ==
1113 UVC_ITT_MEDIA_TRANSPORT_INPUT) { 1113 UVC_ITT_MEDIA_TRANSPORT_INPUT) {
1114 term->media.bControlSize = n; 1114 term->media.bControlSize = n;
1115 term->media.bmControls = (__u8 *)term + sizeof *term; 1115 term->media.bmControls = (u8 *)term + sizeof(*term);
1116 term->media.bTransportModeSize = p; 1116 term->media.bTransportModeSize = p;
1117 term->media.bmTransportModes = (__u8 *)term 1117 term->media.bmTransportModes = (u8 *)term
1118 + sizeof *term + n; 1118 + sizeof(*term) + n;
1119 memcpy(term->media.bmControls, &buffer[9], n); 1119 memcpy(term->media.bmControls, &buffer[9], n);
1120 memcpy(term->media.bmTransportModes, &buffer[10+n], p); 1120 memcpy(term->media.bmTransportModes, &buffer[10+n], p);
1121 } 1121 }
1122 1122
1123 if (buffer[7] != 0) 1123 if (buffer[7] != 0)
1124 usb_string(udev, buffer[7], term->name, 1124 usb_string(udev, buffer[7], term->name,
1125 sizeof term->name); 1125 sizeof(term->name));
1126 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA) 1126 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_CAMERA)
1127 sprintf(term->name, "Camera %u", buffer[3]); 1127 sprintf(term->name, "Camera %u", buffer[3]);
1128 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT) 1128 else if (UVC_ENTITY_TYPE(term) == UVC_ITT_MEDIA_TRANSPORT_INPUT)
@@ -1162,7 +1162,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1162 1162
1163 if (buffer[8] != 0) 1163 if (buffer[8] != 0)
1164 usb_string(udev, buffer[8], term->name, 1164 usb_string(udev, buffer[8], term->name,
1165 sizeof term->name); 1165 sizeof(term->name));
1166 else 1166 else
1167 sprintf(term->name, "Output %u", buffer[3]); 1167 sprintf(term->name, "Output %u", buffer[3]);
1168 1168
@@ -1187,7 +1187,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1187 1187
1188 if (buffer[5+p] != 0) 1188 if (buffer[5+p] != 0)
1189 usb_string(udev, buffer[5+p], unit->name, 1189 usb_string(udev, buffer[5+p], unit->name,
1190 sizeof unit->name); 1190 sizeof(unit->name));
1191 else 1191 else
1192 sprintf(unit->name, "Selector %u", buffer[3]); 1192 sprintf(unit->name, "Selector %u", buffer[3]);
1193 1193
@@ -1213,14 +1213,14 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1213 unit->processing.wMaxMultiplier = 1213 unit->processing.wMaxMultiplier =
1214 get_unaligned_le16(&buffer[5]); 1214 get_unaligned_le16(&buffer[5]);
1215 unit->processing.bControlSize = buffer[7]; 1215 unit->processing.bControlSize = buffer[7];
1216 unit->processing.bmControls = (__u8 *)unit + sizeof *unit; 1216 unit->processing.bmControls = (u8 *)unit + sizeof(*unit);
1217 memcpy(unit->processing.bmControls, &buffer[8], n); 1217 memcpy(unit->processing.bmControls, &buffer[8], n);
1218 if (dev->uvc_version >= 0x0110) 1218 if (dev->uvc_version >= 0x0110)
1219 unit->processing.bmVideoStandards = buffer[9+n]; 1219 unit->processing.bmVideoStandards = buffer[9+n];
1220 1220
1221 if (buffer[8+n] != 0) 1221 if (buffer[8+n] != 0)
1222 usb_string(udev, buffer[8+n], unit->name, 1222 usb_string(udev, buffer[8+n], unit->name,
1223 sizeof unit->name); 1223 sizeof(unit->name));
1224 else 1224 else
1225 sprintf(unit->name, "Processing %u", buffer[3]); 1225 sprintf(unit->name, "Processing %u", buffer[3]);
1226 1226
@@ -1246,12 +1246,12 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1246 unit->extension.bNumControls = buffer[20]; 1246 unit->extension.bNumControls = buffer[20];
1247 memcpy(unit->baSourceID, &buffer[22], p); 1247 memcpy(unit->baSourceID, &buffer[22], p);
1248 unit->extension.bControlSize = buffer[22+p]; 1248 unit->extension.bControlSize = buffer[22+p];
1249 unit->extension.bmControls = (__u8 *)unit + sizeof *unit; 1249 unit->extension.bmControls = (u8 *)unit + sizeof(*unit);
1250 memcpy(unit->extension.bmControls, &buffer[23+p], n); 1250 memcpy(unit->extension.bmControls, &buffer[23+p], n);
1251 1251
1252 if (buffer[23+p+n] != 0) 1252 if (buffer[23+p+n] != 0)
1253 usb_string(udev, buffer[23+p+n], unit->name, 1253 usb_string(udev, buffer[23+p+n], unit->name,
1254 sizeof unit->name); 1254 sizeof(unit->name));
1255 else 1255 else
1256 sprintf(unit->name, "Extension %u", buffer[3]); 1256 sprintf(unit->name, "Extension %u", buffer[3]);
1257 1257
@@ -1936,7 +1936,7 @@ int uvc_register_video_device(struct uvc_device *dev,
1936 break; 1936 break;
1937 } 1937 }
1938 1938
1939 strlcpy(vdev->name, dev->name, sizeof vdev->name); 1939 strlcpy(vdev->name, dev->name, sizeof(vdev->name));
1940 1940
1941 /* 1941 /*
1942 * Set the driver data before calling video_register_device, otherwise 1942 * Set the driver data before calling video_register_device, otherwise
@@ -2070,7 +2070,8 @@ static int uvc_probe(struct usb_interface *intf,
2070 udev->devpath); 2070 udev->devpath);
2071 2071
2072 /* Allocate memory for the device and initialize it. */ 2072 /* Allocate memory for the device and initialize it. */
2073 if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL) 2073 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2074 if (dev == NULL)
2074 return -ENOMEM; 2075 return -ENOMEM;
2075 2076
2076 INIT_LIST_HEAD(&dev->entities); 2077 INIT_LIST_HEAD(&dev->entities);
@@ -2089,9 +2090,9 @@ static int uvc_probe(struct usb_interface *intf,
2089 dev->meta_format = info->meta_format; 2090 dev->meta_format = info->meta_format;
2090 2091
2091 if (udev->product != NULL) 2092 if (udev->product != NULL)
2092 strlcpy(dev->name, udev->product, sizeof dev->name); 2093 strlcpy(dev->name, udev->product, sizeof(dev->name));
2093 else 2094 else
2094 snprintf(dev->name, sizeof dev->name, 2095 snprintf(dev->name, sizeof(dev->name),
2095 "UVC Camera (%04x:%04x)", 2096 "UVC Camera (%04x:%04x)",
2096 le16_to_cpu(udev->descriptor.idVendor), 2097 le16_to_cpu(udev->descriptor.idVendor),
2097 le16_to_cpu(udev->descriptor.idProduct)); 2098 le16_to_cpu(udev->descriptor.idProduct));