linux/arch/riscv/kernel
Erick Archer 28e4748e5e
riscv: Use kcalloc() instead of kzalloc()
As noted in the "Deprecated Interfaces, Language Features, Attributes,
and Conventions" documentation [1], size calculations (especially
multiplication) should not be performed in memory allocator (or similar)
function arguments due to the risk of them overflowing. This could lead
to values wrapping around and a smaller allocation being made than the
caller was expecting. Using those allocations could lead to linear
overflows of heap memory and other misbehaviors.

So, use the purpose specific kcalloc() function instead of the argument
count * size in the kzalloc() function.

Also, it is preferred to use sizeof(*pointer) instead of sizeof(type)
due to the type of the variable can change and one needs not change the
former (unlike the latter).

Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: https://github.com/KSPP/linux/issues/162
Signed-off-by: Erick Archer <erick.archer@gmx.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20240120135400.4710-1-erick.archer@gmx.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-03-20 08:56:07 -07:00
..
compat_vdso kbuild: unify vdso_install rules 2023-10-28 21:09:02 +09:00
pi RISC-V: build: Allow LTO to be selected 2024-01-22 10:06:29 -08:00
probes riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
tests Support rv32 ULEB128 test 2023-12-06 04:08:39 -08:00
vdso RISC-V Patches for the 6.8 Merge Window, Part 1 2024-01-17 10:50:46 -08:00
.gitignore
acpi.c RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping 2023-10-26 09:40:31 -07:00
alternative.c riscv: errata: Rename defines for Andes 2024-03-12 07:13:12 -07:00
asm-offsets.c riscv: Implement Shadow Call Stack 2023-10-27 14:43:08 -07:00
cacheinfo.c RISC-V Patches for the 6.4 Merge Window, Part 1 2023-04-28 16:55:39 -07:00
cfi.c cfi: Flip headers 2023-12-15 16:25:55 -08:00
compat_signal.c
compat_syscall_table.c riscv: Implement syscall wrappers 2023-08-23 14:16:36 -07:00
copy-unaligned.h RISC-V: Probe for unaligned access speed 2023-09-01 09:06:25 -07:00
copy-unaligned.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
cpu-hotplug.c riscv: Use the same CPU operations for all CPUs 2024-01-04 15:03:07 -08:00
cpu.c Merge patch series "Linux RISC-V AIA Preparatory Series" 2023-11-08 18:57:17 -08:00
cpu_ops.c riscv: Use the same CPU operations for all CPUs 2024-01-04 15:03:07 -08:00
cpu_ops_sbi.c riscv: Remove unused members from struct cpu_operations 2024-01-04 15:03:06 -08:00
cpu_ops_spinwait.c riscv: Remove unused members from struct cpu_operations 2024-01-04 15:03:06 -08:00
cpufeature.c Merge patch series "riscv: Use Kconfig to set unaligned access speed" 2024-03-15 10:17:14 -07:00
crash_core.c kexec: drop dependency on ARCH_SUPPORTS_KEXEC from CRASH_DUMP 2023-12-12 17:20:16 -08:00
crash_dump.c
crash_save_regs.S
efi-header.S riscv: Prepare EFI header for relocatable kernels 2023-04-19 07:46:28 -07:00
efi.c riscv: Use accessors to page table entries instead of direct dereference 2023-12-20 10:48:15 -08:00
elf_kexec.c kexec_file, riscv: print out debugging message if required 2023-12-20 15:02:57 -08:00
entry.S riscv: blacklist assembly symbols for kprobe 2024-01-24 15:59:42 -08:00
fpu.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
ftrace.c riscv: ftrace: Make function graph use ftrace directly 2024-01-17 18:17:08 -08:00
head.h riscv: entry: Convert to generic entry 2023-03-23 08:47:00 -07:00
head.S Merge patch series "Fix XIP boot and make XIP testable in QEMU" 2024-01-09 20:10:39 -08:00
hibernate-asm.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
hibernate.c riscv: hibernate: remove WARN_ON in save_processor_state 2023-06-23 10:06:22 -07:00
image-vars.h efi: move screen_info into efi init code 2023-10-17 16:33:39 +02:00
irq.c Merge patch "drivers: perf: Do not broadcast to other cpus when starting a counter" 2023-11-09 06:44:13 -08:00
jump_label.c
kernel_mode_vector.c riscv: vector: allow kernel-mode Vector with preemption 2024-01-16 07:14:02 -08:00
kexec_relocate.S riscv: kexec: Cleanup riscv_kexec_relocate 2023-09-20 02:53:29 -07:00
kgdb.c
machine_kexec.c kexec_file, riscv: print out debugging message if required 2023-12-20 15:02:57 -08:00
machine_kexec_file.c
Makefile riscv: Set unaligned access speed at compile time 2024-03-13 07:30:31 -07:00
mcount-dyn.S Merge patch series "riscv: ftrace: Miscellaneous ftrace improvements" 2024-01-17 18:17:29 -08:00
mcount.S use linux/export.h rather than asm-generic/export.h 2024-01-09 20:10:40 -08:00
module-sections.c
module.c riscv: optimize ELF relocation function in riscv 2024-01-17 18:21:10 -08:00
paravirt.c RISC-V: paravirt: Implement steal-time support 2023-12-30 11:26:04 +05:30
patch.c riscv: Check if the code to patch lies in the exit section 2024-01-09 10:58:59 -08:00
perf_callchain.c
perf_regs.c
process.c riscv: vector: allow kernel-mode Vector with preemption 2024-01-16 07:14:02 -08:00
ptrace.c Merge patch series "riscv: Introduce compat-mode helpers & improve arch_get_mmap_end()" 2024-03-20 08:56:05 -07:00
reset.c
riscv_ksyms.c
sbi-ipi.c RISC-V: Allow marking IPIs as suitable for remote FENCEs 2023-04-08 11:26:24 +01:00
sbi.c RISC-V: Add SBI debug console helper routines 2024-01-10 07:04:03 -08:00
setup.c Driver core changes for 6.8-rc1 2024-01-18 09:48:40 -08:00
signal.c Merge patch series "riscv: support kernel-mode Vector" 2024-01-16 07:14:04 -08:00
smp.c riscv: Use the same CPU operations for all CPUs 2024-01-04 15:03:07 -08:00
smpboot.c RISC-V: Remove duplicated include in smpboot.c 2024-01-24 17:18:19 -08:00
soc.c
stacktrace.c
suspend.c cpuidle: RISC-V: Move few functions to arch/riscv 2024-03-19 17:51:38 -07:00
suspend_entry.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
sys_hwprobe.c riscv: Set unaligned access speed at compile time 2024-03-13 07:30:31 -07:00
sys_riscv.c riscv: hwprobe: export Zicond extension 2024-01-09 20:12:30 -08:00
syscall_table.c riscv: Implement syscall wrappers 2023-08-23 14:16:36 -07:00
time.c RISC-V: paravirt: Add skeleton for pv-time support 2023-12-30 11:25:03 +05:30
traps.c riscv: Support RANDOMIZE_KSTACK_OFFSET 2024-01-24 17:24:24 -08:00
traps_misaligned.c riscv: Set unaligned access speed at compile time 2024-03-13 07:30:31 -07:00
unaligned_access_speed.c riscv: Use kcalloc() instead of kzalloc() 2024-03-20 08:56:07 -07:00
vdso.c riscv: vdso: include vdso/vsyscall.h for vdso_data 2023-07-04 07:54:41 -07:00
vector.c riscv: vector: allow kernel-mode Vector with preemption 2024-01-16 07:14:02 -08:00
vmlinux-xip.lds.S riscv: Check if the code to patch lies in the exit section 2024-01-09 10:58:59 -08:00
vmlinux.lds.S riscv: Check if the code to patch lies in the exit section 2024-01-09 10:58:59 -08:00