Skip to content

Commit ecaec47

Browse files
committed
ASoC: codecs: lpass-rx-macro: Few code cleanups
Merge series from Krzysztof Kozlowski <[email protected]>: Improve a bit the Qualcomm LPASS RX macro driver and align similar parts of code with LPASS WSA macro driver for consistency. No external dependencies.
2 parents cabf0b0 + 67820eb commit ecaec47

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

include/sound/soc-dapm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
457457
int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
458458
struct snd_ctl_elem_value *uncontrol);
459459
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
460-
const struct snd_soc_dapm_widget *widget, int num);
460+
const struct snd_soc_dapm_widget *widget, unsigned int num);
461461
struct snd_soc_dapm_widget *snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
462462
const struct snd_soc_dapm_widget *widget);
463463
struct snd_soc_dapm_widget *snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,

sound/soc/codecs/lpass-macro-common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ void lpass_macro_pds_exit(struct lpass_macro *pds);
4141
void lpass_macro_set_codec_version(enum lpass_codec_version version);
4242
enum lpass_codec_version lpass_macro_get_codec_version(void);
4343

44+
static inline void lpass_macro_pds_exit_action(void *pds)
45+
{
46+
lpass_macro_pds_exit(pds);
47+
}
48+
4449
static inline const char *lpass_macro_get_codec_version_string(int version)
4550
{
4651
switch (version) {

sound/soc/codecs/lpass-rx-macro.c

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
33

4+
#include <linux/cleanup.h>
45
#include <linux/module.h>
56
#include <linux/init.h>
67
#include <linux/io.h>
@@ -1662,7 +1663,7 @@ static bool rx_is_readable_register(struct device *dev, unsigned int reg)
16621663
return rx_is_rw_register(dev, reg);
16631664
}
16641665

1665-
static struct regmap_config rx_regmap_config = {
1666+
static const struct regmap_config rx_regmap_config = {
16661667
.name = "rx_macro",
16671668
.reg_bits = 16,
16681669
.val_bits = 32, /* 8 but with 32 bit read/write */
@@ -3611,8 +3612,8 @@ static int rx_macro_component_probe(struct snd_soc_component *component)
36113612
struct rx_macro *rx = snd_soc_component_get_drvdata(component);
36123613
const struct snd_soc_dapm_widget *widgets;
36133614
const struct snd_kcontrol_new *controls;
3614-
unsigned int num_controls;
3615-
int ret, num_widgets;
3615+
unsigned int num_controls, num_widgets;
3616+
int ret;
36163617

36173618
snd_soc_component_init_regmap(component, rx->regmap);
36183619

@@ -3764,7 +3765,6 @@ static const struct snd_soc_component_driver rx_macro_component_drv = {
37643765

37653766
static int rx_macro_probe(struct platform_device *pdev)
37663767
{
3767-
struct reg_default *reg_defaults;
37683768
struct device *dev = &pdev->dev;
37693769
kernel_ulong_t flags;
37703770
struct rx_macro *rx;
@@ -3803,12 +3803,17 @@ static int rx_macro_probe(struct platform_device *pdev)
38033803
if (IS_ERR(rx->pds))
38043804
return PTR_ERR(rx->pds);
38053805

3806+
ret = devm_add_action_or_reset(dev, lpass_macro_pds_exit_action, rx->pds);
3807+
if (ret)
3808+
return ret;
3809+
38063810
base = devm_platform_ioremap_resource(pdev, 0);
3807-
if (IS_ERR(base)) {
3808-
ret = PTR_ERR(base);
3809-
goto err;
3810-
}
3811+
if (IS_ERR(base))
3812+
return PTR_ERR(base);
3813+
38113814
rx->codec_version = lpass_macro_get_codec_version();
3815+
struct reg_default *reg_defaults __free(kfree) = NULL;
3816+
38123817
switch (rx->codec_version) {
38133818
case LPASS_CODEC_VERSION_1_0:
38143819
case LPASS_CODEC_VERSION_1_1:
@@ -3818,10 +3823,8 @@ static int rx_macro_probe(struct platform_device *pdev)
38183823
rx->rxn_reg_stride = 0x80;
38193824
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_pre_2_5_defaults);
38203825
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
3821-
if (!reg_defaults) {
3822-
ret = -ENOMEM;
3823-
goto err;
3824-
}
3826+
if (!reg_defaults)
3827+
return -ENOMEM;
38253828
memcpy(&reg_defaults[0], rx_defaults, sizeof(rx_defaults));
38263829
memcpy(&reg_defaults[ARRAY_SIZE(rx_defaults)],
38273830
rx_pre_2_5_defaults, sizeof(rx_pre_2_5_defaults));
@@ -3833,28 +3836,29 @@ static int rx_macro_probe(struct platform_device *pdev)
38333836
rx->rxn_reg_stride = 0xc0;
38343837
def_count = ARRAY_SIZE(rx_defaults) + ARRAY_SIZE(rx_2_5_defaults);
38353838
reg_defaults = kmalloc_array(def_count, sizeof(struct reg_default), GFP_KERNEL);
3836-
if (!reg_defaults) {
3837-
ret = -ENOMEM;
3838-
goto err;
3839-
}
3839+
if (!reg_defaults)
3840+
return -ENOMEM;
38403841
memcpy(&reg_defaults[0], rx_defaults, sizeof(rx_defaults));
38413842
memcpy(&reg_defaults[ARRAY_SIZE(rx_defaults)],
38423843
rx_2_5_defaults, sizeof(rx_2_5_defaults));
38433844
break;
38443845
default:
38453846
dev_err(dev, "Unsupported Codec version (%d)\n", rx->codec_version);
3846-
ret = -EINVAL;
3847-
goto err;
3847+
return -EINVAL;
38483848
}
38493849

3850-
rx_regmap_config.reg_defaults = reg_defaults;
3851-
rx_regmap_config.num_reg_defaults = def_count;
3850+
struct regmap_config *reg_config __free(kfree) = kmemdup(&rx_regmap_config,
3851+
sizeof(*reg_config),
3852+
GFP_KERNEL);
3853+
if (!reg_config)
3854+
return -ENOMEM;
38523855

3853-
rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
3854-
if (IS_ERR(rx->regmap)) {
3855-
ret = PTR_ERR(rx->regmap);
3856-
goto err_ver;
3857-
}
3856+
reg_config->reg_defaults = reg_defaults;
3857+
reg_config->num_reg_defaults = def_count;
3858+
3859+
rx->regmap = devm_regmap_init_mmio(dev, base, reg_config);
3860+
if (IS_ERR(rx->regmap))
3861+
return PTR_ERR(rx->regmap);
38583862

38593863
dev_set_drvdata(dev, rx);
38603864

@@ -3866,7 +3870,7 @@ static int rx_macro_probe(struct platform_device *pdev)
38663870

38673871
ret = clk_prepare_enable(rx->macro);
38683872
if (ret)
3869-
goto err_ver;
3873+
return ret;
38703874

38713875
ret = clk_prepare_enable(rx->dcodec);
38723876
if (ret)
@@ -3912,7 +3916,6 @@ static int rx_macro_probe(struct platform_device *pdev)
39123916
if (ret)
39133917
goto err_clkout;
39143918

3915-
kfree(reg_defaults);
39163919
return 0;
39173920

39183921
err_clkout:
@@ -3925,10 +3928,6 @@ static int rx_macro_probe(struct platform_device *pdev)
39253928
clk_disable_unprepare(rx->dcodec);
39263929
err_dcodec:
39273930
clk_disable_unprepare(rx->macro);
3928-
err_ver:
3929-
kfree(reg_defaults);
3930-
err:
3931-
lpass_macro_pds_exit(rx->pds);
39323931

39333932
return ret;
39343933
}
@@ -3942,8 +3941,6 @@ static void rx_macro_remove(struct platform_device *pdev)
39423941
clk_disable_unprepare(rx->fsgen);
39433942
clk_disable_unprepare(rx->macro);
39443943
clk_disable_unprepare(rx->dcodec);
3945-
3946-
lpass_macro_pds_exit(rx->pds);
39473944
}
39483945

39493946
static const struct of_device_id rx_macro_dt_match[] = {

sound/soc/codecs/lpass-wsa-macro.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
33

4+
#include <linux/cleanup.h>
45
#include <linux/module.h>
56
#include <linux/init.h>
67
#include <linux/io.h>
@@ -2725,8 +2726,6 @@ static const struct snd_soc_component_driver wsa_macro_component_drv = {
27252726
static int wsa_macro_probe(struct platform_device *pdev)
27262727
{
27272728
struct device *dev = &pdev->dev;
2728-
struct reg_default *reg_defaults;
2729-
struct regmap_config *reg_config;
27302729
struct wsa_macro *wsa;
27312730
kernel_ulong_t flags;
27322731
void __iomem *base;
@@ -2765,6 +2764,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
27652764
return PTR_ERR(base);
27662765

27672766
wsa->codec_version = lpass_macro_get_codec_version();
2767+
struct reg_default *reg_defaults __free(kfree) = NULL;
2768+
27682769
switch (wsa->codec_version) {
27692770
case LPASS_CODEC_VERSION_1_0:
27702771
case LPASS_CODEC_VERSION_1_1:
@@ -2773,9 +2774,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
27732774
case LPASS_CODEC_VERSION_2_1:
27742775
wsa->reg_layout = &wsa_codec_v2_1;
27752776
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_1);
2776-
reg_defaults = devm_kmalloc_array(dev, def_count,
2777-
sizeof(*reg_defaults),
2778-
GFP_KERNEL);
2777+
reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
2778+
GFP_KERNEL);
27792779
if (!reg_defaults)
27802780
return -ENOMEM;
27812781
memcpy(&reg_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2789,9 +2789,8 @@ static int wsa_macro_probe(struct platform_device *pdev)
27892789
case LPASS_CODEC_VERSION_2_8:
27902790
wsa->reg_layout = &wsa_codec_v2_5;
27912791
def_count = ARRAY_SIZE(wsa_defaults) + ARRAY_SIZE(wsa_defaults_v2_5);
2792-
reg_defaults = devm_kmalloc_array(dev, def_count,
2793-
sizeof(*reg_defaults),
2794-
GFP_KERNEL);
2792+
reg_defaults = kmalloc_array(def_count, sizeof(*reg_defaults),
2793+
GFP_KERNEL);
27952794
if (!reg_defaults)
27962795
return -ENOMEM;
27972796
memcpy(&reg_defaults[0], wsa_defaults, sizeof(wsa_defaults));
@@ -2804,8 +2803,9 @@ static int wsa_macro_probe(struct platform_device *pdev)
28042803
return -EINVAL;
28052804
}
28062805

2807-
reg_config = devm_kmemdup(dev, &wsa_regmap_config,
2808-
sizeof(*reg_config), GFP_KERNEL);
2806+
struct regmap_config *reg_config __free(kfree) = kmemdup(&wsa_regmap_config,
2807+
sizeof(*reg_config),
2808+
GFP_KERNEL);
28092809
if (!reg_config)
28102810
return -ENOMEM;
28112811

@@ -2816,8 +2816,6 @@ static int wsa_macro_probe(struct platform_device *pdev)
28162816
if (IS_ERR(wsa->regmap))
28172817
return PTR_ERR(wsa->regmap);
28182818

2819-
devm_kfree(dev, reg_config);
2820-
devm_kfree(dev, reg_defaults);
28212819
dev_set_drvdata(dev, wsa);
28222820

28232821
wsa->dev = dev;

sound/soc/soc-dapm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3857,7 +3857,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
38573857
*/
38583858
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
38593859
const struct snd_soc_dapm_widget *widget,
3860-
int num)
3860+
unsigned int num)
38613861
{
38623862
int i;
38633863
int ret = 0;

0 commit comments

Comments
 (0)