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: 119719 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp414430qgn; Mon, 27 Nov 2017 07:23:21 -0800 (PST) X-Google-Smtp-Source: AGs4zMalhnWXW75HzjZDT7bSyAo7KDWlehqA8uxtbyDh32YzKGE00MAmnEDul1OLR7PzJ+KtpgfB X-Received: by 10.101.66.66 with SMTP id d2mr18620298pgq.244.1511796201662; Mon, 27 Nov 2017 07:23:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511796201; cv=none; d=google.com; s=arc-20160816; b=yy10HnBTm7hu74X2mlDRE/8jzv9C0dS02ouTzMQuYyZEQ1RDQ0geNpwVu25rOeYvVp VlzaKKXFGHDTfS/va/i3p/zepq60hB79E5usyGGicttto9ZW73tT1NHajcHSP40FZhsB DE/mnMpRdZHgkhotzRtqsNrYW6PYegImyXNsQcwq0mNyuYSxR6dU4ErvyIxzfP8dMDbN e+Kb/3XsJ6QVjzgcBBx7exbznOFu38VqUaVS1N1NydQ5q+8mjWK92o1YlgdDPT2ggg0V QrcfDhDsJct0GZr6UHlTLzS+W+6p0ddNu7p5QB3scU1dTBmtD0ivO7bfDjZxhTpPkX1l xQMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=3S5DhQRyur12SFlEmqCKm5JrG/MTroynyOgRpB94ANo=; b=qHAwcG7a5IN5+HFN+kpVyo4jP3oNe63vVvls5BoVVBFkQW8/UcCx4os44gKIv1VRmZ MHzx0EQ09jC85RBKjdRVCYomCD98umsZuTVoPjJ/cw1OTKxEwOXtrb5DOPsAGTdbIl2G uYZu8OPbv0xCaQ+3VkiHybW5Z0x3nH5FQwyFsB4458AVsDJnuccmgTshs6PjZzgDejTj umbWJRhbfYZfZXD7f72/yxc6FfWdBtHD2vPhNduETA41hX8LeoMa4u6fkxW/Pyy++gxu 0p67oAQX8vV4pyTNurWVxh+lPzVKgIs94SXDGHzfx/bYsjKXUpdSef+87RbvVAv5U2E3 0yfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4si9976008pfc.22.2017.11.27.07.23.21; Mon, 27 Nov 2017 07:23:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752626AbdK0PXU (ORCPT + 4 others); 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 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 --- 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(-) -- 2.9.0 Reviewed-by: Alan Cox 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;