Commit 22cb2f06 authored by Rahul Kumar's avatar Rahul Kumar Committed by Wei Liu
Browse files

Drivers: hv: Use kmalloc_array() instead of kmalloc()



Documentation/process/deprecated.rst recommends against the use of
kmalloc with dynamic size calculations due to the risk of overflow and
smaller allocation being made than the caller was expecting.

Replace kmalloc() with kmalloc_array() in hv_common.c to make the
intended allocation size clearer and avoid potential overflow issues.

The number of pages (pgcount) is bounded, so overflow is not a
practical concern here. However, using kmalloc_array() better reflects
the intent to allocate an array and improves consistency with other
allocations.

No functional change intended.

Signed-off-by: default avatarRahul Kumar <rk0006818@gmail.com>
Signed-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent 5f4b5edc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ int hv_common_cpu_init(unsigned int cpu)
	 * online and then taken offline
	 */
	if (!*inputarg) {
		mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
		mem = kmalloc_array(pgcount, HV_HYP_PAGE_SIZE, flags);
		if (!mem)
			return -ENOMEM;