Skip to content

Commit 22cb2f0

Browse files
rahul19kumar8liuw
authored andcommitted
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>
1 parent 5f4b5ed commit 22cb2f0

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/hv/hv_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ int hv_common_cpu_init(unsigned int cpu)
487487
* online and then taken offline
488488
*/
489489
if (!*inputarg) {
490-
mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
490+
mem = kmalloc_array(pgcount, HV_HYP_PAGE_SIZE, flags);
491491
if (!mem)
492492
return -ENOMEM;
493493

0 commit comments

Comments
 (0)