Skip to content

Commit 35a5ab8

Browse files
Baoli.Zhangvinodkoul
authored andcommitted
soundwire: use krealloc_array to prevent integer overflow
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>
1 parent 654a7ae commit 35a5ab8

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

drivers/soundwire/generic_bandwidth_allocation.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,15 @@ static int sdw_add_element_group_count(struct sdw_group *group,
308308
unsigned int *rates;
309309
unsigned int *lanes;
310310

311-
rates = krealloc(group->rates,
312-
sizeof(int) * (group->max_size + 1),
313-
GFP_KERNEL);
311+
rates = krealloc_array(group->rates, group->max_size + 1,
312+
sizeof(*group->rates), GFP_KERNEL);
314313
if (!rates)
315314
return -ENOMEM;
316315

317316
group->rates = rates;
318317

319-
lanes = krealloc(group->lanes,
320-
sizeof(int) * (group->max_size + 1),
321-
GFP_KERNEL);
318+
lanes = krealloc_array(group->lanes, group->max_size + 1,
319+
sizeof(*group->lanes), GFP_KERNEL);
322320
if (!lanes)
323321
return -ENOMEM;
324322

0 commit comments

Comments
 (0)