diff options
author | Michael Hennerich <michael.hennerich@analog.com> | 2008-11-11 12:11:28 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-29 14:53:36 -0500 |
commit | 9bc6218dc1dc7bd421f3d141241c8e0e70c4e92b (patch) | |
tree | a8c54009c879e94c19e4e2e89a65dda001607181 /drivers/media/video/uvc | |
parent | 4d3939f6eecb1c3330a34e0bc95a6b8529207b88 (diff) |
V4L/DVB (9660): uvcvideo: Fix unaligned memory access.
Use the unaligned memory access macros when accessing unaligned memory.
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Bryan Wu <cooloney@kernel.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/uvc')
-rw-r--r-- | drivers/media/video/uvc/uvc_driver.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c index 1e3b4fe5ae93..7fe3ae954c19 100644 --- a/drivers/media/video/uvc/uvc_driver.c +++ b/drivers/media/video/uvc/uvc_driver.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/vmalloc.h> | 32 | #include <linux/vmalloc.h> |
33 | #include <linux/wait.h> | 33 | #include <linux/wait.h> |
34 | #include <asm/atomic.h> | 34 | #include <asm/atomic.h> |
35 | #include <asm/unaligned.h> | ||
35 | 36 | ||
36 | #include <media/v4l2-common.h> | 37 | #include <media/v4l2-common.h> |
37 | 38 | ||
@@ -452,20 +453,20 @@ static int uvc_parse_format(struct uvc_device *dev, | |||
452 | 453 | ||
453 | frame->bFrameIndex = buffer[3]; | 454 | frame->bFrameIndex = buffer[3]; |
454 | frame->bmCapabilities = buffer[4]; | 455 | frame->bmCapabilities = buffer[4]; |
455 | frame->wWidth = le16_to_cpup((__le16 *)&buffer[5]); | 456 | frame->wWidth = get_unaligned_le16(&buffer[5]); |
456 | frame->wHeight = le16_to_cpup((__le16 *)&buffer[7]); | 457 | frame->wHeight = get_unaligned_le16(&buffer[7]); |
457 | frame->dwMinBitRate = le32_to_cpup((__le32 *)&buffer[9]); | 458 | frame->dwMinBitRate = get_unaligned_le32(&buffer[9]); |
458 | frame->dwMaxBitRate = le32_to_cpup((__le32 *)&buffer[13]); | 459 | frame->dwMaxBitRate = get_unaligned_le32(&buffer[13]); |
459 | if (ftype != VS_FRAME_FRAME_BASED) { | 460 | if (ftype != VS_FRAME_FRAME_BASED) { |
460 | frame->dwMaxVideoFrameBufferSize = | 461 | frame->dwMaxVideoFrameBufferSize = |
461 | le32_to_cpup((__le32 *)&buffer[17]); | 462 | get_unaligned_le32(&buffer[17]); |
462 | frame->dwDefaultFrameInterval = | 463 | frame->dwDefaultFrameInterval = |
463 | le32_to_cpup((__le32 *)&buffer[21]); | 464 | get_unaligned_le32(&buffer[21]); |
464 | frame->bFrameIntervalType = buffer[25]; | 465 | frame->bFrameIntervalType = buffer[25]; |
465 | } else { | 466 | } else { |
466 | frame->dwMaxVideoFrameBufferSize = 0; | 467 | frame->dwMaxVideoFrameBufferSize = 0; |
467 | frame->dwDefaultFrameInterval = | 468 | frame->dwDefaultFrameInterval = |
468 | le32_to_cpup((__le32 *)&buffer[17]); | 469 | get_unaligned_le32(&buffer[17]); |
469 | frame->bFrameIntervalType = buffer[21]; | 470 | frame->bFrameIntervalType = buffer[21]; |
470 | } | 471 | } |
471 | frame->dwFrameInterval = *intervals; | 472 | frame->dwFrameInterval = *intervals; |
@@ -488,7 +489,7 @@ static int uvc_parse_format(struct uvc_device *dev, | |||
488 | * some other divisions by zero which could happen. | 489 | * some other divisions by zero which could happen. |
489 | */ | 490 | */ |
490 | for (i = 0; i < n; ++i) { | 491 | for (i = 0; i < n; ++i) { |
491 | interval = le32_to_cpup((__le32 *)&buffer[26+4*i]); | 492 | interval = get_unaligned_le32(&buffer[26+4*i]); |
492 | *(*intervals)++ = interval ? interval : 1; | 493 | *(*intervals)++ = interval ? interval : 1; |
493 | } | 494 | } |
494 | 495 | ||
@@ -832,8 +833,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, | |||
832 | unit->type = VC_EXTENSION_UNIT; | 833 | unit->type = VC_EXTENSION_UNIT; |
833 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); | 834 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); |
834 | unit->extension.bNumControls = buffer[20]; | 835 | unit->extension.bNumControls = buffer[20]; |
835 | unit->extension.bNrInPins = | 836 | unit->extension.bNrInPins = get_unaligned_le16(&buffer[21]); |
836 | le16_to_cpup((__le16 *)&buffer[21]); | ||
837 | unit->extension.baSourceID = (__u8 *)unit + sizeof *unit; | 837 | unit->extension.baSourceID = (__u8 *)unit + sizeof *unit; |
838 | memcpy(unit->extension.baSourceID, &buffer[22], p); | 838 | memcpy(unit->extension.baSourceID, &buffer[22], p); |
839 | unit->extension.bControlSize = buffer[22+p]; | 839 | unit->extension.bControlSize = buffer[22+p]; |
@@ -877,8 +877,8 @@ static int uvc_parse_standard_control(struct uvc_device *dev, | |||
877 | return -EINVAL; | 877 | return -EINVAL; |
878 | } | 878 | } |
879 | 879 | ||
880 | dev->uvc_version = le16_to_cpup((__le16 *)&buffer[3]); | 880 | dev->uvc_version = get_unaligned_le16(&buffer[3]); |
881 | dev->clock_frequency = le32_to_cpup((__le32 *)&buffer[7]); | 881 | dev->clock_frequency = get_unaligned_le32(&buffer[7]); |
882 | 882 | ||
883 | /* Parse all USB Video Streaming interfaces. */ | 883 | /* Parse all USB Video Streaming interfaces. */ |
884 | for (i = 0; i < n; ++i) { | 884 | for (i = 0; i < n; ++i) { |
@@ -905,7 +905,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, | |||
905 | /* Make sure the terminal type MSB is not null, otherwise it | 905 | /* Make sure the terminal type MSB is not null, otherwise it |
906 | * could be confused with a unit. | 906 | * could be confused with a unit. |
907 | */ | 907 | */ |
908 | type = le16_to_cpup((__le16 *)&buffer[4]); | 908 | type = get_unaligned_le16(&buffer[4]); |
909 | if ((type & 0xff00) == 0) { | 909 | if ((type & 0xff00) == 0) { |
910 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | 910 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " |
911 | "interface %d INPUT_TERMINAL %d has invalid " | 911 | "interface %d INPUT_TERMINAL %d has invalid " |
@@ -947,11 +947,11 @@ static int uvc_parse_standard_control(struct uvc_device *dev, | |||
947 | term->camera.bControlSize = n; | 947 | term->camera.bControlSize = n; |
948 | term->camera.bmControls = (__u8 *)term + sizeof *term; | 948 | term->camera.bmControls = (__u8 *)term + sizeof *term; |
949 | term->camera.wObjectiveFocalLengthMin = | 949 | term->camera.wObjectiveFocalLengthMin = |
950 | le16_to_cpup((__le16 *)&buffer[8]); | 950 | get_unaligned_le16(&buffer[8]); |
951 | term->camera.wObjectiveFocalLengthMax = | 951 | term->camera.wObjectiveFocalLengthMax = |
952 | le16_to_cpup((__le16 *)&buffer[10]); | 952 | get_unaligned_le16(&buffer[10]); |
953 | term->camera.wOcularFocalLength = | 953 | term->camera.wOcularFocalLength = |
954 | le16_to_cpup((__le16 *)&buffer[12]); | 954 | get_unaligned_le16(&buffer[12]); |
955 | memcpy(term->camera.bmControls, &buffer[15], n); | 955 | memcpy(term->camera.bmControls, &buffer[15], n); |
956 | } else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) { | 956 | } else if (UVC_ENTITY_TYPE(term) == ITT_MEDIA_TRANSPORT_INPUT) { |
957 | term->media.bControlSize = n; | 957 | term->media.bControlSize = n; |
@@ -987,7 +987,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, | |||
987 | /* Make sure the terminal type MSB is not null, otherwise it | 987 | /* Make sure the terminal type MSB is not null, otherwise it |
988 | * could be confused with a unit. | 988 | * could be confused with a unit. |
989 | */ | 989 | */ |
990 | type = le16_to_cpup((__le16 *)&buffer[4]); | 990 | type = get_unaligned_le16(&buffer[4]); |
991 | if ((type & 0xff00) == 0) { | 991 | if ((type & 0xff00) == 0) { |
992 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " | 992 | uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol " |
993 | "interface %d OUTPUT_TERMINAL %d has invalid " | 993 | "interface %d OUTPUT_TERMINAL %d has invalid " |
@@ -1061,7 +1061,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, | |||
1061 | unit->type = buffer[2]; | 1061 | unit->type = buffer[2]; |
1062 | unit->processing.bSourceID = buffer[4]; | 1062 | unit->processing.bSourceID = buffer[4]; |
1063 | unit->processing.wMaxMultiplier = | 1063 | unit->processing.wMaxMultiplier = |
1064 | le16_to_cpup((__le16 *)&buffer[5]); | 1064 | get_unaligned_le16(&buffer[5]); |
1065 | unit->processing.bControlSize = buffer[7]; | 1065 | unit->processing.bControlSize = buffer[7]; |
1066 | unit->processing.bmControls = (__u8 *)unit + sizeof *unit; | 1066 | unit->processing.bmControls = (__u8 *)unit + sizeof *unit; |
1067 | memcpy(unit->processing.bmControls, &buffer[8], n); | 1067 | memcpy(unit->processing.bmControls, &buffer[8], n); |
@@ -1096,8 +1096,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, | |||
1096 | unit->type = buffer[2]; | 1096 | unit->type = buffer[2]; |
1097 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); | 1097 | memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); |
1098 | unit->extension.bNumControls = buffer[20]; | 1098 | unit->extension.bNumControls = buffer[20]; |
1099 | unit->extension.bNrInPins = | 1099 | unit->extension.bNrInPins = get_unaligned_le16(&buffer[21]); |
1100 | le16_to_cpup((__le16 *)&buffer[21]); | ||
1101 | unit->extension.baSourceID = (__u8 *)unit + sizeof *unit; | 1100 | unit->extension.baSourceID = (__u8 *)unit + sizeof *unit; |
1102 | memcpy(unit->extension.baSourceID, &buffer[22], p); | 1101 | memcpy(unit->extension.baSourceID, &buffer[22], p); |
1103 | unit->extension.bControlSize = buffer[22+p]; | 1102 | unit->extension.bControlSize = buffer[22+p]; |