From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E61D3AB29B for ; Tue, 9 Jun 2026 10:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781000084; cv=none; b=hsST+p27Txei15gucyCgV6auMY+ELu2oJI9aeVjIDZr1Ko3HqGVNYtlH9YyFEsiPoGNZlUHgFkopvXXj2ImYIThLeqNfgSaPZZSIK6QapMT8n7cnRn4PN6YGty8tj2VZTVm8qhnng7JbfJoBlrGcoBs5GdIebXj6P8YH3bZSjp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781000084; c=relaxed/simple; bh=mmBRck6qw3HDiRThn0t7FRw+I6yetJilzsUBgjGPst0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XrexyxXB7vkf3c5t2wdAgvm/UarefDJuGEOEJWsZRcAKoNaAXbIuxQY58cSrZeul3PaEBD1U1rS15OkYOmE5JAiyum++nXu1+FcPSA6PL6x4IfURky0PdIOHYTprNeBOAO01l/GcaLYuguBNdHFkfLlA6Y1TN5Ya9+9FJr8Nt28= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FjEAq+fw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FjEAq+fw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 533F61F00893; Tue, 9 Jun 2026 10:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781000083; bh=x5SurVNei7qXZpnVkTio4SjbuaoFsYUCctzLpIfINmY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=FjEAq+fwVRUQoVRfBI5b5no7f1S0V3dp1PdH7Z7VN/0W2IA3irqBbqqMHIxpb4YEc avnEPZ2xgr793o9pi2HqlPcnOi4+sKzNGAk7AM738I+A0zKQM5EaEYyquFt0GMup1d MHqxS5YHOOj8eOvGqdYmB049rlOETW+bNqJlR3o8= Date: Tue, 9 Jun 2026 12:13:43 +0200 From: Greg Kroah-Hartman To: tze.yee.ng@altera.com Cc: Dinh Nguyen , Alan Tull , Richard Gong , linux-kernel@vger.kernel.org, Adrian Ng Ho Yin , Nazim Amirul Subject: Re: [PATCH] firmware: stratix10-svc: fix memory leaks and list corruption bugs Message-ID: <2026060950-blooming-scalping-0bdc@gregkh> References: <6e13c57d085f61fc97c90ab5121b6dcc5119e035.1780996415.git.tze.yee.ng@altera.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > > 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 > --- > 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; What if one is not NULL but the other is? Will you not leak memory here now? thanks, greg k-h