From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: Michail Tatas <michail.tatas@gmail.com>,
maddy@linux.ibm.com, mpe@ellerman.id.au, chleroy@kernel.org,
atrajeev@linux.ibm.com, npiggin@gmail.com
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/pseries/htmdump: Fix leak in htmdump_init_debugfs
Date: Wed, 05 Aug 2026 07:24:01 +0530 [thread overview]
Message-ID: <1pcdmix2.ritesh.list@gmail.com> (raw)
In-Reply-To: <anJDq-JckR6j-6EJ@michalis-linux>
Michail Tatas <michail.tatas@gmail.com> writes:
> If any allocation fails during init all previous allocations are
> leaked and the debugfs directory is left.
> Fix by freeing the allocations that have already happened and also
> remove the directory that has been created.
>
> Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
> ---
> arch/powerpc/platforms/pseries/htmdump.c | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/htmdump.c b/arch/powerpc/platforms/pseries/htmdump.c
> index 489a80e87082..f33941b80ada 100644
> --- a/arch/powerpc/platforms/pseries/htmdump.c
> +++ b/arch/powerpc/platforms/pseries/htmdump.c
> @@ -527,28 +527,28 @@ static int htmdump_init_debugfs(void)
> htm_status_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!htm_status_buf) {
> pr_err("Failed to allocate htmstatus buf\n");
> - return -ENOMEM;
> + goto htm_status_buf_err;
> }
>
> /* Debugfs interface file to present System Processor Configuration */
> htm_info_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!htm_info_buf) {
> pr_err("Failed to allocate htm info buf\n");
> - return -ENOMEM;
> + goto htm_info_buf_err;
> }
>
> /* Debugfs interface file to present HTM capabilities */
> htm_caps_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!htm_caps_buf) {
> pr_err("Failed to allocate htm caps buf\n");
> - return -ENOMEM;
> + goto htm_caps_buf_err;
> }
>
> /* Memory to present HTM system memory configuration */
> htm_mem_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!htm_mem_buf) {
> pr_err("Failed to allocate htm mem buf\n");
> - return -ENOMEM;
> + goto htm_mem_buf_err;
> }
>
> debugfs_create_file("htmstatus", 0400, htmdump_debugfs_dir, htm_status_buf, &htmstatus_fops);
> @@ -557,6 +557,17 @@ static int htmdump_init_debugfs(void)
> debugfs_create_file("htmsystem_mem", 0400, htmdump_debugfs_dir, htm_mem_buf, &htmsystem_mem_fops);
>
> return 0;
> +
> +htm_mem_buf_err:
> + kfree(htm_caps_buf);
> +htm_caps_buf_err:
> + kfree(htm_info_buf);
> +htm_info_buf_err:
> + kfree(htm_status_buf);
> +htm_status_buf_err:
> + debugfs_remove_recursive(htmdump_debugfs_dir);
> + kfree(htm_buf);
> + return -ENOMEM;
> }
So far the only error this function returns is -ENOMEM, so this looks
ok. Later if someone adds a different error return value, then it should
introduce a new ret variable and we should return ret from here.
But as for this patch - this looks good to me. So please feel free to add:
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
prev parent reply other threads:[~2026-08-05 1:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 19:55 [PATCH] powerpc/pseries/htmdump: Fix leak in htmdump_init_debugfs Michail Tatas
2026-08-05 1:54 ` Ritesh Harjani [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=1pcdmix2.ritesh.list@gmail.com \
--to=ritesh.list@gmail.com \
--cc=atrajeev@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=michail.tatas@gmail.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.