diff mbox

PM: Convert timers to use timer_setup()

Message ID 20171016232055.GA100369@beast (mailing list archive)
State Mainlined
Delegated to: Rafael Wysocki
Headers show

Commit Message

Kees Cook Oct. 16, 2017, 11:20 p.m. UTC
In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Removes test of .data field, since
that will be going away.

Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/base/power/runtime.c |  7 +++----
 drivers/base/power/wakeup.c  | 11 +++++------
 2 files changed, 8 insertions(+), 10 deletions(-)

Comments

Wysocki, Rafael J Oct. 16, 2017, 11:53 p.m. UTC | #1
On 10/17/2017 1:20 AM, Kees Cook wrote:
> In preparation for unconditionally passing the struct timer_list pointer to
> all timer callbacks, switch to using the new timer_setup() and from_timer()
> to pass the timer pointer explicitly. Removes test of .data field, since
> that will be going away.
>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-pm@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>   drivers/base/power/runtime.c |  7 +++----
>   drivers/base/power/wakeup.c  | 11 +++++------
>   2 files changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 7bcf80fa9ada..1cea431c0adf 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -894,9 +894,9 @@ static void pm_runtime_work(struct work_struct *work)
>    *
>    * Check if the time is right and queue a suspend request.
>    */
> -static void pm_suspend_timer_fn(unsigned long data)
> +static void pm_suspend_timer_fn(struct timer_list *t)
>   {
> -	struct device *dev = (struct device *)data;
> +	struct device *dev = from_timer(dev, t, power.suspend_timer);
>   	unsigned long flags;
>   	unsigned long expires;
>   
> @@ -1499,8 +1499,7 @@ void pm_runtime_init(struct device *dev)
>   	INIT_WORK(&dev->power.work, pm_runtime_work);
>   
>   	dev->power.timer_expires = 0;
> -	setup_timer(&dev->power.suspend_timer, pm_suspend_timer_fn,
> -			(unsigned long)dev);
> +	timer_setup(&dev->power.suspend_timer, pm_suspend_timer_fn, 0);
>   
>   	init_waitqueue_head(&dev->power.wait_queue);
>   }
> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> index cdd6f256da59..680ee1d36ac9 100644
> --- a/drivers/base/power/wakeup.c
> +++ b/drivers/base/power/wakeup.c
> @@ -54,7 +54,7 @@ static unsigned int saved_count;
>   
>   static DEFINE_SPINLOCK(events_lock);
>   
> -static void pm_wakeup_timer_fn(unsigned long data);
> +static void pm_wakeup_timer_fn(struct timer_list *t);
>   
>   static LIST_HEAD(wakeup_sources);
>   
> @@ -176,7 +176,7 @@ void wakeup_source_add(struct wakeup_source *ws)
>   		return;
>   
>   	spin_lock_init(&ws->lock);
> -	setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws);
> +	timer_setup(&ws->timer, pm_wakeup_timer_fn, 0);
>   	ws->active = false;
>   	ws->last_time = ktime_get();
>   
> @@ -481,8 +481,7 @@ static bool wakeup_source_not_registered(struct wakeup_source *ws)
>   	 * Use timer struct to check if the given source is initialized
>   	 * by wakeup_source_add.
>   	 */
> -	return ws->timer.function != pm_wakeup_timer_fn ||
> -		   ws->timer.data != (unsigned long)ws;
> +	return ws->timer.function != (TIMER_FUNC_TYPE)pm_wakeup_timer_fn;
>   }
>   
>   /*
> @@ -724,9 +723,9 @@ EXPORT_SYMBOL_GPL(pm_relax);
>    * in @data if it is currently active and its timer has not been canceled and
>    * the expiration time of the timer is not in future.
>    */
> -static void pm_wakeup_timer_fn(unsigned long data)
> +static void pm_wakeup_timer_fn(struct timer_list *t)
>   {
> -	struct wakeup_source *ws = (struct wakeup_source *)data;
> +	struct wakeup_source *ws = from_timer(ws, t, timer);
>   	unsigned long flags;
>   
>   	spin_lock_irqsave(&ws->lock, flags);
Rafael J. Wysocki Oct. 17, 2017, 12:15 a.m. UTC | #2
On Tuesday, October 17, 2017 2:19:48 AM CEST Kees Cook wrote:
> On Mon, Oct 16, 2017 at 4:53 PM, Rafael J. Wysocki
> <rafael.j.wysocki@intel.com> wrote:
> > On 10/17/2017 1:20 AM, Kees Cook wrote:
> >>
> >> In preparation for unconditionally passing the struct timer_list pointer
> >> to
> >> all timer callbacks, switch to using the new timer_setup() and
> >> from_timer()
> >> to pass the timer pointer explicitly. Removes test of .data field, since
> >> that will be going away.
> >>
> >> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> >> Cc: Pavel Machek <pavel@ucw.cz>
> >> Cc: Len Brown <len.brown@intel.com>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: linux-pm@vger.kernel.org
> >> Signed-off-by: Kees Cook <keescook@chromium.org>
> >
> >
> > Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Do you want this to be carried in the timers tree, or can you pick it up?

I can pick it up, but only for 4.15.

Thanks,
Rafael
Kees Cook Oct. 17, 2017, 12:19 a.m. UTC | #3
On Mon, Oct 16, 2017 at 4:53 PM, Rafael J. Wysocki
<rafael.j.wysocki@intel.com> wrote:
> On 10/17/2017 1:20 AM, Kees Cook wrote:
>>
>> In preparation for unconditionally passing the struct timer_list pointer
>> to
>> all timer callbacks, switch to using the new timer_setup() and
>> from_timer()
>> to pass the timer pointer explicitly. Removes test of .data field, since
>> that will be going away.
>>
>> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
>> Cc: Pavel Machek <pavel@ucw.cz>
>> Cc: Len Brown <len.brown@intel.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: linux-pm@vger.kernel.org
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>
>
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Do you want this to be carried in the timers tree, or can you pick it up?

Thanks!

-Kees
Kees Cook Oct. 17, 2017, 12:30 a.m. UTC | #4
On Mon, Oct 16, 2017 at 5:15 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Tuesday, October 17, 2017 2:19:48 AM CEST Kees Cook wrote:
>> On Mon, Oct 16, 2017 at 4:53 PM, Rafael J. Wysocki
>> <rafael.j.wysocki@intel.com> wrote:
>> > On 10/17/2017 1:20 AM, Kees Cook wrote:
>> >>
>> >> In preparation for unconditionally passing the struct timer_list pointer
>> >> to
>> >> all timer callbacks, switch to using the new timer_setup() and
>> >> from_timer()
>> >> to pass the timer pointer explicitly. Removes test of .data field, since
>> >> that will be going away.
>> >>
>> >> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
>> >> Cc: Pavel Machek <pavel@ucw.cz>
>> >> Cc: Len Brown <len.brown@intel.com>
>> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> >> Cc: linux-pm@vger.kernel.org
>> >> Signed-off-by: Kees Cook <keescook@chromium.org>
>> >
>> >
>> > Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>
>> Do you want this to be carried in the timers tree, or can you pick it up?
>
> I can pick it up, but only for 4.15.

Yup, this is based on -next. Thanks!

-Kees
diff mbox

Patch

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 7bcf80fa9ada..1cea431c0adf 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -894,9 +894,9 @@  static void pm_runtime_work(struct work_struct *work)
  *
  * Check if the time is right and queue a suspend request.
  */
-static void pm_suspend_timer_fn(unsigned long data)
+static void pm_suspend_timer_fn(struct timer_list *t)
 {
-	struct device *dev = (struct device *)data;
+	struct device *dev = from_timer(dev, t, power.suspend_timer);
 	unsigned long flags;
 	unsigned long expires;
 
@@ -1499,8 +1499,7 @@  void pm_runtime_init(struct device *dev)
 	INIT_WORK(&dev->power.work, pm_runtime_work);
 
 	dev->power.timer_expires = 0;
-	setup_timer(&dev->power.suspend_timer, pm_suspend_timer_fn,
-			(unsigned long)dev);
+	timer_setup(&dev->power.suspend_timer, pm_suspend_timer_fn, 0);
 
 	init_waitqueue_head(&dev->power.wait_queue);
 }
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index cdd6f256da59..680ee1d36ac9 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -54,7 +54,7 @@  static unsigned int saved_count;
 
 static DEFINE_SPINLOCK(events_lock);
 
-static void pm_wakeup_timer_fn(unsigned long data);
+static void pm_wakeup_timer_fn(struct timer_list *t);
 
 static LIST_HEAD(wakeup_sources);
 
@@ -176,7 +176,7 @@  void wakeup_source_add(struct wakeup_source *ws)
 		return;
 
 	spin_lock_init(&ws->lock);
-	setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws);
+	timer_setup(&ws->timer, pm_wakeup_timer_fn, 0);
 	ws->active = false;
 	ws->last_time = ktime_get();
 
@@ -481,8 +481,7 @@  static bool wakeup_source_not_registered(struct wakeup_source *ws)
 	 * Use timer struct to check if the given source is initialized
 	 * by wakeup_source_add.
 	 */
-	return ws->timer.function != pm_wakeup_timer_fn ||
-		   ws->timer.data != (unsigned long)ws;
+	return ws->timer.function != (TIMER_FUNC_TYPE)pm_wakeup_timer_fn;
 }
 
 /*
@@ -724,9 +723,9 @@  EXPORT_SYMBOL_GPL(pm_relax);
  * in @data if it is currently active and its timer has not been canceled and
  * the expiration time of the timer is not in future.
  */
-static void pm_wakeup_timer_fn(unsigned long data)
+static void pm_wakeup_timer_fn(struct timer_list *t)
 {
-	struct wakeup_source *ws = (struct wakeup_source *)data;
+	struct wakeup_source *ws = from_timer(ws, t, timer);
 	unsigned long flags;
 
 	spin_lock_irqsave(&ws->lock, flags);