soundwire: increase group->max_size after allocation

Only update `group->max_size` after both allocations succeed to avoid
leaving the group's state inconsistent if one allocation fails.

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-3-baoli.zhang@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
This commit is contained in:
Baoli.Zhang 2026-05-06 13:50:36 +08:00 committed by Vinod Koul
parent f772ff5a0e
commit 654a7ae10b

View File

@ -308,9 +308,8 @@ static int sdw_add_element_group_count(struct sdw_group *group,
unsigned int *rates;
unsigned int *lanes;
group->max_size += 1;
rates = krealloc(group->rates,
(sizeof(int) * group->max_size),
sizeof(int) * (group->max_size + 1),
GFP_KERNEL);
if (!rates)
return -ENOMEM;
@ -318,12 +317,14 @@ static int sdw_add_element_group_count(struct sdw_group *group,
group->rates = rates;
lanes = krealloc(group->lanes,
(sizeof(int) * group->max_size),
sizeof(int) * (group->max_size + 1),
GFP_KERNEL);
if (!lanes)
return -ENOMEM;
group->lanes = lanes;
group->max_size += 1;
}
group->rates[group->count] = rate;