[PATCH v1 3/3] soundwire: use krealloc_array to prevent integer overflow
From: Baoli.Zhang
Date: Fri Mar 20 2026 - 01:43:04 EST
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@xxxxxxxxxxxxxxx>
Signed-off-by: Baoli.Zhang <baoli.zhang@xxxxxxxxxxxxxxx>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
drivers/soundwire/generic_bandwidth_allocation.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c
index cd9ccbaf0e46f..3575d69ce1c50 100644
--- a/drivers/soundwire/generic_bandwidth_allocation.c
+++ b/drivers/soundwire/generic_bandwidth_allocation.c
@@ -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;
--
2.43.0