Skip to content

Commit 67820eb

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: lpass-wsa-macro: Simplify with cleanup.h
Driver's probe() has two allocations which are needed only within the probe() itself - for devm_regmap_init_mmio(). Usage of devm interface is a bit misleading here, because these can be freed right after each scope finishes. This makes the code a bit more obvious and self documenting. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/20240701-b4-qcom-audio-lpass-codec-cleanups-v3-6-6d98d4dd1ef5@linaro.org Signed-off-by: Mark Brown <[email protected]>
1 parent c72585d commit 67820eb

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

sound/soc/codecs/lpass-wsa-macro.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
33

4+
#include <linux/cleanup.h>
45
#include <linux/module.h>
56
#include <linux/init.h>
67
#include <linux/io.h>
@@ -2725,8 +2726,6 @@ static const struct snd_soc_component_driver wsa_macro_component_drv = {
27252726
static int wsa_macro_probe(struct platform_device *pdev)
27262727
{
27272728
struct device *dev = &pdev->dev;
2728-
struct reg_default *reg_defaults;
2729-
struct regmap_config *reg_config;
27302729
struct wsa_macro *wsa;
27312730
kernel_ulong_t flags;
27322731
void __iomem *base;
@@ -2765,6 +2764,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
27652764
return PTR_ERR(base);
27662765

27672766
wsa->codec_version = lpass_macro_get_codec_version();
2767+
struct reg_default *reg_defaults __free(kfree) = NULL;
2768+
27682769
switch (wsa->codec_version) {
27692770
case LPASS_CODEC_VERSION_1_0:
27702771
case LPASS_CODEC_VERSION_1_1:
@@ -2773,9 +2774,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
27732774
case LPASS_CODEC_VERSION_2_1:
27742775
wsa->reg_layout = &wsa_codec_v2_1;
27752776
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_1);
2776-
reg_defaults = devm_kmalloc_array(dev, def_count,
2777-
sizeof(*reg_defaults),
2778-
GFP_KERNEL);
2777+
reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
2778+
GFP_KERNEL);
27792779
if (!reg_defaults)
27802780
return -ENOMEM;
27812781
memcpy(&reg_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2789,9 +2789,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
27892789
case LPASS_CODEC_VERSION_2_8:
27902790
wsa->reg_layout = &wsa_codec_v2_5;
27912791
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_5);
2792-
reg_defaults = devm_kmalloc_array(dev, def_count,
2793-
sizeof(*reg_defaults),
2794-
GFP_KERNEL);
2792+
reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
2793+
GFP_KERNEL);
27952794
if (!reg_defaults)
27962795
return -ENOMEM;
27972796
memcpy(&reg_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2804,8 +2803,9 @@ static int wsa_macro_probe(struct platform_device *pdev)
28042803
return -EINVAL;
28052804
}
28062805

2807-
reg_config = devm_kmemdup(dev, &wsa_regmap_config,
2808-
sizeof(*reg_config), GFP_KERNEL);
2806+
struct regmap_config *reg_config __free(kfree) = kmemdup(&wsa_regmap_config,
2807+
sizeof(*reg_config),
2808+
GFP_KERNEL);
28092809
if (!reg_config)
28102810
return -ENOMEM;
28112811

@@ -2816,8 +2816,6 @@ static int wsa_macro_probe(struct platform_device *pdev)
28162816
if (IS_ERR(wsa->regmap))
28172817
return PTR_ERR(wsa->regmap);
28182818

2819-
devm_kfree(dev, reg_config);
2820-
devm_kfree(dev, reg_defaults);
28212819
dev_set_drvdata(dev, wsa);
28222820

28232821
wsa->dev = dev;

0 commit comments

Comments
 (0)