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.

iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code

Use devm_* and dev_err_probe() simplify probe function and remove
vf610_adc_remove().

Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20241126195256.2441622-1-Frank.Li@nxp.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Frank Li and committed by
Jonathan Cameron
207149d9 0ecb42a1

+25 -53
+25 -53
drivers/iio/adc/vf610_adc.c
··· 814 814 }; 815 815 MODULE_DEVICE_TABLE(of, vf610_adc_match); 816 816 817 + static void vf610_adc_action_remove(void *d) 818 + { 819 + struct vf610_adc *info = d; 820 + 821 + regulator_disable(info->vref); 822 + } 823 + 817 824 static int vf610_adc_probe(struct platform_device *pdev) 818 825 { 819 826 struct device *dev = &pdev->dev; ··· 830 823 int ret; 831 824 832 825 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc)); 833 - if (!indio_dev) { 834 - dev_err(&pdev->dev, "Failed allocating iio device\n"); 835 - return -ENOMEM; 836 - } 826 + if (!indio_dev) 827 + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n"); 837 828 838 829 info = iio_priv(indio_dev); 839 830 info->dev = &pdev->dev; ··· 847 842 ret = devm_request_irq(info->dev, irq, 848 843 vf610_adc_isr, 0, 849 844 dev_name(&pdev->dev), indio_dev); 850 - if (ret < 0) { 851 - dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq); 852 - return ret; 853 - } 845 + if (ret < 0) 846 + return dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq); 854 847 855 - info->clk = devm_clk_get(&pdev->dev, "adc"); 856 - if (IS_ERR(info->clk)) { 857 - dev_err(&pdev->dev, "failed getting clock, err = %ld\n", 858 - PTR_ERR(info->clk)); 859 - return PTR_ERR(info->clk); 860 - } 848 + info->clk = devm_clk_get_enabled(&pdev->dev, "adc"); 849 + if (IS_ERR(info->clk)) 850 + return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), "failed getting clock\n"); 861 851 862 852 info->vref = devm_regulator_get(&pdev->dev, "vref"); 863 853 if (IS_ERR(info->vref)) 864 854 return PTR_ERR(info->vref); 865 855 866 856 ret = regulator_enable(info->vref); 857 + if (ret) 858 + return ret; 859 + 860 + ret = devm_add_action_or_reset(&pdev->dev, vf610_adc_action_remove, info); 867 861 if (ret) 868 862 return ret; 869 863 ··· 883 879 indio_dev->channels = vf610_adc_iio_channels; 884 880 indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels); 885 881 886 - ret = clk_prepare_enable(info->clk); 887 - if (ret) { 888 - dev_err(&pdev->dev, 889 - "Could not prepare or enable the clock.\n"); 890 - goto error_adc_clk_enable; 891 - } 892 - 893 882 vf610_adc_cfg_init(info); 894 883 vf610_adc_hw_init(info); 895 884 896 - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 897 - NULL, &iio_triggered_buffer_setup_ops); 898 - if (ret < 0) { 899 - dev_err(&pdev->dev, "Couldn't initialise the buffer\n"); 900 - goto error_iio_device_register; 901 - } 885 + ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, &iio_pollfunc_store_time, 886 + NULL, &iio_triggered_buffer_setup_ops); 887 + if (ret < 0) 888 + return dev_err_probe(&pdev->dev, ret, "Couldn't initialise the buffer\n"); 902 889 903 890 mutex_init(&info->lock); 904 891 905 - ret = iio_device_register(indio_dev); 906 - if (ret) { 907 - dev_err(&pdev->dev, "Couldn't register the device.\n"); 908 - goto error_adc_buffer_init; 909 - } 892 + ret = devm_iio_device_register(&pdev->dev, indio_dev); 893 + if (ret) 894 + return dev_err_probe(&pdev->dev, ret, "Couldn't register the device.\n"); 910 895 911 896 return 0; 912 - 913 - error_adc_buffer_init: 914 - iio_triggered_buffer_cleanup(indio_dev); 915 - error_iio_device_register: 916 - clk_disable_unprepare(info->clk); 917 - error_adc_clk_enable: 918 - regulator_disable(info->vref); 919 - 920 - return ret; 921 - } 922 - 923 - static void vf610_adc_remove(struct platform_device *pdev) 924 - { 925 - struct iio_dev *indio_dev = platform_get_drvdata(pdev); 926 - struct vf610_adc *info = iio_priv(indio_dev); 927 - 928 - iio_device_unregister(indio_dev); 929 - iio_triggered_buffer_cleanup(indio_dev); 930 - regulator_disable(info->vref); 931 - clk_disable_unprepare(info->clk); 932 897 } 933 898 934 899 static int vf610_adc_suspend(struct device *dev) ··· 945 972 946 973 static struct platform_driver vf610_adc_driver = { 947 974 .probe = vf610_adc_probe, 948 - .remove = vf610_adc_remove, 949 975 .driver = { 950 976 .name = DRIVER_NAME, 951 977 .of_match_table = vf610_adc_match,