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: jz47xx: Convert to devm_clk_get_enabled()

Jihed Chaibi <jihed.chaibi.dev@gmail.com> says:

The jz4725b, jz4760 and jz4770 Ingenic codec drivers all share the same
clock management pattern: the clock is obtained with devm_clk_get() in
the platform probe, then manually enabled in the component probe and
disabled in the component remove. The clk_prepare_enable() call in the
component probe is unchecked, meaning clock enable failures are silently
ignored and can lead to register access on unpowered hardware.

This series converts all three drivers to devm_clk_get_enabled(), which
combines the get, prepare and enable steps and ties the clock lifetime to
the device via devres. The now-redundant component remove callbacks and
the struct clk pointers in the private structs are removed.

+12 -46
+4 -14
sound/soc/codecs/jz4725b.c
··· 160 160 struct jz_icdc { 161 161 struct regmap *regmap; 162 162 void __iomem *base; 163 - struct clk *clk; 164 163 }; 165 164 166 165 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(jz4725b_adc_tlv, 0, 150, 0); ··· 404 405 struct jz_icdc *icdc = snd_soc_component_get_drvdata(component); 405 406 struct regmap *map = icdc->regmap; 406 407 407 - clk_prepare_enable(icdc->clk); 408 - 409 408 /* Write CONFIGn (n=1 to 8) bits. 410 409 * The value 0x0f is specified in the datasheet as a requirement. 411 410 */ ··· 415 418 return 0; 416 419 } 417 420 418 - static void jz4725b_codec_dev_remove(struct snd_soc_component *component) 419 - { 420 - struct jz_icdc *icdc = snd_soc_component_get_drvdata(component); 421 - 422 - clk_disable_unprepare(icdc->clk); 423 - } 424 - 425 421 static const struct snd_soc_component_driver jz4725b_codec = { 426 422 .probe = jz4725b_codec_dev_probe, 427 - .remove = jz4725b_codec_dev_remove, 428 423 .set_bias_level = jz4725b_codec_set_bias_level, 429 424 .controls = jz4725b_codec_controls, 430 425 .num_controls = ARRAY_SIZE(jz4725b_codec_controls), ··· 607 618 { 608 619 struct device *dev = &pdev->dev; 609 620 struct jz_icdc *icdc; 621 + struct clk *clk; 610 622 int ret; 611 623 612 624 icdc = devm_kzalloc(dev, sizeof(*icdc), GFP_KERNEL); ··· 623 633 if (IS_ERR(icdc->regmap)) 624 634 return PTR_ERR(icdc->regmap); 625 635 626 - icdc->clk = devm_clk_get(&pdev->dev, "aic"); 627 - if (IS_ERR(icdc->clk)) 628 - return PTR_ERR(icdc->clk); 636 + clk = devm_clk_get_enabled(dev, "aic"); 637 + if (IS_ERR(clk)) 638 + return PTR_ERR(clk); 629 639 630 640 platform_set_drvdata(pdev, icdc); 631 641
+4 -16
sound/soc/codecs/jz4760.c
··· 163 163 struct device *dev; 164 164 struct regmap *regmap; 165 165 void __iomem *base; 166 - struct clk *clk; 167 166 }; 168 167 169 168 static int jz4760_codec_set_bias_level(struct snd_soc_component *codec, ··· 601 602 602 603 static int jz4760_codec_codec_probe(struct snd_soc_component *codec) 603 604 { 604 - struct jz_codec *jz_codec = snd_soc_component_get_drvdata(codec); 605 - 606 - clk_prepare_enable(jz_codec->clk); 607 - 608 605 jz4760_codec_codec_init_regs(codec); 609 606 610 607 return 0; 611 608 } 612 609 613 - static void jz4760_codec_codec_remove(struct snd_soc_component *codec) 614 - { 615 - struct jz_codec *jz_codec = snd_soc_component_get_drvdata(codec); 616 - 617 - clk_disable_unprepare(jz_codec->clk); 618 - } 619 - 620 610 static const struct snd_soc_component_driver jz4760_codec_soc_codec_dev = { 621 611 .probe = jz4760_codec_codec_probe, 622 - .remove = jz4760_codec_codec_remove, 623 612 .set_bias_level = jz4760_codec_set_bias_level, 624 613 .controls = jz4760_codec_snd_controls, 625 614 .num_controls = ARRAY_SIZE(jz4760_codec_snd_controls), ··· 805 818 { 806 819 struct device *dev = &pdev->dev; 807 820 struct jz_codec *codec; 821 + struct clk *clk; 808 822 int ret; 809 823 810 824 codec = devm_kzalloc(dev, sizeof(*codec), GFP_KERNEL); ··· 823 835 if (IS_ERR(codec->regmap)) 824 836 return PTR_ERR(codec->regmap); 825 837 826 - codec->clk = devm_clk_get(dev, "aic"); 827 - if (IS_ERR(codec->clk)) 828 - return PTR_ERR(codec->clk); 838 + clk = devm_clk_get_enabled(dev, "aic"); 839 + if (IS_ERR(clk)) 840 + return PTR_ERR(clk); 829 841 830 842 platform_set_drvdata(pdev, codec); 831 843
+4 -16
sound/soc/codecs/jz4770.c
··· 179 179 struct device *dev; 180 180 struct regmap *regmap; 181 181 void __iomem *base; 182 - struct clk *clk; 183 182 }; 184 183 185 184 static int jz4770_codec_set_bias_level(struct snd_soc_component *codec, ··· 633 634 634 635 static int jz4770_codec_codec_probe(struct snd_soc_component *codec) 635 636 { 636 - struct jz_codec *jz_codec = snd_soc_component_get_drvdata(codec); 637 - 638 - clk_prepare_enable(jz_codec->clk); 639 - 640 637 jz4770_codec_codec_init_regs(codec); 641 638 642 639 return 0; 643 640 } 644 641 645 - static void jz4770_codec_codec_remove(struct snd_soc_component *codec) 646 - { 647 - struct jz_codec *jz_codec = snd_soc_component_get_drvdata(codec); 648 - 649 - clk_disable_unprepare(jz_codec->clk); 650 - } 651 - 652 642 static const struct snd_soc_component_driver jz4770_codec_soc_codec_dev = { 653 643 .probe = jz4770_codec_codec_probe, 654 - .remove = jz4770_codec_codec_remove, 655 644 .set_bias_level = jz4770_codec_set_bias_level, 656 645 .controls = jz4770_codec_snd_controls, 657 646 .num_controls = ARRAY_SIZE(jz4770_codec_snd_controls), ··· 852 865 { 853 866 struct device *dev = &pdev->dev; 854 867 struct jz_codec *codec; 868 + struct clk *clk; 855 869 int ret; 856 870 857 871 codec = devm_kzalloc(dev, sizeof(*codec), GFP_KERNEL); ··· 870 882 if (IS_ERR(codec->regmap)) 871 883 return PTR_ERR(codec->regmap); 872 884 873 - codec->clk = devm_clk_get(dev, "aic"); 874 - if (IS_ERR(codec->clk)) 875 - return PTR_ERR(codec->clk); 885 + clk = devm_clk_get_enabled(dev, "aic"); 886 + if (IS_ERR(clk)) 887 + return PTR_ERR(clk); 876 888 877 889 platform_set_drvdata(pdev, codec); 878 890