[PATCH v5 3/9] greybus: operation: arm request timeout before sending
From: Ayush Singh
Date: Tue Nov 03 2026 - 12:11:15 EST
The host driver can complete a request before add_timer is called. The
main case for this is softsvc, although, depending on which transport
is used, there is a possibility that response arrives much faster than
expected.
By populating timer earilier, we prevent the starting a timer on
already completed request (which would then leak an active timer on cleanup).
Signed-off-by: Ayush Singh <ayush@xxxxxxxxxxxxxxx>
---
drivers/greybus/operation.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
index a63bc2eb164e..2d37acedf36f 100644
--- a/drivers/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -782,20 +782,25 @@ int gb_operation_request_send(struct gb_operation *operation,
return 0;
}
+ /*
+ * Arm the timeout before sending: the response can arrive, and the
+ * operation complete, before the host driver returns.
+ */
+ if (timeout) {
+ operation->timer.expires = jiffies + msecs_to_jiffies(timeout);
+ add_timer(&operation->timer);
+ }
+
ret = gb_message_send(operation->request, gfp);
gb_operation_put_active(operation);
gb_operation_put(operation);
if (ret)
goto err_put_active;
- if (timeout) {
- operation->timer.expires = jiffies + msecs_to_jiffies(timeout);
- add_timer(&operation->timer);
- }
-
return 0;
err_put_active:
+ timer_delete_sync(&operation->timer);
gb_operation_put_active(operation);
err_put:
gb_operation_put(operation);
--
2.56.0