From: Charlie Jenkins <charlie@rivosinc.com>
To: "Clément Léger" <cleger@rivosinc.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Kai Zhang <zhangkai@iscas.ac.cn>,
Andrew Jones <ajones@ventanamicro.com>
Subject: Re: [PATCH v2] riscv: module: use a plain variable for list_head instead of a pointer
Date: Wed, 27 Nov 2024 11:18:32 -0800 [thread overview]
Message-ID: <Z0dwiIUThatX1H_X@ghost> (raw)
In-Reply-To: <20241127142519.3038691-1-cleger@rivosinc.com>
On Wed, Nov 27, 2024 at 03:25:17PM +0100, Clément Léger wrote:
> rel_head's list_head member, rel_entry, doesn't need to be allocated,
> its storage can just be part of the allocated rel_head. Remove the
> pointer which allows to get rid of the allocation as well as an existing
> memory leak found by Kai Zang using kmemleak.
>
> Reported-by: Kai Zhang <zhangkai@iscas.ac.cn>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Thanks for looking into this!
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
> ---
>
> V2:
> - Add Kai Reported-by
> - Reword the commit description (Andrew)
>
> ---
> arch/riscv/kernel/module.c | 18 ++++--------------
> 1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
> index 1cd461f3d872..47d0ebeec93c 100644
> --- a/arch/riscv/kernel/module.c
> +++ b/arch/riscv/kernel/module.c
> @@ -23,7 +23,7 @@ struct used_bucket {
>
> struct relocation_head {
> struct hlist_node node;
> - struct list_head *rel_entry;
> + struct list_head rel_entry;
> void *location;
> };
>
> @@ -634,7 +634,7 @@ process_accumulated_relocations(struct module *me,
> location = rel_head_iter->location;
> list_for_each_entry_safe(rel_entry_iter,
> rel_entry_iter_tmp,
> - rel_head_iter->rel_entry,
> + &rel_head_iter->rel_entry,
> head) {
> curr_type = rel_entry_iter->type;
> reloc_handlers[curr_type].reloc_handler(
> @@ -704,16 +704,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
> return -ENOMEM;
> }
>
> - rel_head->rel_entry =
> - kmalloc(sizeof(struct list_head), GFP_KERNEL);
> -
> - if (!rel_head->rel_entry) {
> - kfree(entry);
> - kfree(rel_head);
> - return -ENOMEM;
> - }
> -
> - INIT_LIST_HEAD(rel_head->rel_entry);
> + INIT_LIST_HEAD(&rel_head->rel_entry);
> rel_head->location = location;
> INIT_HLIST_NODE(&rel_head->node);
> if (!current_head->first) {
> @@ -722,7 +713,6 @@ static int add_relocation_to_accumulate(struct module *me, int type,
>
> if (!bucket) {
> kfree(entry);
> - kfree(rel_head->rel_entry);
> kfree(rel_head);
> return -ENOMEM;
> }
> @@ -735,7 +725,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
> }
>
> /* Add relocation to head of discovered rel_head */
> - list_add_tail(&entry->head, rel_head->rel_entry);
> + list_add_tail(&entry->head, &rel_head->rel_entry);
>
> return 0;
> }
> --
> 2.45.2
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Charlie Jenkins <charlie@rivosinc.com>
To: "Clément Léger" <cleger@rivosinc.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Kai Zhang <zhangkai@iscas.ac.cn>,
Andrew Jones <ajones@ventanamicro.com>
Subject: Re: [PATCH v2] riscv: module: use a plain variable for list_head instead of a pointer
Date: Wed, 27 Nov 2024 11:18:32 -0800 [thread overview]
Message-ID: <Z0dwiIUThatX1H_X@ghost> (raw)
In-Reply-To: <20241127142519.3038691-1-cleger@rivosinc.com>
On Wed, Nov 27, 2024 at 03:25:17PM +0100, Clément Léger wrote:
> rel_head's list_head member, rel_entry, doesn't need to be allocated,
> its storage can just be part of the allocated rel_head. Remove the
> pointer which allows to get rid of the allocation as well as an existing
> memory leak found by Kai Zang using kmemleak.
>
> Reported-by: Kai Zhang <zhangkai@iscas.ac.cn>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Thanks for looking into this!
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
> ---
>
> V2:
> - Add Kai Reported-by
> - Reword the commit description (Andrew)
>
> ---
> arch/riscv/kernel/module.c | 18 ++++--------------
> 1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
> index 1cd461f3d872..47d0ebeec93c 100644
> --- a/arch/riscv/kernel/module.c
> +++ b/arch/riscv/kernel/module.c
> @@ -23,7 +23,7 @@ struct used_bucket {
>
> struct relocation_head {
> struct hlist_node node;
> - struct list_head *rel_entry;
> + struct list_head rel_entry;
> void *location;
> };
>
> @@ -634,7 +634,7 @@ process_accumulated_relocations(struct module *me,
> location = rel_head_iter->location;
> list_for_each_entry_safe(rel_entry_iter,
> rel_entry_iter_tmp,
> - rel_head_iter->rel_entry,
> + &rel_head_iter->rel_entry,
> head) {
> curr_type = rel_entry_iter->type;
> reloc_handlers[curr_type].reloc_handler(
> @@ -704,16 +704,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
> return -ENOMEM;
> }
>
> - rel_head->rel_entry =
> - kmalloc(sizeof(struct list_head), GFP_KERNEL);
> -
> - if (!rel_head->rel_entry) {
> - kfree(entry);
> - kfree(rel_head);
> - return -ENOMEM;
> - }
> -
> - INIT_LIST_HEAD(rel_head->rel_entry);
> + INIT_LIST_HEAD(&rel_head->rel_entry);
> rel_head->location = location;
> INIT_HLIST_NODE(&rel_head->node);
> if (!current_head->first) {
> @@ -722,7 +713,6 @@ static int add_relocation_to_accumulate(struct module *me, int type,
>
> if (!bucket) {
> kfree(entry);
> - kfree(rel_head->rel_entry);
> kfree(rel_head);
> return -ENOMEM;
> }
> @@ -735,7 +725,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
> }
>
> /* Add relocation to head of discovered rel_head */
> - list_add_tail(&entry->head, rel_head->rel_entry);
> + list_add_tail(&entry->head, &rel_head->rel_entry);
>
> return 0;
> }
> --
> 2.45.2
>
next prev parent reply other threads:[~2024-11-27 19:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 14:25 [PATCH v2] riscv: module: use a plain variable for list_head instead of a pointer Clément Léger
2024-11-27 14:25 ` Clément Léger
2024-11-27 19:18 ` Charlie Jenkins [this message]
2024-11-27 19:18 ` Charlie Jenkins
2024-11-28 1:01 ` laokz
2024-11-28 1:01 ` laokz
2024-11-28 7:36 ` Clément Léger
2024-11-28 7:36 ` Clément Léger
2024-11-28 8:32 ` Andrew Jones
2024-11-28 8:32 ` Andrew Jones
2024-11-28 14:24 ` laokz
2024-11-28 14:24 ` laokz
2025-01-09 16:16 ` patchwork-bot+linux-riscv
2025-01-09 16:16 ` patchwork-bot+linux-riscv
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=Z0dwiIUThatX1H_X@ghost \
--to=charlie@rivosinc.com \
--cc=ajones@ventanamicro.com \
--cc=aou@eecs.berkeley.edu \
--cc=cleger@rivosinc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=zhangkai@iscas.ac.cn \
/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.