[PATCH v6 2/9] greybus: operation: arm request timeout before sending

From: Ayush Singh

Date: Fri Dec 04 2026 - 05:31:37 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 | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
index a9eada39ec79..cac3b0abf62b 100644
--- a/drivers/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -786,18 +786,23 @@ int gb_operation_request_send(struct gb_operation *operation,
if (ret)
goto err_put;

- ret = gb_message_send(operation->request, gfp);
- if (ret)
- goto err_put_active;
-
+ /*
+ * 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);
+ if (ret)
+ goto err_put_active;
+
return 0;

err_put_active:
+ timer_delete_sync(&operation->timer);
gb_operation_put_active(operation);
gb_operation_put_active(operation);
err_put:

--
2.56.1