[PATCH 1/3] media: v4l2-core: move the code that copies v4l2_event_time32 to a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move the code that copies v4l2_event_time32 to function
"put_v4l2_event_time32". This function will also be used
for the case of 64-bit kernel other than x86_64 in later
commits.

Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@xxxxxxxxxxxxx>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 41 +++++++++++++++++-----------
 include/media/v4l2-ioctl.h           |  6 ++++
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 05d5db3d85e5..24bdb2383595 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -3167,6 +3167,28 @@ static int video_get_user(void __user *arg, void *parg,
 	return err;
 }
 
+int put_v4l2_event_time32(void *parg, void __user *arg)
+{
+	struct v4l2_event *ev = parg;
+	struct v4l2_event_time32 ev32;
+
+	memset(&ev32, 0, sizeof(ev32));
+
+	ev32.type	= ev->type;
+	ev32.pending	= ev->pending;
+	ev32.sequence	= ev->sequence;
+	ev32.timestamp.tv_sec	= ev->timestamp.tv_sec;
+	ev32.timestamp.tv_nsec	= ev->timestamp.tv_nsec;
+	ev32.id		= ev->id;
+
+	memcpy(&ev32.u, &ev->u, sizeof(ev->u));
+	memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved));
+
+	if (copy_to_user(arg, &ev32, sizeof(ev32)))
+		return -EFAULT;
+	return 0;
+}
+
 static int video_put_user(void __user *arg, void *parg,
 			  unsigned int real_cmd, unsigned int cmd)
 {
@@ -3186,23 +3208,10 @@ static int video_put_user(void __user *arg, void *parg,
 #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME)
 	switch (cmd) {
 	case VIDIOC_DQEVENT_TIME32: {
-		struct v4l2_event *ev = parg;
-		struct v4l2_event_time32 ev32;
-
-		memset(&ev32, 0, sizeof(ev32));
+		int ret = put_v4l2_event_time32(parg, arg);
 
-		ev32.type	= ev->type;
-		ev32.pending	= ev->pending;
-		ev32.sequence	= ev->sequence;
-		ev32.timestamp.tv_sec	= ev->timestamp.tv_sec;
-		ev32.timestamp.tv_nsec	= ev->timestamp.tv_nsec;
-		ev32.id		= ev->id;
-
-		memcpy(&ev32.u, &ev->u, sizeof(ev->u));
-		memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved));
-
-		if (copy_to_user(arg, &ev32, sizeof(ev32)))
-			return -EFAULT;
+		if (ret)
+			return ret;
 		break;
 	}
 	case VIDIOC_QUERYBUF_TIME32:
diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
index edb733f21604..0c209bbbc76f 100644
--- a/include/media/v4l2-ioctl.h
+++ b/include/media/v4l2-ioctl.h
@@ -784,6 +784,12 @@ struct v4l2_buffer_time32 {
 		__u32		reserved;
 	};
 };
+
+/*
+ * This function is used to copy the struct v4l2_event_time32 to userspace
+ */
+int put_v4l2_event_time32(void *parg, void __user *arg);
+
 #define VIDIOC_QUERYBUF_TIME32	_IOWR('V',  9, struct v4l2_buffer_time32)
 #define VIDIOC_QBUF_TIME32	_IOWR('V', 15, struct v4l2_buffer_time32)
 #define VIDIOC_DQBUF_TIME32	_IOWR('V', 17, struct v4l2_buffer_time32)
-- 
2.17.1




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux