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

iio: adc: mxs-lradc: fix the order of two cleanup operations

Smatch reports:
drivers/iio/adc/mxs-lradc-adc.c:766 mxs_lradc_adc_probe() warn:
missing unwind goto?

the order of three init operation:
1.mxs_lradc_adc_trigger_init
2.iio_triggered_buffer_setup
3.mxs_lradc_adc_hw_init

thus, the order of three cleanup operation should be:
1.mxs_lradc_adc_hw_stop
2.iio_triggered_buffer_cleanup
3.mxs_lradc_adc_trigger_remove

we exchange the order of two cleanup operations,
introducing the following differences:
1.if mxs_lradc_adc_trigger_init fails, returns directly;
2.if trigger_init succeeds but iio_triggered_buffer_setup fails,
goto err_trig and remove the trigger.

In addition, we also reorder the unwind that goes on in the
remove() callback to match the new ordering.

Fixes: 6dd112b9f85e ("iio: adc: mxs-lradc: Add support for ADC driver")
Signed-off-by: Jiakai Luo <jkluo@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
Link: https://lore.kernel.org/r/20230422133407.72908-1-jkluo@hust.edu.cn
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jiakai Luo and committed by
Jonathan Cameron
27b2ed5b 28f73ded

+5 -5
+5 -5
drivers/iio/adc/mxs-lradc-adc.c
··· 757 757 758 758 ret = mxs_lradc_adc_trigger_init(iio); 759 759 if (ret) 760 - goto err_trig; 760 + return ret; 761 761 762 762 ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, 763 763 &mxs_lradc_adc_trigger_handler, 764 764 &mxs_lradc_adc_buffer_ops); 765 765 if (ret) 766 - return ret; 766 + goto err_trig; 767 767 768 768 adc->vref_mv = mxs_lradc_adc_vref_mv[lradc->soc]; 769 769 ··· 801 801 802 802 err_dev: 803 803 mxs_lradc_adc_hw_stop(adc); 804 - mxs_lradc_adc_trigger_remove(iio); 805 - err_trig: 806 804 iio_triggered_buffer_cleanup(iio); 805 + err_trig: 806 + mxs_lradc_adc_trigger_remove(iio); 807 807 return ret; 808 808 } 809 809 ··· 814 814 815 815 iio_device_unregister(iio); 816 816 mxs_lradc_adc_hw_stop(adc); 817 - mxs_lradc_adc_trigger_remove(iio); 818 817 iio_triggered_buffer_cleanup(iio); 818 + mxs_lradc_adc_trigger_remove(iio); 819 819 820 820 return 0; 821 821 }