From 3b718fca86b98175974d37f18a28d6e02cfb350d Mon Sep 17 00:00:00 2001 From: Harsh Patel Date: Tue, 5 Aug 2025 12:36:15 +0530 Subject: [PATCH] transport: Release the Out-of-band Buffer once Read is done to reuse it. Currently Transport uses 'struct mod_transport_buffer' to manages shared payload buffer between sender and receiver. The buffer's 'status' field synchronizes the access to ensure that only one agent uses the buffer at a time. Previously, the buffer was not properly unlocked after message was read by the receiver, preventing reuse for subsequent transactions. This change updates 'transport_release_channel_lock()' to mark shared buffer as free(by setting the status bit) once the receiver has finished processing the message. This allows both sender and receiver to safely reuse the shared buffer for future data exchange. Flow: - Sender checks if the buffer is free (status[0] set). - If free, sender writes data and locks the buffer (clears status[0]). - Receiver reads and processes the message. - After processing, receiver calls `transport_release_channel_lock()` to set status[0], marking the buffer as free again. This logic applies only to out-of-band channels that uses the shared buffer. Signed-off-by: Harsh Patel --- module/transport/src/mod_transport.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/module/transport/src/mod_transport.c b/module/transport/src/mod_transport.c index 30727ad3..9a435ac0 100644 --- a/module/transport/src/mod_transport.c +++ b/module/transport/src/mod_transport.c @@ -454,6 +454,29 @@ static int transport_release_channel_lock(fwk_id_t channel_id) * transport_respond() function that releases the channel context. */ channel_ctx->locked = false; + + if (channel_ctx->config->transport_type == + MOD_TRANSPORT_CHANNEL_TRANSPORT_TYPE_OUT_BAND) { + /* + * For Out-of-band communication channels: + * After processing a message, unlock the shared buffer memory by + * marking it as free, so that other applications can reuse it. + * This enusures proper buffer management and prevents the + * resource leaks. + */ + struct mod_transport_buffer *buffer = NULL; + buffer = ((struct mod_transport_buffer *) + channel_ctx->config->out_band_mailbox_address); + + if (buffer == NULL) { + FWK_LOG_ERR( + "%s ERROR: NULL buffer in \"%s()\"", MOD_NAME, __func__); + return FWK_E_PANIC; + } + + buffer->status |= MOD_TRANSPORT_MAILBOX_STATUS_FREE_MASK; + } + return FWK_SUCCESS; } -- GitLab