]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soundwire: increase group->max_size after allocation
authorBaoli.Zhang <baoli.zhang@linux.intel.com>
Wed, 6 May 2026 05:50:36 +0000 (13:50 +0800)
committerVinod Koul <vkoul@kernel.org>
Thu, 7 May 2026 07:34:38 +0000 (13:04 +0530)
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>
drivers/soundwire/generic_bandwidth_allocation.c

index f016ad088a1db0ebda9c9687a8067dec353ddad6..cd9ccbaf0e46fda492e72c0cd3fc5d41ba411dc2 100644 (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;