Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Rahul Kumar <rk0006818@gmail.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Rahul Kumar and committed by
Wei Liu
22cb2f06 5f4b5edc

+1 -1
+1 -1
drivers/hv/hv_common.c
··· 487 487 * online and then taken offline 488 488 */ 489 489 if (!*inputarg) { 490 - mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags); 490 + mem = kmalloc_array(pgcount, HV_HYP_PAGE_SIZE, flags); 491 491 if (!mem) 492 492 return -ENOMEM; 493 493