From e3ea545d516ae06c1471a8bc230b3b40a7589dc0 Mon Sep 17 00:00:00 2001 From: Ekansh Gupta Date: Fri, 22 Nov 2024 06:18:30 +0530 Subject: [PATCH] Handle session close properly Session close call is used by capability and context management functions. The handling should be in such a way that capability request should not close the device node if the PD is established. Handle session close correctly. Signed-off-by: Ekansh Gupta --- inc/fastrpc_common.h | 2 +- src/fastrpc_apps_user.c | 16 +++++++++++----- src/fastrpc_cap.c | 2 +- src/fastrpc_context.c | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/inc/fastrpc_common.h b/inc/fastrpc_common.h index 2c5e9b3f..c07749d8 100644 --- a/inc/fastrpc_common.h +++ b/inc/fastrpc_common.h @@ -167,7 +167,7 @@ int fastrpc_session_open(int domain, int *dev); /** * @brief closes the remote session/file descriptor of the fastrpc device node */ -int fastrpc_session_close(int domain); +void fastrpc_session_close(int domain, int dev); /** * @brief increments the reference count of the domain * used to identify whether there are any active remote calls for a specific domain diff --git a/src/fastrpc_apps_user.c b/src/fastrpc_apps_user.c index 7474d669..1187f554 100644 --- a/src/fastrpc_apps_user.c +++ b/src/fastrpc_apps_user.c @@ -362,12 +362,18 @@ int fastrpc_session_open(int domain, int *dev) { return AEE_ECONNREFUSED; } -int fastrpc_session_close(int domain) { - int dev = hlist[domain].dev; - - if (dev >= 0) +void fastrpc_session_close(int domain, int dev) { + if (!hlist) + return; + if ((hlist[domain].dev == INVALID_DEVICE) && + (dev != INVALID_DEVICE)) { close(dev); - return 0; + } else if ((hlist[domain].dev != INVALID_DEVICE) && + (dev == INVALID_DEVICE)) { + close(hlist[domain].dev); + hlist[domain].dev = INVALID_DEVICE; + } + return; } int fastrpc_session_get(int domain) { diff --git a/src/fastrpc_cap.c b/src/fastrpc_cap.c index da80873c..a31eb8b0 100644 --- a/src/fastrpc_cap.c +++ b/src/fastrpc_cap.c @@ -128,7 +128,7 @@ int fastrpc_get_cap(uint32_t domain, uint32_t attributeID, uint32_t *capability) bail: if(dev != -1) - fastrpc_session_close(dom); + fastrpc_session_close(dom, dev); if (nErr) { FARF(ERROR, "Warning 0x%x: %s failed to get attribute %u for domain %u (errno %s)", nErr, __func__, attributeID, domain, strerror(errno)); } diff --git a/src/fastrpc_context.c b/src/fastrpc_context.c index e37fb02e..0dfa0388 100644 --- a/src/fastrpc_context.c +++ b/src/fastrpc_context.c @@ -134,7 +134,7 @@ static int fastrpc_context_deinit(fastrpc_context *ctx) { if (!ctx->devs[i]) continue; - fastrpc_session_close(domain); + fastrpc_session_close(domain, INVALID_DEVICE); } free(ctx->devs);