From patchwork Tue Sep 15 15:49:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 7187741 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0648A9F336 for ; Tue, 15 Sep 2015 15:53:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 18A4A206A5 for ; Tue, 15 Sep 2015 15:52:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1FA472069D for ; Tue, 15 Sep 2015 15:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754447AbbIOPwz (ORCPT ); Tue, 15 Sep 2015 11:52:55 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:57541 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754661AbbIOPte (ORCPT ); Tue, 15 Sep 2015 11:49:34 -0400 Received: from wuerfel.lan. ([149.172.15.242]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0LzHnN-1YYJVx35Sj-014V4J; Tue, 15 Sep 2015 17:49:28 +0200 From: Arnd Bergmann To: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Mauro Carvalho Chehab , linux-api@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Arnd Bergmann Subject: [PATCH 7/7] [RFC] [media] introduce v4l2_timespec type for timestamps Date: Tue, 15 Sep 2015 17:49:08 +0200 Message-Id: <1442332148-488079-8-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.1.0.rc2 In-Reply-To: <1442332148-488079-1-git-send-email-arnd@arndb.de> References: <1442332148-488079-1-git-send-email-arnd@arndb.de> X-Provags-ID: V03:K0:fmNXYunln5NGhFH0cw+Sfp6DKB/oC6TKfuHNCBcG6i1ZkMh5R5n p0AQH3HI2QLbSH7h39dHVGo2+9qIlbOS++G+BElDseSDCleYeorKJS++0AP4E+VTuzNvbIi mWdWNNoAZAkelAZivzOzS2KpXOBIezwlxXZhZTEmWbUBMnnVmOEak7OU7eMOg+KZpqnYlgS 8+WbSxco/AU1gmRJRzCqA== X-UI-Out-Filterresults: notjunk:1; V01:K0:C6eneB4Efjw=:m25wSmd7Q5kwoc8AVCrpyQ QdI60JOxSO3Gh2soF2Npv5QYdWLHoOtRac7lNMkY+ApWV36d30es1boKwkYH3Ib7Jrq6gy1HB V+R1gG4PGhNK7U8YJ5Iek+94L4cCZbcuzhyPd6zdIWWvWZ/kizz/oZfWdgxHghhaokfQ7Kdd4 Dmb1/lfLqYaFh+5HyPKdTMmg8FtHCH6QTeCs7WwBiLhdtx0gji+D7+DO55znS/kl1UqjfcWYw LQU6xvmC/h4FUOykLCnVaRno5gmO4T2fvgiuPvNvDD3xT1wlVCw4FotG2jc7OHu7JVg6G1GPA JeImmQBmatJvXabd+ODe3vmJ2sL3vjE55d/zQ3mXEhMC+kd2dSHGL/IJ/JLA11KLL+Qg5ilTh JM3DKdzlXeIkl8kFEpS6dWTwpL1B9JN4gqvskVJHUf0qvbvDnfa30YZw5sRWrGC1kG7jqB7Yf Y4tuIltnhgJgjMn4p7aeEUyaqtlGajaXuU5zSMM6AyiskYsAbB/AMzE/96gTZ5wzhrolh9Y5V AgDPFYCSHiP2jEN8a2K0k+8quebJiyonX+9zC1RctVSQz6wdJ/W8pVS9UsYHl/DyrwvHMssrb ymOdXDz5nyRk6qp4xI0Gj2IqJ9TOPWMhEOkN6CXuiEUPR9/qIZNmr1fNdDpd+pKjx4zmjx5oz wMLtT/RmWM+3l95YRh0lqqwtETZnaSnGVQMslgkx8XVgsTWUrP98K9sfgRxJ26CCIwCk= Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The v4l2 event queue uses a 'struct timespec' to pass monotonic timestamps. This is not a problem by itself, but it breaks when user space redefines timespec to use 'long long' on 32-bit systems. To avoid that problem, we define our own replacement for timespec here, using 'long' tv_sec and tv_nsec members. This means no change to the existing API, but lets us keep using it with a y2038 compatible libc. As a side-effect, this changes the API for x32 programs to be the same as native 32-bit, using a 32-bit tv_sec/tv_nsec value, but both old and new kernels already support both formats for on the binary level for compat and x32. Alternatively, we could leave the header file to define the interface based on 'struct timespec', and implement both ioctls for native processes. I picked the approach in this case because it matches what we do for v4l2_timeval in the respective patch, but both would work equally well here. Signed-off-by: Arnd Bergmann --- drivers/media/v4l2-core/v4l2-event.c | 20 +++++++++++++------- include/uapi/linux/videodev2.h | 8 +++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c index 8d3171c6bee8..2a26ad591f59 100644 --- a/drivers/media/v4l2-core/v4l2-event.c +++ b/drivers/media/v4l2-core/v4l2-event.c @@ -108,7 +108,7 @@ static struct v4l2_subscribed_event *v4l2_event_subscribed( } static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev, - const struct timespec *ts) + const struct v4l2_timespec *ts) { struct v4l2_subscribed_event *sev; struct v4l2_kevent *kev; @@ -170,17 +170,20 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev) { struct v4l2_fh *fh; unsigned long flags; - struct timespec timestamp; + struct timespec64 timestamp; + struct v4l2_timespec vts; if (vdev == NULL) return; - ktime_get_ts(×tamp); + ktime_get_ts64(×tamp); + vts.tv_sec = timestamp.tv_sec; + vts.tv_nsec = timestamp.tv_nsec; spin_lock_irqsave(&vdev->fh_lock, flags); list_for_each_entry(fh, &vdev->fh_list, list) - __v4l2_event_queue_fh(fh, ev, ×tamp); + __v4l2_event_queue_fh(fh, ev, &vts); spin_unlock_irqrestore(&vdev->fh_lock, flags); } @@ -189,12 +192,15 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue); void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev) { unsigned long flags; - struct timespec timestamp; + struct timespec64 timestamp; + struct v4l2_timespec vts; - ktime_get_ts(×tamp); + ktime_get_ts64(×tamp); + vts.tv_sec = timestamp.tv_sec; + vts.tv_nsec = timestamp.tv_nsec; spin_lock_irqsave(&fh->vdev->fh_lock, flags); - __v4l2_event_queue_fh(fh, ev, ×tamp); + __v4l2_event_queue_fh(fh, ev, &vts); spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); } EXPORT_SYMBOL_GPL(v4l2_event_queue_fh); diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index b02cf054fbb8..bc659be87260 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -809,6 +809,12 @@ struct v4l2_timeval { long tv_usec; }; +/* used for monotonic times, therefore y2038 safe */ +struct v4l2_timespec { + long tv_sec; + long tv_nsec; +}; + /** * struct v4l2_buffer - video buffer info * @index: id number of the buffer @@ -2088,7 +2094,7 @@ struct v4l2_event { } u; __u32 pending; __u32 sequence; - struct timespec timestamp; + struct v4l2_timespec timestamp; __u32 id; __u32 reserved[8]; };