From patchwork Mon Nov 27 15:21:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10077009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1472B60353 for ; Mon, 27 Nov 2017 15:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04D1728F19 for ; Mon, 27 Nov 2017 15:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDA7F28F1E; Mon, 27 Nov 2017 15:23:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A061C28F19 for ; Mon, 27 Nov 2017 15:23:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752626AbdK0PXU (ORCPT ); Mon, 27 Nov 2017 10:23:20 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:50205 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbdK0PXT (ORCPT ); Mon, 27 Nov 2017 10:23:19 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.129]) with ESMTPA (Nemesis) id 0M6JFz-1f4Zwd2WxX-00yQ3C; Mon, 27 Nov 2017 16:23:00 +0100 From: Arnd Bergmann To: Alan Cox , Sakari Ailus , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: y2038@lists.linaro.org, Arnd Bergmann , Andy Shevchenko , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t Date: Mon, 27 Nov 2017 16:21:41 +0100 Message-Id: <20171127152256.2184193-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:qI5+tzzKffcrYw34eBB9VBL1/c9jIl5pWZq92T6sZQp98bKPxCF 9AN/dEMe4G+DjYlVXvPKesFJNaXfU9v4ZogQ7h9o7tNTdh8Gn5f61OlmKTtNRBEM4e3eTjX oGP76AHecQlXKcx8AF5R14EJgR5kM9ru2VohYyOs15qBAnJcHLGzBzB96t427pc8lJutzII vNWJoIcaBbYZGYthF5OjQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:0S7gQa/CRh4=:iprJwiAvpOy4Icj3g99H65 wEK+oI4hh4iYXZu4IcnKB7Ae5osuLBjk6qZ8nWXdNJa9iS+/IHRxvmYKcChmi63qYivb8f2Yh hggm2ZcIQ6hDjiODs37g+PAfsRB7NK6b0KrbUT982z/8QvIh0Jnk7Ijl2h3sk0N6ehhw1WOMU xQj/SxbFUTy86U+yU7AsHbMtLg+UQZrPhYnT6WGE3cBmz/vzZ8os3WiJ2Ip3QQiV2xGSN4jeM eL3jV8f7PAURMtg9Z/5YgWGJodYlyJbzksXhEpJUjLYALUopkBAYCoIrngfYnbjsEp9/7iOFl KIPMm7u2sPZJ83Z6nDy9IPVG336IRAR8koO8XTapyYhWjwOV99/wN/crp9+kY1/U5o+6IHfD7 45oZJz9I7aJ134Tl1rSZs7A3hP1283HctEn/u1lv2CeqRdcY0dB3Q9EAl7zePcJdMRkKw4+OP 4df13F7vRit7biy3ZEKTiSRZSVZl/p4TvzdaoHfiPgkkgAffYb6ErrnJPfQjtwwJ/GqVOMy4X qqhTltXdCpCT5frxB7yhpLHt528DRZWmNOTtpxvjxKEwMdkJCCIz7JPyfspcfCTyrdBhfmf6w Ovjse7g7L/jeHgNRbtQ/MpcCYPjime6a3Lyi/9X8Qear1HGynp7fuqwxRnKHU2XMawSfTS9qG rRhw79QlXSzd9mQOjQqTa/HVcEkgv9wuyqY744PMslDyNOQDHxwJVN8AufYRXtsbs4P8r1VGP rlR/ykVjt95mrNi5tWEjrFjSE7VbNaQmJoTB1Q== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP timespec overflows in 2038 on 32-bit architectures, and the getnstimeofday() suffers from possible time jumps, so the timestamps here are better done using ktime_get(), which has neither of those problems. In case of ov2680, we don't seem to use the timestamp at all, so I just remove it. Signed-off-by: Arnd Bergmann Reviewed-by: Andy Shevchenko Reviewed-by: Alan Cox --- v2: use min_t() as suggested by Andy Shevchenko --- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - .../staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 19 ++++++++----------- drivers/staging/media/atomisp/i2c/ov5693/ov5693.h | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/staging/media/atomisp/i2c/ov2680.h b/drivers/staging/media/atomisp/i2c/ov2680.h index bf4897347df7..03f75dd80f87 100644 --- a/drivers/staging/media/atomisp/i2c/ov2680.h +++ b/drivers/staging/media/atomisp/i2c/ov2680.h @@ -174,7 +174,6 @@ struct ov2680_format { struct mutex input_lock; struct v4l2_ctrl_handler ctrl_handler; struct camera_sensor_platform_data *platform_data; - struct timespec timestamp_t_focus_abs; int vt_pix_clk_freq_mhz; int fmt_idx; int run_mode; diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index 3e7c3851280f..9fa25bb8f1ee 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -973,7 +973,7 @@ static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value) if (ret == 0) { dev->number_of_steps = value - dev->focus; dev->focus = value; - getnstimeofday(&(dev->timestamp_t_focus_abs)); + dev->timestamp_t_focus_abs = ktime_get(); } else dev_err(&client->dev, "%s: i2c failed. ret %d\n", __func__, ret); @@ -993,16 +993,13 @@ static int ov5693_q_focus_status(struct v4l2_subdev *sd, s32 *value) { u32 status = 0; struct ov5693_device *dev = to_ov5693_sensor(sd); - struct timespec temptime; - const struct timespec timedelay = { - 0, - min((u32)abs(dev->number_of_steps) * DELAY_PER_STEP_NS, - (u32)DELAY_MAX_PER_STEP_NS), - }; - - getnstimeofday(&temptime); - temptime = timespec_sub(temptime, (dev->timestamp_t_focus_abs)); - if (timespec_compare(&temptime, &timedelay) <= 0) { + ktime_t temptime; + ktime_t timedelay = ns_to_ktime(min_t(u32, + abs(dev->number_of_steps) * DELAY_PER_STEP_NS, + DELAY_MAX_PER_STEP_NS)); + + temptime = ktime_sub(ktime_get(), (dev->timestamp_t_focus_abs)); + if (ktime_compare(temptime, timedelay) <= 0) { status |= ATOMISP_FOCUS_STATUS_MOVING; status |= ATOMISP_FOCUS_HP_IN_PROGRESS; } else { diff --git a/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h b/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h index 2ea63807c56d..68cfcb4a6c3c 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h +++ b/drivers/staging/media/atomisp/i2c/ov5693/ov5693.h @@ -221,7 +221,7 @@ struct ov5693_device { struct v4l2_ctrl_handler ctrl_handler; struct camera_sensor_platform_data *platform_data; - struct timespec timestamp_t_focus_abs; + ktime_t timestamp_t_focus_abs; int vt_pix_clk_freq_mhz; int fmt_idx; int run_mode;