The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: tze.yee.ng@altera.com
Cc: Dinh Nguyen <dinguyen@kernel.org>, Alan Tull <atull@kernel.org>,
	Richard Gong <richard.gong@intel.com>,
	linux-kernel@vger.kernel.org,
	Adrian Ng Ho Yin <adrian.ho.yin.ng@altera.com>,
	Nazim Amirul <muhammad.nazim.amirul.nazle.asmade@altera.com>
Subject: Re: [PATCH] firmware: stratix10-svc: fix memory leaks and list corruption bugs
Date: Tue, 9 Jun 2026 12:11:18 +0200	[thread overview]
Message-ID: <2026060903-crablike-sulfide-50c2@gregkh> (raw)
In-Reply-To: <6e13c57d085f61fc97c90ab5121b6dcc5119e035.1780996415.git.tze.yee.ng@altera.com>

On Tue, Jun 09, 2026 at 02:19:44AM -0700, tze.yee.ng@altera.com wrote:
> From: Tze Yee Ng <tze.yee.ng@altera.com>
> 
> Fix a memory leak when gen_pool_alloc() fails by freeing pmem on the error
> path. Switch pmem allocation from devm_kzalloc() to kzalloc() with
> explicit kfree() in the free path to match its list-managed life time.
> Remove the erroneous list_del(&svc_data_mem) which corrupted the list head
> on failed lookups. Add NULL guards instratix10_svc_free_memory().
> 
> Fixes: 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver")
> 
> Signed-off-by: Tze Yee Ng <tze.yee.ng@altera.com>
> ---
>  drivers/firmware/stratix10-svc.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c
> index 1ef65bf845fc..3b0e2b14180f 100644
> --- a/drivers/firmware/stratix10-svc.c
> +++ b/drivers/firmware/stratix10-svc.c
> @@ -1912,14 +1912,16 @@ void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
>  	struct gen_pool *genpool = chan->ctrl->genpool;
>  	size_t s = roundup(size, 1 << genpool->min_alloc_order);
>  
> -	pmem = devm_kzalloc(chan->ctrl->dev, sizeof(*pmem), GFP_KERNEL);
> +	pmem = kzalloc_obj(*pmem);
>  	if (!pmem)
>  		return ERR_PTR(-ENOMEM);
>  
>  	guard(mutex)(&svc_mem_lock);
>  	va = gen_pool_alloc(genpool, s);
> -	if (!va)
> +	if (!va) {
> +		kfree(pmem);
>  		return ERR_PTR(-ENOMEM);
> +	}
>  
>  	memset((void *)va, 0, s);
>  	pa = gen_pool_virt_to_phys(genpool, va);
> @@ -1945,6 +1947,9 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);
>  void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr)
>  {
>  	struct stratix10_svc_data_mem *pmem;
> +
> +	if (!chan || !kaddr)
> +		return;
>  	guard(mutex)(&svc_mem_lock);
>  
>  	list_for_each_entry(pmem, &svc_data_mem, node)
> @@ -1953,10 +1958,9 @@ void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr)
>  				       (unsigned long)kaddr, pmem->size);
>  			pmem->vaddr = NULL;
>  			list_del(&pmem->node);
> +			kfree(pmem);
>  			return;
>  		}
> -
> -	list_del(&svc_data_mem);
>  }
>  EXPORT_SYMBOL_GPL(stratix10_svc_free_memory);
>  
> -- 
> 2.43.7
> 


Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an
  older released kernel, yet you do not have a cc: stable line in the
  signed-off-by area at all, which means that the patch will not be
  applied to any older kernel releases.  To properly fix this, please
  follow the documented rules in the
  Documentation/process/stable-kernel-rules.rst file for how to resolve
  this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

  reply	other threads:[~2026-06-09 10:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09  9:19 [PATCH] firmware: stratix10-svc: fix memory leaks and list corruption bugs tze.yee.ng
2026-06-09 10:11 ` Greg Kroah-Hartman [this message]
2026-06-09 10:13 ` Greg Kroah-Hartman
2026-06-10  1:47   ` NG, TZE YEE
2026-06-10  6:07     ` Greg Kroah-Hartman
2026-06-12  3:43       ` NG, TZE YEE
2026-06-12  7:54         ` Greg Kroah-Hartman
2026-06-19  3:45           ` NG, TZE YEE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026060903-crablike-sulfide-50c2@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=adrian.ho.yin.ng@altera.com \
    --cc=atull@kernel.org \
    --cc=dinguyen@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muhammad.nazim.amirul.nazle.asmade@altera.com \
    --cc=richard.gong@intel.com \
    --cc=tze.yee.ng@altera.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox