Skip to content

Commit 1a7b846

Browse files
krzkbroonie
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 7d996c8 commit 1a7b846

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

sound/soc/soc-ops.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// with code, comments and ideas from :-
1212
// Richard Purdie <[email protected]>
1313

14+
#include <linux/cleanup.h>
1415
#include <linux/module.h>
1516
#include <linux/moduleparam.h>
1617
#include <linux/init.h>
@@ -727,14 +728,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
727728
struct soc_bytes *params = (void *)kcontrol->private_value;
728729
int ret, len;
729730
unsigned int val, mask;
730-
void *data;
731731

732732
if (!component->regmap || !params->num_regs)
733733
return -EINVAL;
734734

735735
len = params->num_regs * component->val_bytes;
736736

737-
data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
737+
void *data __free(kfree) = kmemdup(ucontrol->value.bytes.data, len,
738+
GFP_KERNEL | GFP_DMA);
738739
if (!data)
739740
return -ENOMEM;
740741

@@ -746,7 +747,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
746747
if (params->mask) {
747748
ret = regmap_read(component->regmap, params->base, &val);
748749
if (ret != 0)
749-
goto out;
750+
return ret;
750751

751752
val &= params->mask;
752753

@@ -760,14 +761,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
760761
ret = regmap_parse_val(component->regmap,
761762
&mask, &mask);
762763
if (ret != 0)
763-
goto out;
764+
return ret;
764765

765766
((u16 *)data)[0] &= mask;
766767

767768
ret = regmap_parse_val(component->regmap,
768769
&val, &val);
769770
if (ret != 0)
770-
goto out;
771+
return ret;
771772

772773
((u16 *)data)[0] |= val;
773774
break;
@@ -776,30 +777,23 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
776777
ret = regmap_parse_val(component->regmap,
777778
&mask, &mask);
778779
if (ret != 0)
779-
goto out;
780+
return ret;
780781

781782
((u32 *)data)[0] &= mask;
782783

783784
ret = regmap_parse_val(component->regmap,
784785
&val, &val);
785786
if (ret != 0)
786-
goto out;
787+
return ret;
787788

788789
((u32 *)data)[0] |= val;
789790
break;
790791
default:
791-
ret = -EINVAL;
792-
goto out;
792+
return -EINVAL;
793793
}
794794
}
795795

796-
ret = regmap_raw_write(component->regmap, params->base,
797-
data, len);
798-
799-
out:
800-
kfree(data);
801-
802-
return ret;
796+
return regmap_raw_write(component->regmap, params->base, data, len);
803797
}
804798
EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
805799

0 commit comments

Comments
 (0)