ASoC: tegra: ADX: simplify probe allocation
Subsystems (3)
PATCH 1/1 ASoC: tegra: ADX: simplify probe allocation
Reduce 3 allocations to one using a flexible array member.
Also use of_device_get_match_data. No error checking since it cannot be NULL.
Signed-off-by Rosen Penev <[email protected]>
--- sound/soc/tegra/tegra210_adx.c | 24 ++++++++---------------- sound/soc/tegra/tegra210_adx.h | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-)
sound/soc/tegra/tegra210_adx.c +8 -16
@@ -676,17 +676,20 @@ static int tegra210_adx_platform_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct tegra210_adx *adx; -const struct of_device_id *match; -struct tegra210_adx_soc_data *soc_data; +const struct tegra210_adx_soc_data *soc_data;void __iomem *regs; +size_t alloc_size;int err; - adx =devm_kzalloc (dev,sizeof (*adx),GFP_KERNEL ); + soc_data =of_device_get_match_data (&pdev->dev); + alloc_size =struct_size (adx, map, soc_data->ram_depth); + alloc_size +=sizeof (u32) * soc_data->byte_mask_size; + + adx =devm_kzalloc (dev, alloc_size,GFP_KERNEL );if (!adx)return -ENOMEM ; - match =of_match_device (tegra210_adx_of_match, dev); - soc_data = (struct tegra210_adx_soc_data *)match->data; + adx->byte_mask = adx->map + soc_data->ram_depth; adx->soc_data = soc_data;dev_set_drvdata (dev, adx);
@@ -703,17 +706,6 @@ static int tegra210_adx_platform_probe(struct platform_device *pdev)regcache_cache_only (adx->regmap, true); - adx->map =devm_kzalloc (dev, soc_data->ram_depth *sizeof (*adx->map), -GFP_KERNEL ); -if (!adx->map) -return -ENOMEM ; - - adx->byte_mask =devm_kzalloc (dev, - soc_data->byte_mask_size *sizeof (*adx->byte_mask), -GFP_KERNEL ); -if (!adx->byte_mask) -return -ENOMEM ; - tegra210_adx_dais[TEGRA_ADX_IN_DAI_ID ].playback.channels_max = adx->soc_data->max_ch;
sound/soc/tegra/tegra210_adx.h +1 -1
@@ -88,9 +88,9 @@ struct tegra210_adx_soc_data {struct tegra210_adx {struct regmap *regmap; -unsigned int *map;unsigned int *byte_mask;const struct tegra210_adx_soc_data *soc_data; +unsigned int map[]; };#endif
Signature · 1 line
2.54.0
Jon Hunter
maintainerQuoted 4 lines · Rosen Penev
Reduce 3 allocations to one using a flexible array member.
Also use
of_device_get_match_data. No error checking since it cannot be NULL.
Sounds like that should be a separate patch. A patch should do one thing.
Jon
Signature · 1 line
nvpublic