]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soundwire: use krealloc_array to prevent integer overflow
authorBaoli.Zhang <baoli.zhang@linux.intel.com>
Wed, 6 May 2026 05:50:37 +0000 (13:50 +0800)
committerVinod Koul <vkoul@kernel.org>
Thu, 7 May 2026 07:34:38 +0000 (13:04 +0530)
Replace the use of krealloc() with krealloc_array() in
sdw_add_element_group_count to mitigate the risk of integer overflow during
memory allocation size calculation.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Baoli.Zhang <baoli.zhang@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20260506055039.3751028-4-baoli.zhang@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/generic_bandwidth_allocation.c

index cd9ccbaf0e46fda492e72c0cd3fc5d41ba411dc2..3575d69ce1c50c3899276988557068643c36ed81 100644 (file)
@@ -308,17 +308,15 @@ static int sdw_add_element_group_count(struct sdw_group *group,
                unsigned int *rates;
                unsigned int *lanes;
 
-               rates = krealloc(group->rates,
-                                sizeof(int) * (group->max_size + 1),
-                                GFP_KERNEL);
+               rates = krealloc_array(group->rates, group->max_size + 1,
+                                      sizeof(*group->rates), GFP_KERNEL);
                if (!rates)
                        return -ENOMEM;
 
                group->rates = rates;
 
-               lanes = krealloc(group->lanes,
-                                sizeof(int) * (group->max_size + 1),
-                                GFP_KERNEL);
+               lanes = krealloc_array(group->lanes, group->max_size + 1,
+                                      sizeof(*group->lanes), GFP_KERNEL);
                if (!lanes)
                        return -ENOMEM;