All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t
@ 2017-11-27 15:21 Arnd Bergmann
  2017-11-27 15:25 ` Andy Shevchenko
  2017-11-27 19:07 ` Alan Cox
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2017-11-27 15:21 UTC (permalink / raw)
  To: Alan Cox, Sakari Ailus, Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: y2038, Arnd Bergmann, Andy Shevchenko, linux-media, devel, linux-kernel

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 <arnd@arndb.de>
---
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;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t
  2017-11-27 15:21 [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t Arnd Bergmann
@ 2017-11-27 15:25 ` Andy Shevchenko
  2017-11-27 19:07 ` Alan Cox
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2017-11-27 15:25 UTC (permalink / raw)
  To: Arnd Bergmann, Alan Cox, Sakari Ailus, Mauro Carvalho Chehab,
	Greg Kroah-Hartman
  Cc: y2038, linux-media, devel, linux-kernel

On Mon, 2017-11-27 at 16:21 +0100, Arnd Bergmann wrote:
> 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.
> 

Yep,

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> 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;

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t
  2017-11-27 15:21 [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t Arnd Bergmann
  2017-11-27 15:25 ` Andy Shevchenko
@ 2017-11-27 19:07 ` Alan Cox
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Cox @ 2017-11-27 19:07 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Alan Cox, Sakari Ailus, Mauro Carvalho Chehab, y2038,
	Andy Shevchenko, linux-media, devel

On Mon, 27 Nov 2017 16:21:41 +0100
Arnd Bergmann <arnd@arndb.de> wrote:

> 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 <arnd@arndb.de>

Reviewed-by: Alan Cox <alan@linux.intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-27 19:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 15:21 [PATCH v2] [media] staging: atomisp: convert timestamps to ktime_t Arnd Bergmann
2017-11-27 15:25 ` Andy Shevchenko
2017-11-27 19:07 ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.