Skip to content

Commit

Permalink
riscv: Use kvmalloc_array on relocation_hashtable
Browse files Browse the repository at this point in the history
The number of relocations may be a huge value that is unallocatable
by kmalloc. Use kvmalloc instead so that it does not fail.

Fixes: 8fd6c51 ("riscv: Add remaining module relocations")
Suggested-by: Clément Léger <cleger@rivosinc.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Will Pierce <wgpierce17@gmail.com>
Link: https://lore.kernel.org/r/20250402081426.5197-1-wgpierce17@gmail.com
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
  • Loading branch information
Will Pierce authored and Alexandre Ghiti committed Apr 7, 2025
1 parent 0af2f6b commit 8578b2f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions arch/riscv/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ process_accumulated_relocations(struct module *me,
kfree(bucket_iter);
}

kfree(*relocation_hashtable);
kvfree(*relocation_hashtable);
}

static int add_relocation_to_accumulate(struct module *me, int type,
Expand Down Expand Up @@ -752,9 +752,10 @@ initialize_relocation_hashtable(unsigned int num_relocations,

hashtable_size <<= should_double_size;

*relocation_hashtable = kmalloc_array(hashtable_size,
sizeof(**relocation_hashtable),
GFP_KERNEL);
/* Number of relocations may be large, so kvmalloc it */
*relocation_hashtable = kvmalloc_array(hashtable_size,
sizeof(**relocation_hashtable),
GFP_KERNEL);
if (!*relocation_hashtable)
return 0;

Expand Down

0 comments on commit 8578b2f

Please sign in to comment.