All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] staging: greybus: Convert timers to use timer_setup()
@ 2017-10-24 14:49 Kees Cook
  2017-10-24 15:54 ` Bryan O'Donoghue
  0 siblings, 1 reply; 14+ messages in thread
From: Kees Cook @ 2017-10-24 14:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Bryan O'Donoghue
  Cc: linux-kernel, Johan Hovold, Alex Elder, greybus-dev, devel

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.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: greybus-dev@lists.linaro.org
Cc: devel@driverdev.osuosl.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v2: Added back "get" in timer code, thanks to Bryan. :)
---
 drivers/staging/greybus/loopback.c  | 19 +++++++++----------
 drivers/staging/greybus/operation.c |  7 +++----
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index 08e255884206..1c0bafeb7ea5 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -572,16 +572,16 @@ static void gb_loopback_async_operation_work(struct work_struct *work)
 	gb_loopback_async_operation_put(op_async);
 }
 
-static void gb_loopback_async_operation_timeout(unsigned long data)
+static void gb_loopback_async_operation_timeout(struct timer_list *t)
 {
-	struct gb_loopback_async_operation *op_async;
-	u16 id = data;
+	struct gb_loopback_async_operation *op_async =
+		from_timer(op_async, t, timer);
+	unsigned long flags;
+
+	spin_lock_irqsave(&gb_dev.lock, flags);
+	gb_loopback_async_operation_get(op_async);
+	spin_unlock_irqrestore(&gb_dev.lock, flags);
 
-	op_async = gb_loopback_operation_find(id);
-	if (!op_async) {
-		pr_err("operation %d not found - time out ?\n", id);
-		return;
-	}
 	schedule_work(&op_async->work);
 }
 
@@ -631,8 +631,7 @@ static int gb_loopback_async_operation(struct gb_loopback *gb, int type,
 	if (ret)
 		goto error;
 
-	setup_timer(&op_async->timer, gb_loopback_async_operation_timeout,
-			(unsigned long)operation->id);
+	timer_setup(&op_async->timer, gb_loopback_async_operation_timeout, 0);
 	op_async->timer.expires = jiffies + gb->jiffy_timeout;
 	add_timer(&op_async->timer);
 
diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c
index 3023012808d9..ee4ba3f23bef 100644
--- a/drivers/staging/greybus/operation.c
+++ b/drivers/staging/greybus/operation.c
@@ -294,9 +294,9 @@ static void gb_operation_work(struct work_struct *work)
 	gb_operation_put(operation);
 }
 
-static void gb_operation_timeout(unsigned long arg)
+static void gb_operation_timeout(struct timer_list *t)
 {
-	struct gb_operation *operation = (void *)arg;
+	struct gb_operation *operation = from_timer(operation, t, timer);
 
 	if (gb_operation_result_set(operation, -ETIMEDOUT)) {
 		/*
@@ -541,8 +541,7 @@ gb_operation_create_common(struct gb_connection *connection, u8 type,
 			goto err_request;
 		}
 
-		setup_timer(&operation->timer, gb_operation_timeout,
-			    (unsigned long)operation);
+		timer_setup(&operation->timer, gb_operation_timeout, 0);
 	}
 
 	operation->flags = op_flags;
-- 
2.7.4


-- 
Kees Cook
Pixel Security

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

end of thread, other threads:[~2017-11-03 21:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-24 14:49 [PATCH v2] staging: greybus: Convert timers to use timer_setup() Kees Cook
2017-10-24 15:54 ` Bryan O'Donoghue
2017-10-30 11:32   ` Johan Hovold
2017-10-30 11:35     ` Bryan O'Donoghue
2017-10-30 11:38       ` Johan Hovold
2017-10-30 11:44         ` Bryan O'Donoghue
2017-10-30 11:48           ` Johan Hovold
2017-10-30 21:37             ` Kees Cook
2017-10-31  0:01               ` pure.logic
2017-10-31  0:05                 ` Kees Cook
2017-11-03 20:21                   ` Kees Cook
2017-11-03 21:49                     ` Bryan O'Donoghue
2017-11-03 21:49                       ` Kees Cook
2017-10-30 11:35   ` Johan Hovold

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.