ASoC: pcm6240: Use flexible array for config blocks
PATCH 1/1 ASoC: pcm6240: Use flexible array for config blocks
Store the per-config block pointer table in the config allocation instead of allocating it separately.
This ties the table to the config object lifetime and removes the extra allocation and free path.
--- sound/soc/codecs/pcm6240.c | 36 +++++++++++++++--------------------- sound/soc/codecs/pcm6240.h | 2 +- 2 files changed, 16 insertions(+), 22 deletions(-)
sound/soc/codecs/pcm6240.c +15 -21
@@ -1230,15 +1230,11 @@ static struct pcmdevice_config_info *pcmdevice_add_config(void *ctxt, int *status) {struct pcmdevice_priv *pcm_dev = (struct pcmdevice_priv *)ctxt; -struct pcmdevice_config_info *cfg_info; +struct pcmdevice_config_info *cfg_info =NULL ;struct pcmdevice_block_data **bk_da; +char cfg_name[64 ] = {};unsigned int config_offset =0 , i; - - cfg_info = kzalloc_obj(struct pcmdevice_config_info); -if (!cfg_info) { - *status = -ENOMEM ; - goto out; - } +unsigned int nblocks;if (pcm_dev->regbin.fw_hdr.binary_version_num >=0x105 ) {if (config_offset +64 > (int )config_size) {
@@ -1247,7 +1243,7 @@ static struct pcmdevice_config_info *pcmdevice_add_config(void *ctxt, "%s: cfg_name out of boundary\n", __func__); goto out; } -memcpy (cfg_info->cfg_name, &config_data[config_offset],64 ); +memcpy (cfg_name, &config_data[config_offset],64 ); config_offset +=64 ; }
@@ -1257,16 +1253,17 @@ static struct pcmdevice_config_info *pcmdevice_add_config(void *ctxt, __func__); goto out; } - cfg_info->nblocks = -get_unaligned_be32 (&config_data[config_offset]); + nblocks =get_unaligned_be32 (&config_data[config_offset]); config_offset +=4 ; - bk_da = cfg_info->blk_data = kzalloc_objs(struct pcmdevice_block_data *, - cfg_info->nblocks); -if (!bk_da) { + cfg_info =kzalloc_flex (*cfg_info, blk_data, nblocks); +if (!cfg_info) { *status = -ENOMEM ; goto out; } + cfg_info->nblocks = nblocks; +memcpy (cfg_info->cfg_name, cfg_name,sizeof (cfg_info->cfg_name)); + bk_da = cfg_info->blk_data; cfg_info->real_nblocks =0 ;for (i =0 ; i < cfg_info->nblocks; i++) {if (config_offset +12 > config_size) {
@@ -1449,14 +1446,11 @@ static void pcmdevice_config_info_remove(void *ctxt)for (i =0 ; i < regbin->ncfgs; i++) {if (!cfg_info[i])continue ; -if (cfg_info[i]->blk_data) { -for (j =0 ; j < (int )cfg_info[i]->real_nblocks; j++) { -if (!cfg_info[i]->blk_data[j]) -continue ; -kfree (cfg_info[i]->blk_data[j]->regdata); -kfree (cfg_info[i]->blk_data[j]); - } -kfree (cfg_info[i]->blk_data); +for (j =0 ; j < (int )cfg_info[i]->real_nblocks; j++) { +if (!cfg_info[i]->blk_data[j]) +continue ; +kfree (cfg_info[i]->blk_data[j]->regdata); +kfree (cfg_info[i]->blk_data[j]); }kfree (cfg_info[i]); }
sound/soc/codecs/pcm6240.h +1 -1
@@ -199,7 +199,7 @@ struct pcmdevice_config_info {unsigned int nblocks;unsigned int real_nblocks;unsigned char active_dev; -struct pcmdevice_block_data **blk_data; + struct pcmdevice_block_data *blk_data[] __counted_by(nblocks); };struct pcmdevice_regbin {
Signature · 1 line
2.54.0
Mark Brown
maintainerQuoted 1 line · Rosen Penev
ASoC: pcm6240: Use flexible array for config blocks
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[1/1] ASoC: pcm6240: Use flexible array for config blocks
https://git.kernel.org/broonie/sound/c/fea3df9eab74
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark