[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240628-b4-qcom-audio-lpass-codec-cleanups-v2-5-e9741143e485@linaro.org>
Date: Fri, 28 Jun 2024 12:10:59 +0200
From: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
To: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Banajit Goswami <bgoswami@...cinc.com>, Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>, Jaroslav Kysela <perex@...ex.cz>,
Takashi Iwai <tiwai@...e.com>
Cc: alsa-devel@...a-project.org, linux-arm-msm@...r.kernel.org,
linux-sound@...r.kernel.org, linux-kernel@...r.kernel.org,
Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
Subject: [PATCH v2 5/5] 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 <krzysztof.kozlowski@...aro.org>
---
Changes in v2:
1. New patch
---
sound/soc/codecs/lpass-wsa-macro.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index b4e7139bac61..73a588289408 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/io.h>
@@ -2725,8 +2726,6 @@ static const struct snd_soc_component_driver wsa_macro_component_drv = {
static int wsa_macro_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct reg_default *reg_defaults;
- struct regmap_config *reg_config;
struct wsa_macro *wsa;
kernel_ulong_t flags;
void __iomem *base;
@@ -2765,6 +2764,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
return PTR_ERR(base);
wsa->codec_version = lpass_macro_get_codec_version();
+ struct reg_default *reg_defaults __free(kfree) = NULL;
+
switch (wsa->codec_version) {
case LPASS_CODEC_VERSION_1_0:
case LPASS_CODEC_VERSION_1_1:
@@ -2773,9 +2774,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
case LPASS_CODEC_VERSION_2_1:
wsa->reg_layout = &wsa_codec_v2_1;
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_1);
- reg_defaults = devm_kmalloc_array(dev, def_count,
- sizeof(*reg_defaults),
- GFP_KERNEL);
+ reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
+ GFP_KERNEL);
if (!reg_defaults)
return -ENOMEM;
memcpy(®_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2789,9 +2789,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
case LPASS_CODEC_VERSION_2_8:
wsa->reg_layout = &wsa_codec_v2_5;
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_5);
- reg_defaults = devm_kmalloc_array(dev, def_count,
- sizeof(*reg_defaults),
- GFP_KERNEL);
+ reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
+ GFP_KERNEL);
if (!reg_defaults)
return -ENOMEM;
memcpy(®_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2804,8 +2803,9 @@ static int wsa_macro_probe(struct platform_device *pdev)
return -EINVAL;
}
- reg_config = devm_kmemdup(dev, &wsa_regmap_config,
- sizeof(*reg_config), GFP_KERNEL);
+ struct regmap_config *reg_config __free(kfree) = kmemdup(&wsa_regmap_config,
+ sizeof(*reg_config),
+ GFP_KERNEL);
if (!reg_config)
return -ENOMEM;
@@ -2816,8 +2816,6 @@ static int wsa_macro_probe(struct platform_device *pdev)
if (IS_ERR(wsa->regmap))
return PTR_ERR(wsa->regmap);
- devm_kfree(dev, reg_config);
- devm_kfree(dev, reg_defaults);
dev_set_drvdata(dev, wsa);
wsa->dev = dev;
--
2.43.0
Powered by blists - more mailing lists