The v4l2_video_std_construct() implementation sets the "index"
field also properly, so there is no need to do this again. The
return value of v4l2_video_std_construct() can be used as the
ioctl() return value.

I also attached a simple test environment to test this change.
I run my tests under 2.6.25-gcov and with Pinnacle Hybrid Pro
Stick (320e) device.
I checked that all lines of "case VIDIOC_ENUMSTD" in
em28xx-video.c:em28xx_do_ioctl() were executed.

The test results are:
Test Case 1: VIDIOC_ENUMSTD
VIDIOC_ENUMSTD, ret=0
        std = {.index=0, .name="PAL-BG" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=1, .name="PAL-DK" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=2, .name="PAL-I" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=3, .name="NTSC-M" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=4, .name="SECAM L" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=5, .name="SECAM LC" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=6, .name="SECAM K1" }
VIDIOC_ENUMSTD, ret=0
        std = {.index=7, .name="PAL-M" }
VIDIOC_ENUMSTD, ret=-1
        errno=22
PASSED

Test Case 2: VIDIOC_ENUMSTD, index=MAX_EM28XX_TVNORMS
VIDIOC_ENUMSTD, ret=-1
        errno=22
PASSED

Test Case 3: VIDIOC_ENUMSTD, index=U32_MAX
VIDIOC_ENUMSTD, ret=-1
        errno=22
PASSED
diff -r b8b5a5bb8287 em28xx-video.c
--- a/em28xx-video.c	Wed Dec 10 08:54:29 2008 +0100
+++ b/em28xx-video.c	Fri Dec 12 08:19:28 2008 +0100
@@ -1901,11 +1901,7 @@
 		ret = v4l2_video_std_construct(e,
 				dev->board->tvnorms[e->index].id,
 				dev->board->tvnorms[e->index].name);
-
-		e->index = i;
-		if (ret < 0)
-			return ret;
-		return 0;
+		return ret;
 	}
 	case VIDIOC_G_STD:
 	{
/* Written by Márton Németh <[email protected]> */
/* v0.1  12 Dec 2008 Initial version */
/* Released under GPL */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>

#include <linux/videodev2.h>
#include <linux/errno.h>

#define U32_MAX		0xFFFFFFFF

#define MAX_EM28XX_TVNORMS	10

#define TC_PASSED	1
#define TC_FAILED	2

void tc01(int f) {
	int ret;
	struct v4l2_standard std;
	__u32 i;
	int tc_result = TC_PASSED;

	printf("Test Case 1: VIDIOC_ENUMSTD\n");

	i = 0;
	do {
		memset(&std, 0xff, sizeof(std));
		std.index = i;
		ret = ioctl(f, VIDIOC_ENUMSTD, &std);
		printf("VIDIOC_ENUMSTD, ret=%i\n", ret);
		if (ret == 0) {
			printf("\tstd = {.index=%u, .name=\"%s\" }\n", std.index, std.name);
			//std.id
			//std.frameperiod
			//std.framelines
			//std.reserved[0]
			//std.reserved[1]
			//std.reserved[2]
			//std.reserved[3]
		} else {
			printf("\terrno=%i\n", errno);
		}
		if ( ! ((ret == 0) || (ret == -1 && errno == EINVAL)) ) {
			tc_result = TC_FAILED;
		}
		i++;
	} while (ret == 0);

	switch (tc_result) {
	case TC_PASSED:
		printf("PASSED\n");
		break;
	case TC_FAILED:
		printf("PASSED\n");
		break;
	default:
		printf("Internal error: tc_result=%i\n", tc_result);
	}

	printf("\n");
}

void tc02(int f) {
	int ret;
	struct v4l2_standard std;

	printf("Test Case 2: VIDIOC_ENUMSTD, index=MAX_EM28XX_TVNORMS\n");
	memset(&std, 0xff, sizeof(std));
	std.index = MAX_EM28XX_TVNORMS;
	ret = ioctl(f, VIDIOC_ENUMSTD, &std);
	printf("VIDIOC_ENUMSTD, ret=%i\n", ret);
	if (ret != 0) {
		printf("\terrno=%i\n", errno);
	}
	if (ret != -1 || errno != EINVAL) {
		printf("FAILED\n");
	} else {
		printf("PASSED\n");
	}
	printf("\n");
}

void tc03(int f) {
	int ret;
	struct v4l2_standard std;

	printf("Test Case 3: VIDIOC_ENUMSTD, index=U32_MAX\n");
	memset(&std, 0xff, sizeof(std));
	std.index = U32_MAX;
	ret = ioctl(f, VIDIOC_ENUMSTD, &std);
	printf("VIDIOC_ENUMSTD, ret=%i\n", ret);
	if (ret != 0) {
		printf("\terrno=%i\n", errno);
	}
	if (ret != -1 || errno != EINVAL) {
		printf("FAILED\n");
	} else {
		printf("PASSED\n");
	}
	printf("\n");
}


int main() {
	int f;
	int ret;

	f = open("/dev/video0", O_RDWR);
	if (f < 0) {
		perror("cannot open /dev/video0");
		return 1;
	}

	tc01(f);
	tc02(f);
	tc03(f);

	ret = close(f);
	if (ret < 0) {
		perror("cannot open close");
		return 1;
	}

	return 0;
}
_______________________________________________
Em28xx mailing list
[email protected]
http://mcentral.de/mailman/listinfo/em28xx

Reply via email to