From: Heiko Carstens <hca@linux.ibm.com>
To: 林妙倩 <linmq006@gmail.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] s390/mm: Fix memory leak in add_marker() when kvrealloc fails
Date: Mon, 27 Oct 2025 13:31:00 +0100 [thread overview]
Message-ID: <20251027123100.14551Baf-hca@linux.ibm.com> (raw)
In-Reply-To: <CAH-r-ZG8vP=6qH42ew26BMBL9dRB3OtLUeFmMmKXzp1tnKvkxQ@mail.gmail.com>
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!
prev parent reply other threads:[~2025-10-27 12:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-26 9:13 [PATCH] s390/mm: Fix memory leak in add_marker() when kvrealloc fails Miaoqian Lin
2025-10-27 10:14 ` Heiko Carstens
2025-10-27 11:53 ` 林妙倩
2025-10-27 12:31 ` Heiko Carstens [this message]
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=20251027123100.14551Baf-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=linmq006@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=svens@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).