Skip to content

Commit

Permalink
ASoC: ops: Simplify with cleanup.h
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
krzk authored and broonie committed Jul 8, 2024
1 parent 7d996c8 commit 1a7b846
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions sound/soc/soc-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// with code, comments and ideas from :-
// Richard Purdie <[email protected]>

#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 1a7b846

Please sign in to comment.