[PATCH 1/2] misc: fastrpc: create ADSP duplicate sessions before registering devices

From: Ekansh Gupta

Date: Thu Dec 03 2026 - 00:41:46 EST


fastrpc_rpmsg_probe() appends the ADSP duplicate sessions at the end of
probe, after fastrpc_device_register() has already exposed the device
nodes to userspace. This leaves a window in which:

- an open() can only be served by the real CB sessions and may fail
with all sessions in use, which is exactly what the duplicate
sessions are meant to avoid;

- the duplicates are memcpy()'d from the last session. If that session
has already been handed out, the copies are created with used = true.
fastrpc_session_free() only clears the flag of the session it is
given, so these copies can never be allocated again.

Create the duplicate sessions right after the CB devices are created
and before any device node is registered, so that the session table is
complete and unused by the time userspace can access it.

While moving the block, drop its local 'flags' declaration, which
shadowed the one already declared at function scope.

Fixes: 112dc91edd51 ("misc: fastrpc: move ADSP duplicate session creation to the driver")
Co-developed-by: Vinayak Katoch <vinayak.katoch@xxxxxxxxxxxxxxxx>
Signed-off-by: Vinayak Katoch <vinayak.katoch@xxxxxxxxxxxxxxxx>
Signed-off-by: Ekansh Gupta <ekansh.gupta@xxxxxxxxxxxxxxxx>
---
drivers/misc/fastrpc.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1dcc8602a380..cb0972722e08 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -2792,6 +2792,21 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
if (err)
goto err_free_data;

+ if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
+ struct fastrpc_session_ctx *last_sess;
+ struct fastrpc_session_ctx *dup_sess;
+
+ spin_lock_irqsave(&data->lock, flags);
+ last_sess = &data->session[data->sesscount - 1];
+ for (i = 0; i < FASTRPC_DUP_SESSIONS; i++) {
+ if (data->sesscount >= FASTRPC_MAX_SESSIONS)
+ break;
+ dup_sess = &data->session[data->sesscount++];
+ memcpy(dup_sess, last_sess, sizeof(*dup_sess));
+ }
+ spin_unlock_irqrestore(&data->lock, flags);
+ }
+
switch (domain_id) {
case ADSP_DOMAIN_ID:
case MDSP_DOMAIN_ID:
@@ -2819,22 +2834,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
goto err_depopulate;
}

- if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
- struct fastrpc_session_ctx *last_sess;
- struct fastrpc_session_ctx *dup_sess;
- unsigned long flags;
-
- spin_lock_irqsave(&data->lock, flags);
- last_sess = &data->session[data->sesscount - 1];
- for (i = 0; i < FASTRPC_DUP_SESSIONS; i++) {
- if (data->sesscount >= FASTRPC_MAX_SESSIONS)
- break;
- dup_sess = &data->session[data->sesscount++];
- memcpy(dup_sess, last_sess, sizeof(*dup_sess));
- }
- spin_unlock_irqrestore(&data->lock, flags);
- }
-
return 0;

err_deregister_fdev:

--
2.34.1