[PATCH v2 2/4] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool

Jianping Li posted 4 patches 3 weeks, 4 days ago
[PATCH v2 2/4] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool
Posted by Jianping Li 3 weeks, 4 days ago
From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>

The initially allocated memory is not properly included in the pool,
leading to potential issues with memory management. The issue is
actually a memory leak because the initial memory is never used by
Audio PD. It will immediately make a remote heap request as no memory is
added to the pool initially. Set the number of pages to one to ensure
that the initially allocated memory is correctly added to the Audio PD
memory pool.

Fixes: 0871561055e66 ("misc: fastrpc: Add support for audiopd")
Cc: stable@kernel.org
Co-developed-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
Signed-off-by: Jianping Li <jianping.li@oss.qualcomm.com>
---
 drivers/misc/fastrpc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 515a43c9d95d..4f12fa5a05aa 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1328,7 +1328,9 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 		err = PTR_ERR(name);
 		goto err;
 	}
-
+	inbuf.client_id = fl->client_id;
+	inbuf.namelen = init.namelen;
+	inbuf.pageslen = 0;
 	if (!fl->cctx->remote_heap) {
 		err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,
 						&fl->cctx->remote_heap);
@@ -1351,12 +1353,10 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 				goto err_map;
 			}
 			scm_done = true;
+			inbuf.pageslen = 1;
 		}
 	}
 
-	inbuf.client_id = fl->client_id;
-	inbuf.namelen = init.namelen;
-	inbuf.pageslen = 0;
 	fl->pd = USER_PD;
 
 	args[0].ptr = (u64)(uintptr_t)&inbuf;
-- 
2.43.0
Re: [PATCH v2 2/4] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool
Posted by Dmitry Baryshkov 3 weeks, 3 days ago
On Thu, Jan 15, 2026 at 04:28:49PM +0800, Jianping Li wrote:
> From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
> 
> The initially allocated memory is not properly included in the pool,
> leading to potential issues with memory management. The issue is

Define "properly" and be more explicit about "potential issues". Please
be more precise in commit messages.

> actually a memory leak because the initial memory is never used by

Why is it not used?

> Audio PD. It will immediately make a remote heap request as no memory is

Ok, you've described one issue. Beforehand it was "issues". Are there
any others? if not, please drop the "potential issues" part.

> added to the pool initially. Set the number of pages to one to ensure
> that the initially allocated memory is correctly added to the Audio PD
> memory pool.
> 
> Fixes: 0871561055e66 ("misc: fastrpc: Add support for audiopd")
> Cc: stable@kernel.org
> Co-developed-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
> Signed-off-by: Jianping Li <jianping.li@oss.qualcomm.com>
> ---
>  drivers/misc/fastrpc.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 

The patch  LGTM.

-- 
With best wishes
Dmitry
Re: [PATCH v2 2/4] misc: fastrpc: Fix initial memory allocation for Audio PD memory pool
Posted by Jianping 1 week ago

On 1/16/2026 4:45 AM, Dmitry Baryshkov wrote:
> On Thu, Jan 15, 2026 at 04:28:49PM +0800, Jianping Li wrote:
>> From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
>>
>> The initially allocated memory is not properly included in the pool,
>> leading to potential issues with memory management. The issue is
> 
> Define "properly" and be more explicit about "potential issues". Please
> be more precise in commit messages.
By “properly” I mean that the initially allocated buffer is supposed to 
be added into the Audio PD memory pool by setting pageslen accordingly.

With pageslen = 0, this buffer is never registered and therefore never 
becomes part of the pool.
I will drop the vague wording and describe the exact problem.
> 
>> actually a memory leak because the initial memory is never used by
> 
> Why is it not used?
Because pageslen = 0 indicates that no pages are provided.

As a result, Audio PD immediately issues a remote heap request, ignoring 
the initially allocated memory entirely.

That initial buffer becomes unreachable and is effectively leaked.
> 
>> Audio PD. It will immediately make a remote heap request as no memory is
> 
> Ok, you've described one issue. Beforehand it was "issues". Are there
> any others? if not, please drop the "potential issues" part.
There are no additional issues beyond the memory leak caused by the 
unused initial buffer.

I will remove the “potential issues” phrasing and state explicitly that 
the problem is a memory leak due to the initial buffer never being added 
to the pool.
> 
>> added to the pool initially. Set the number of pages to one to ensure
>> that the initially allocated memory is correctly added to the Audio PD
>> memory pool.
>>
>> Fixes: 0871561055e66 ("misc: fastrpc: Add support for audiopd")
>> Cc: stable@kernel.org
>> Co-developed-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
>> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
>> Signed-off-by: Jianping Li <jianping.li@oss.qualcomm.com>
>> ---
>>   drivers/misc/fastrpc.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
> 
> The patch  LGTM.
>