[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251027123100.14551Baf-hca@linux.ibm.com>
Date: Mon, 27 Oct 2025 13:31:00 +0100
From: Heiko Carstens <hca@...ux.ibm.com>
To: 林妙倩 <linmq006@...il.com>
Cc: Alexander Gordeev <agordeev@...ux.ibm.com>,
Gerald Schaefer <gerald.schaefer@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>, linux-s390@...r.kernel.org,
linux-kernel@...r.kernel.org, bpf@...r.kernel.org,
stable@...r.kernel.org
Subject: Re: [PATCH] s390/mm: Fix memory leak in add_marker() when kvrealloc
fails
On Mon, Oct 27, 2025 at 07:53:25PM +0800, 林妙倩 wrote:
> > Care to send a new version?
>
> I'm not sure if I can make it right.
> Do you think this way can fix the leak correctly? Thanks.
>
> ```diff
> static int add_marker(unsigned long start, unsigned long end, const char *name)
> {
> - size_t oldsize, newsize;
> -
> - oldsize = markers_cnt * sizeof(*markers);
> - newsize = oldsize + 2 * sizeof(*markers);
> - if (!oldsize)
> - markers = kvmalloc(newsize, GFP_KERNEL);
> - else
> - markers = kvrealloc(markers, newsize, GFP_KERNEL);
> - if (!markers)
> - goto error;
> + struct addr_marker *new_markers;
> + size_t newsize;
> +
> + newsize = (markers_cnt + 2) * sizeof(*markers);
> + new_markers = kvrealloc(markers, newsize, GFP_KERNEL);
> + if (!new_markers)
> + return -ENOMEM;
> +
> + markers = new_markers;
> markers[markers_cnt].is_start = 1;
> markers[markers_cnt].start_address = start;
> markers[markers_cnt].size = end - start;
> @@ -312,9 +311,6 @@ static int add_marker(unsigned long start,
> unsigned long end, const char *name)
> markers[markers_cnt].name = name;
> markers_cnt++;
> return 0;
> -error:
> - markers_cnt = 0;
> - return -ENOMEM;
> }
Not exactly what I had in mind, but this looks good too.
Could you send a proper second version of your patch, please?
Thanks!
Powered by blists - more mailing lists