Skip to content

Commit

Permalink
riscv: module: remove relocation_head rel_entry member allocation
Browse files Browse the repository at this point in the history
relocation_head's list_head member, rel_entry, doesn't need to be
allocated, its storage can just be part of the allocated relocation_head.
Remove the pointer which allows to get rid of the allocation as well as
an existing memory leak found by Kai Zhang using kmemleak.

Fixes: 8fd6c51 ("riscv: Add remaining module relocations")
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>
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
Link: https://lore.kernel.org/r/20241128081636.3620468-1-cleger@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
clementleger authored and palmer-dabbelt committed Jan 8, 2025
1 parent 498d5b1 commit 03f0b54
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions arch/riscv/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 03f0b54

Please sign in to comment.