From 7d7d9d39959a9cf732e480ef8379601bddbb6a3f Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 24 Mar 2015 15:04:11 +0100 Subject: [PATCH] libv4l2: Correctly initialize structures This uses C99 initializers so that structs are zeroed if no value has been specified. Change-Id: I00274262d86035318b68406e4826e6e095aec8d6 Signed-off-by: Andreas Schneider --- libv4l2/exynos_v4l2.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libv4l2/exynos_v4l2.c b/libv4l2/exynos_v4l2.c index 0110f7f..345fd5a 100644 --- a/libv4l2/exynos_v4l2.c +++ b/libv4l2/exynos_v4l2.c @@ -195,7 +195,9 @@ int exynos_v4l2_close(int fd) bool exynos_v4l2_enuminput(int fd, int index, char *input_name_buf) { int ret = -1; - struct v4l2_input input; + struct v4l2_input input = { + .index = index, + }; Exynos_v4l2_In(); @@ -204,7 +206,6 @@ bool exynos_v4l2_enuminput(int fd, int index, char *input_name_buf) return NULL; } - input.index = index; ret = ioctl(fd, VIDIOC_ENUMINPUT, &input, 32); if (ret) { ALOGE("%s: no matching index founds", __func__); @@ -223,7 +224,9 @@ bool exynos_v4l2_enuminput(int fd, int index, char *input_name_buf) int exynos_v4l2_s_input(int fd, int index) { int ret = -1; - struct v4l2_input input; + struct v4l2_input input = { + .index = index, + }; Exynos_v4l2_In(); @@ -232,8 +235,6 @@ int exynos_v4l2_s_input(int fd, int index) return ret; } - input.index = index; - ret = ioctl(fd, VIDIOC_S_INPUT, &input); if (ret){ ALOGE("failed to ioctl: VIDIOC_S_INPUT (%d - %s)", errno, strerror(errno)); @@ -286,14 +287,14 @@ bool exynos_v4l2_querycap(int fd, unsigned int need_caps) bool exynos_v4l2_enum_fmt(int fd, enum v4l2_buf_type type, unsigned int fmt) { - struct v4l2_fmtdesc fmtdesc; + struct v4l2_fmtdesc fmtdesc = { + .index = 0, + .type = type, + }; int found = 0; Exynos_v4l2_In(); - fmtdesc.type = type; - fmtdesc.index = 0; - while (ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) == 0) { if (fmtdesc.pixelformat == fmt) { ALOGE("Passed fmt = %#x found pixel format[%d]: %s", fmt, fmtdesc.index, fmtdesc.description); @@ -737,13 +738,13 @@ int exynos_v4l2_g_ctrl(int fd, unsigned int id, int *value) int exynos_v4l2_s_ctrl(int fd, unsigned int id, int value) { int ret = -1; - struct v4l2_control ctrl; + struct v4l2_control ctrl = { + .id = id, + .value = value, + }; Exynos_v4l2_In(); - ctrl.id = id; - ctrl.value = value; - if (fd < 0) { ALOGE("%s: invalid fd: %d", __func__, fd); return ret; -- 2.20.1