Commit 1a7b8468 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Mark Brown

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: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240703-asoc-cleanup-h-v1-9-71219dfd0aef@linaro.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 7d996c8a
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
// with code, comments and ideas from :- // with code, comments and ideas from :-
// Richard Purdie <richard@openedhand.com> // Richard Purdie <richard@openedhand.com>
#include <linux/cleanup.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -727,14 +728,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -727,14 +728,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
struct soc_bytes *params = (void *)kcontrol->private_value; struct soc_bytes *params = (void *)kcontrol->private_value;
int ret, len; int ret, len;
unsigned int val, mask; unsigned int val, mask;
void *data;
if (!component->regmap || !params->num_regs) if (!component->regmap || !params->num_regs)
return -EINVAL; return -EINVAL;
len = params->num_regs * component->val_bytes; 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) if (!data)
return -ENOMEM; return -ENOMEM;
...@@ -746,7 +747,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -746,7 +747,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
if (params->mask) { if (params->mask) {
ret = regmap_read(component->regmap, params->base, &val); ret = regmap_read(component->regmap, params->base, &val);
if (ret != 0) if (ret != 0)
goto out; return ret;
val &= params->mask; val &= params->mask;
...@@ -760,14 +761,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -760,14 +761,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&mask, &mask); &mask, &mask);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u16 *)data)[0] &= mask; ((u16 *)data)[0] &= mask;
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&val, &val); &val, &val);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u16 *)data)[0] |= val; ((u16 *)data)[0] |= val;
break; break;
...@@ -776,30 +777,23 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, ...@@ -776,30 +777,23 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&mask, &mask); &mask, &mask);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u32 *)data)[0] &= mask; ((u32 *)data)[0] &= mask;
ret = regmap_parse_val(component->regmap, ret = regmap_parse_val(component->regmap,
&val, &val); &val, &val);
if (ret != 0) if (ret != 0)
goto out; return ret;
((u32 *)data)[0] |= val; ((u32 *)data)[0] |= val;
break; break;
default: default:
ret = -EINVAL; return -EINVAL;
goto out;
} }
} }
ret = regmap_raw_write(component->regmap, params->base, return regmap_raw_write(component->regmap, params->base, data, len);
data, len);
out:
kfree(data);
return ret;
} }
EXPORT_SYMBOL_GPL(snd_soc_bytes_put); EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment