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
37653766static 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
39183921err_clkout :
@@ -3925,10 +3928,6 @@ static int rx_macro_probe(struct platform_device *pdev)
39253928 clk_disable_unprepare (rx -> dcodec );
39263929err_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
39493946static const struct of_device_id rx_macro_dt_match [] = {
0 commit comments