1
1
// SPDX-License-Identifier: GPL-2.0-only
2
2
// Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
3
3
4
+ #include <linux/cleanup.h>
4
5
#include <linux/module.h>
5
6
#include <linux/init.h>
6
7
#include <linux/io.h>
@@ -1662,7 +1663,7 @@ static bool rx_is_readable_register(struct device *dev, unsigned int reg)
1662
1663
return rx_is_rw_register (dev , reg );
1663
1664
}
1664
1665
1665
- static struct regmap_config rx_regmap_config = {
1666
+ static const struct regmap_config rx_regmap_config = {
1666
1667
.name = "rx_macro" ,
1667
1668
.reg_bits = 16 ,
1668
1669
.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)
3611
3612
struct rx_macro * rx = snd_soc_component_get_drvdata (component );
3612
3613
const struct snd_soc_dapm_widget * widgets ;
3613
3614
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 ;
3616
3617
3617
3618
snd_soc_component_init_regmap (component , rx -> regmap );
3618
3619
@@ -3764,7 +3765,6 @@ static const struct snd_soc_component_driver rx_macro_component_drv = {
3764
3765
3765
3766
static int rx_macro_probe (struct platform_device * pdev )
3766
3767
{
3767
- struct reg_default * reg_defaults ;
3768
3768
struct device * dev = & pdev -> dev ;
3769
3769
kernel_ulong_t flags ;
3770
3770
struct rx_macro * rx ;
@@ -3803,12 +3803,17 @@ static int rx_macro_probe(struct platform_device *pdev)
3803
3803
if (IS_ERR (rx -> pds ))
3804
3804
return PTR_ERR (rx -> pds );
3805
3805
3806
+ ret = devm_add_action_or_reset (dev , lpass_macro_pds_exit_action , rx -> pds );
3807
+ if (ret )
3808
+ return ret ;
3809
+
3806
3810
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
+
3811
3814
rx -> codec_version = lpass_macro_get_codec_version ();
3815
+ struct reg_default * reg_defaults __free (kfree ) = NULL ;
3816
+
3812
3817
switch (rx -> codec_version ) {
3813
3818
case LPASS_CODEC_VERSION_1_0 :
3814
3819
case LPASS_CODEC_VERSION_1_1 :
@@ -3818,10 +3823,8 @@ static int rx_macro_probe(struct platform_device *pdev)
3818
3823
rx -> rxn_reg_stride = 0x80 ;
3819
3824
def_count = ARRAY_SIZE (rx_defaults ) + ARRAY_SIZE (rx_pre_2_5_defaults );
3820
3825
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 ;
3825
3828
memcpy (& reg_defaults [0 ], rx_defaults , sizeof (rx_defaults ));
3826
3829
memcpy (& reg_defaults [ARRAY_SIZE (rx_defaults )],
3827
3830
rx_pre_2_5_defaults , sizeof (rx_pre_2_5_defaults ));
@@ -3833,28 +3836,29 @@ static int rx_macro_probe(struct platform_device *pdev)
3833
3836
rx -> rxn_reg_stride = 0xc0 ;
3834
3837
def_count = ARRAY_SIZE (rx_defaults ) + ARRAY_SIZE (rx_2_5_defaults );
3835
3838
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 ;
3840
3841
memcpy (& reg_defaults [0 ], rx_defaults , sizeof (rx_defaults ));
3841
3842
memcpy (& reg_defaults [ARRAY_SIZE (rx_defaults )],
3842
3843
rx_2_5_defaults , sizeof (rx_2_5_defaults ));
3843
3844
break ;
3844
3845
default :
3845
3846
dev_err (dev , "Unsupported Codec version (%d)\n" , rx -> codec_version );
3846
- ret = - EINVAL ;
3847
- goto err ;
3847
+ return - EINVAL ;
3848
3848
}
3849
3849
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 ;
3852
3855
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 );
3858
3862
3859
3863
dev_set_drvdata (dev , rx );
3860
3864
@@ -3866,7 +3870,7 @@ static int rx_macro_probe(struct platform_device *pdev)
3866
3870
3867
3871
ret = clk_prepare_enable (rx -> macro );
3868
3872
if (ret )
3869
- goto err_ver ;
3873
+ return ret ;
3870
3874
3871
3875
ret = clk_prepare_enable (rx -> dcodec );
3872
3876
if (ret )
@@ -3912,7 +3916,6 @@ static int rx_macro_probe(struct platform_device *pdev)
3912
3916
if (ret )
3913
3917
goto err_clkout ;
3914
3918
3915
- kfree (reg_defaults );
3916
3919
return 0 ;
3917
3920
3918
3921
err_clkout :
@@ -3925,10 +3928,6 @@ static int rx_macro_probe(struct platform_device *pdev)
3925
3928
clk_disable_unprepare (rx -> dcodec );
3926
3929
err_dcodec :
3927
3930
clk_disable_unprepare (rx -> macro );
3928
- err_ver :
3929
- kfree (reg_defaults );
3930
- err :
3931
- lpass_macro_pds_exit (rx -> pds );
3932
3931
3933
3932
return ret ;
3934
3933
}
@@ -3942,8 +3941,6 @@ static void rx_macro_remove(struct platform_device *pdev)
3942
3941
clk_disable_unprepare (rx -> fsgen );
3943
3942
clk_disable_unprepare (rx -> macro );
3944
3943
clk_disable_unprepare (rx -> dcodec );
3945
-
3946
- lpass_macro_pds_exit (rx -> pds );
3947
3944
}
3948
3945
3949
3946
static const struct of_device_id rx_macro_dt_match [] = {
0 commit comments