[PATCH 26/44] iio: Switch to use hrtimer_setup()

Nam Cao posted 44 patches 4 weeks ago
[PATCH 26/44] iio: Switch to use hrtimer_setup()
Posted by Nam Cao 4 weeks ago
There is a newly introduced hrtimer_setup() which will replace
hrtimer_init(). This new function is similar to the old one, except that it
also sanity-checks and initializes the timer's callback function.

Switch to use this new function.

Patch was created by using Coccinelle.

Signed-off-by: Nam Cao <namcao@linutronix.de>
---
Cc: Jonathan Cameron <jic23@kernel.org>
---
 drivers/iio/adc/ti-tsc2046.c           | 4 +---
 drivers/iio/trigger/iio-trig-hrtimer.c | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c
index 311d97001249..87c86d752293 100644
--- a/drivers/iio/adc/ti-tsc2046.c
+++ b/drivers/iio/adc/ti-tsc2046.c
@@ -812,9 +812,7 @@ static int tsc2046_adc_probe(struct spi_device *spi)
 
 	spin_lock_init(&priv->state_lock);
 	priv->state = TSC2046_STATE_SHUTDOWN;
-	hrtimer_init(&priv->trig_timer, CLOCK_MONOTONIC,
-		     HRTIMER_MODE_REL_SOFT);
-	priv->trig_timer.function = tsc2046_adc_timer;
+	hrtimer_setup(&priv->trig_timer, tsc2046_adc_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
 
 	ret = devm_iio_trigger_register(dev, trig);
 	if (ret) {
diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c
index 716c795d08fb..82c72baccb62 100644
--- a/drivers/iio/trigger/iio-trig-hrtimer.c
+++ b/drivers/iio/trigger/iio-trig-hrtimer.c
@@ -145,8 +145,8 @@ static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name)
 	trig_info->swt.trigger->ops = &iio_hrtimer_trigger_ops;
 	trig_info->swt.trigger->dev.groups = iio_hrtimer_attr_groups;
 
-	hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
-	trig_info->timer.function = iio_hrtimer_trig_handler;
+	hrtimer_setup(&trig_info->timer, iio_hrtimer_trig_handler, CLOCK_MONOTONIC,
+		      HRTIMER_MODE_REL_HARD);
 
 	trig_info->sampling_frequency[0] = HRTIMER_DEFAULT_SAMPLING_FREQUENCY;
 	trig_info->period = NSEC_PER_SEC / trig_info->sampling_frequency[0];
-- 
2.39.5
Re: [PATCH 26/44] iio: Switch to use hrtimer_setup()
Posted by Jonathan Cameron 3 weeks, 1 day ago
On Mon, 28 Oct 2024 08:35:02 +0100
Nam Cao <namcao@linutronix.de> wrote:

> There is a newly introduced hrtimer_setup() which will replace
> hrtimer_init(). This new function is similar to the old one, except that it
> also sanity-checks and initializes the timer's callback function.
> 
> Switch to use this new function.
> 
> Patch was created by using Coccinelle.
> 
> Signed-off-by: Nam Cao <namcao@linutronix.de>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Seems sensible to me.

https://lore.kernel.org/lkml/2159c09badceec667d800005ac98824105ba8dc6.1729864615.git.namcao@linutronix.de/
Has definition of hrtimer_setup()

+CC  linux-iio as an FYI.

Jonathan

> ---
> Cc: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/iio/adc/ti-tsc2046.c           | 4 +---
>  drivers/iio/trigger/iio-trig-hrtimer.c | 4 ++--
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c
> index 311d97001249..87c86d752293 100644
> --- a/drivers/iio/adc/ti-tsc2046.c
> +++ b/drivers/iio/adc/ti-tsc2046.c
> @@ -812,9 +812,7 @@ static int tsc2046_adc_probe(struct spi_device *spi)
>  
>  	spin_lock_init(&priv->state_lock);
>  	priv->state = TSC2046_STATE_SHUTDOWN;
> -	hrtimer_init(&priv->trig_timer, CLOCK_MONOTONIC,
> -		     HRTIMER_MODE_REL_SOFT);
> -	priv->trig_timer.function = tsc2046_adc_timer;
> +	hrtimer_setup(&priv->trig_timer, tsc2046_adc_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
>  
>  	ret = devm_iio_trigger_register(dev, trig);
>  	if (ret) {
> diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c
> index 716c795d08fb..82c72baccb62 100644
> --- a/drivers/iio/trigger/iio-trig-hrtimer.c
> +++ b/drivers/iio/trigger/iio-trig-hrtimer.c
> @@ -145,8 +145,8 @@ static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name)
>  	trig_info->swt.trigger->ops = &iio_hrtimer_trigger_ops;
>  	trig_info->swt.trigger->dev.groups = iio_hrtimer_attr_groups;
>  
> -	hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
> -	trig_info->timer.function = iio_hrtimer_trig_handler;
> +	hrtimer_setup(&trig_info->timer, iio_hrtimer_trig_handler, CLOCK_MONOTONIC,
> +		      HRTIMER_MODE_REL_HARD);
>  
>  	trig_info->sampling_frequency[0] = HRTIMER_DEFAULT_SAMPLING_FREQUENCY;
>  	trig_info->period = NSEC_PER_SEC / trig_info->sampling_frequency[0];