Skip to content

Commit 03f0b54

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
riscv: module: remove relocation_head rel_entry member allocation
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 <[email protected]> Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Tested-by: Charlie Jenkins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 498d5b1 commit 03f0b54

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

arch/riscv/kernel/module.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct used_bucket {
2323

2424
struct relocation_head {
2525
struct hlist_node node;
26-
struct list_head *rel_entry;
26+
struct list_head rel_entry;
2727
void *location;
2828
};
2929

@@ -634,7 +634,7 @@ process_accumulated_relocations(struct module *me,
634634
location = rel_head_iter->location;
635635
list_for_each_entry_safe(rel_entry_iter,
636636
rel_entry_iter_tmp,
637-
rel_head_iter->rel_entry,
637+
&rel_head_iter->rel_entry,
638638
head) {
639639
curr_type = rel_entry_iter->type;
640640
reloc_handlers[curr_type].reloc_handler(
@@ -704,16 +704,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
704704
return -ENOMEM;
705705
}
706706

707-
rel_head->rel_entry =
708-
kmalloc(sizeof(struct list_head), GFP_KERNEL);
709-
710-
if (!rel_head->rel_entry) {
711-
kfree(entry);
712-
kfree(rel_head);
713-
return -ENOMEM;
714-
}
715-
716-
INIT_LIST_HEAD(rel_head->rel_entry);
707+
INIT_LIST_HEAD(&rel_head->rel_entry);
717708
rel_head->location = location;
718709
INIT_HLIST_NODE(&rel_head->node);
719710
if (!current_head->first) {
@@ -722,7 +713,6 @@ static int add_relocation_to_accumulate(struct module *me, int type,
722713

723714
if (!bucket) {
724715
kfree(entry);
725-
kfree(rel_head->rel_entry);
726716
kfree(rel_head);
727717
return -ENOMEM;
728718
}
@@ -735,7 +725,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
735725
}
736726

737727
/* Add relocation to head of discovered rel_head */
738-
list_add_tail(&entry->head, rel_head->rel_entry);
728+
list_add_tail(&entry->head, &rel_head->rel_entry);
739729

740730
return 0;
741731
}

0 commit comments

Comments
 (0)