[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240703-asoc-cleanup-h-v1-9-71219dfd0aef@linaro.org>
Date: Wed, 03 Jul 2024 14:11:03 +0200
From: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
To: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
Banajit Goswami <bgoswami@...cinc.com>
Cc: linux-sound@...r.kernel.org, linux-kernel@...r.kernel.org,
alsa-devel@...a-project.org, linux-arm-msm@...r.kernel.org,
Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
Subject: [PATCH 09/11] ASoC: ops: Simplify with cleanup.h
Allocate the memory with scoped/cleanup.h to reduce error handling (less
error paths) and make the code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
---
sound/soc/soc-ops.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index b27e89ff6a16..19928f098d8d 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -11,6 +11,7 @@
// with code, comments and ideas from :-
// Richard Purdie <richard@...nedhand.com>
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@@ -727,14 +728,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
struct soc_bytes *params = (void *)kcontrol->private_value;
int ret, len;
unsigned int val, mask;
- void *data;
if (!component->regmap || !params->num_regs)
return -EINVAL;
len = params->num_regs * component->val_bytes;
- data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
+ void *data __free(kfree) = kmemdup(ucontrol->value.bytes.data, len,
+ GFP_KERNEL | GFP_DMA);
if (!data)
return -ENOMEM;
@@ -746,7 +747,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
if (params->mask) {
ret = regmap_read(component->regmap, params->base, &val);
if (ret != 0)
- goto out;
+ return ret;
val &= params->mask;
@@ -760,14 +761,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
ret = regmap_parse_val(component->regmap,
&mask, &mask);
if (ret != 0)
- goto out;
+ return ret;
((u16 *)data)[0] &= mask;
ret = regmap_parse_val(component->regmap,
&val, &val);
if (ret != 0)
- goto out;
+ return ret;
((u16 *)data)[0] |= val;
break;
@@ -776,30 +777,23 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
ret = regmap_parse_val(component->regmap,
&mask, &mask);
if (ret != 0)
- goto out;
+ return ret;
((u32 *)data)[0] &= mask;
ret = regmap_parse_val(component->regmap,
&val, &val);
if (ret != 0)
- goto out;
+ return ret;
((u32 *)data)[0] |= val;
break;
default:
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
}
- ret = regmap_raw_write(component->regmap, params->base,
- data, len);
-
-out:
- kfree(data);
-
- return ret;
+ return regmap_raw_write(component->regmap, params->base, data, len);
}
EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
--
2.43.0
Powered by blists - more mailing lists