Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: codecs: Simplify mclk initialization

Merge series from Cezary Rojewski <cezary.rojewski@intel.com>:

The patchset may not cover all codecs found in the codecs/ directory -
noticed a possible improvement and grepped for similar pattern across C
files found in the directory. Those addressed here seem pretty
straightforward.

Most of clk_xxx() functions do check if provided clk-pointer is
non-NULL. These do not check if the pointer is an error-pointer.
Providing such to a clk_xxx() results in a panic.

By utilizing _optional() variant of devm_clk_get() the driver code is
both simplified and more robust. There is no need to remember about
IS_ERR(clk) checks each time mclk is accessed.

+20 -40
+4 -8
sound/soc/codecs/da7213.c
··· 2101 2101 pm_runtime_put_sync(component->dev); 2102 2102 2103 2103 /* Check if MCLK provided */ 2104 - da7213->mclk = devm_clk_get(component->dev, "mclk"); 2105 - if (IS_ERR(da7213->mclk)) { 2106 - if (PTR_ERR(da7213->mclk) != -ENOENT) 2107 - return PTR_ERR(da7213->mclk); 2108 - else 2109 - da7213->mclk = NULL; 2110 - } else { 2104 + da7213->mclk = devm_clk_get_optional(component->dev, "mclk"); 2105 + if (IS_ERR(da7213->mclk)) 2106 + return PTR_ERR(da7213->mclk); 2107 + if (da7213->mclk) 2111 2108 /* Do automatic PLL handling assuming fixed clock until 2112 2109 * set_pll() has been called. This makes the codec usable 2113 2110 * with the simple-audio-card driver. */ 2114 2111 da7213->fixed_clk_auto_pll = true; 2115 - } 2116 2112 2117 2113 /* Default infinite tone gen, start/stop by Kcontrol */ 2118 2114 snd_soc_component_write(component, DA7213_TONE_GEN_CYCLES, DA7213_BEEP_CYCLES_MASK);
+4 -8
sound/soc/codecs/nau8825.c
··· 2836 2836 if (nau8825->adc_delay < 125 || nau8825->adc_delay > 500) 2837 2837 dev_warn(dev, "Please set the suitable delay time!\n"); 2838 2838 2839 - nau8825->mclk = devm_clk_get(dev, "mclk"); 2840 - if (PTR_ERR(nau8825->mclk) == -EPROBE_DEFER) { 2841 - return -EPROBE_DEFER; 2842 - } else if (PTR_ERR(nau8825->mclk) == -ENOENT) { 2839 + nau8825->mclk = devm_clk_get_optional(dev, "mclk"); 2840 + if (IS_ERR(nau8825->mclk)) 2841 + return PTR_ERR(nau8825->mclk); 2842 + if (!nau8825->mclk) 2843 2843 /* The MCLK is managed externally or not used at all */ 2844 - nau8825->mclk = NULL; 2845 2844 dev_info(dev, "No 'mclk' clock found, assume MCLK is managed externally"); 2846 - } else if (IS_ERR(nau8825->mclk)) { 2847 - return -EINVAL; 2848 - } 2849 2845 2850 2846 return 0; 2851 2847 }
+3 -6
sound/soc/codecs/rt5514.c
··· 1054 1054 1055 1055 switch (level) { 1056 1056 case SND_SOC_BIAS_PREPARE: 1057 - if (IS_ERR(rt5514->mclk)) 1058 - break; 1059 - 1060 1057 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { 1061 1058 clk_disable_unprepare(rt5514->mclk); 1062 1059 } else { ··· 1094 1097 struct platform_device *pdev = container_of(component->dev, 1095 1098 struct platform_device, dev); 1096 1099 1097 - rt5514->mclk = devm_clk_get(component->dev, "mclk"); 1098 - if (PTR_ERR(rt5514->mclk) == -EPROBE_DEFER) 1099 - return -EPROBE_DEFER; 1100 + rt5514->mclk = devm_clk_get_optional(component->dev, "mclk"); 1101 + if (IS_ERR(rt5514->mclk)) 1102 + return PTR_ERR(rt5514->mclk); 1100 1103 1101 1104 if (rt5514->pdata.dsp_calib_clk_name) { 1102 1105 rt5514->dsp_calib_clk = devm_clk_get(&pdev->dev,
+3 -6
sound/soc/codecs/rt5616.c
··· 1174 1174 * away from ON. Disable the clock in that case, otherwise 1175 1175 * enable it. 1176 1176 */ 1177 - if (IS_ERR(rt5616->mclk)) 1178 - break; 1179 - 1180 1177 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { 1181 1178 clk_disable_unprepare(rt5616->mclk); 1182 1179 } else { ··· 1222 1225 struct rt5616_priv *rt5616 = snd_soc_component_get_drvdata(component); 1223 1226 1224 1227 /* Check if MCLK provided */ 1225 - rt5616->mclk = devm_clk_get(component->dev, "mclk"); 1226 - if (PTR_ERR(rt5616->mclk) == -EPROBE_DEFER) 1227 - return -EPROBE_DEFER; 1228 + rt5616->mclk = devm_clk_get_optional(component->dev, "mclk"); 1229 + if (IS_ERR(rt5616->mclk)) 1230 + return PTR_ERR(rt5616->mclk); 1228 1231 1229 1232 rt5616->component = component; 1230 1233
+3 -6
sound/soc/codecs/rt5640.c
··· 1949 1949 * away from ON. Disable the clock in that case, otherwise 1950 1950 * enable it. 1951 1951 */ 1952 - if (IS_ERR(rt5640->mclk)) 1953 - break; 1954 - 1955 1952 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { 1956 1953 clk_disable_unprepare(rt5640->mclk); 1957 1954 } else { ··· 2658 2661 u32 val; 2659 2662 2660 2663 /* Check if MCLK provided */ 2661 - rt5640->mclk = devm_clk_get(component->dev, "mclk"); 2662 - if (PTR_ERR(rt5640->mclk) == -EPROBE_DEFER) 2663 - return -EPROBE_DEFER; 2664 + rt5640->mclk = devm_clk_get_optional(component->dev, "mclk"); 2665 + if (IS_ERR(rt5640->mclk)) 2666 + return PTR_ERR(rt5640->mclk); 2664 2667 2665 2668 rt5640->component = component; 2666 2669
+3 -6
sound/soc/codecs/rt5660.c
··· 1079 1079 snd_soc_component_update_bits(component, RT5660_GEN_CTRL1, 1080 1080 RT5660_DIG_GATE_CTRL, RT5660_DIG_GATE_CTRL); 1081 1081 1082 - if (IS_ERR(rt5660->mclk)) 1083 - break; 1084 - 1085 1082 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { 1086 1083 clk_disable_unprepare(rt5660->mclk); 1087 1084 } else { ··· 1274 1277 return -ENOMEM; 1275 1278 1276 1279 /* Check if MCLK provided */ 1277 - rt5660->mclk = devm_clk_get(&i2c->dev, "mclk"); 1278 - if (PTR_ERR(rt5660->mclk) == -EPROBE_DEFER) 1279 - return -EPROBE_DEFER; 1280 + rt5660->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); 1281 + if (IS_ERR(rt5660->mclk)) 1282 + return PTR_ERR(rt5660->mclk); 1280 1283 1281 1284 i2c_set_clientdata(i2c, rt5660); 1282 1285