Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3523904rwr; Sat, 22 Apr 2023 06:55:28 -0700 (PDT) X-Google-Smtp-Source: AKy350YT2u1rcazeJJmIdggdRID+9C0BeAthzAuc8nQJx/NADSNn7gt06XuO9olff0Wd1kHvltUE X-Received: by 2002:a05:6a20:8e19:b0:d7:3c1a:6c9a with SMTP id y25-20020a056a208e1900b000d73c1a6c9amr9773458pzj.4.1682171728591; Sat, 22 Apr 2023 06:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682171728; cv=none; d=google.com; s=arc-20160816; b=qJ01Iphzt/RWDed0cCx+5BaZsJQTkMmfy8OfGI2AQM0UjENeGDKvmiIOQgvIOZMiBQ g9yAcaotdV6+NomcQO32FZxv+T+C+6VWklSr8O09kP2nYz/ZypybKA8ivYc6EFWoDmUO D7YakscQ9KxiBVHX87aoh4PnrsrHX+MKAgPWlI6Kx1Ru43ce6pgYJqbW9MrprfufeQg1 yTo/+dT2m8SAmRsAqA4W/Pnh+azGP4ZrKOxrSdmaPQsxWd9OuR/1JevqpSkLPmB/vdaI dZs2PZP0vECyIxrLtQo0qB4dfvCuA7tvjSgNfvmoyUKDM6CpW4U+kytwGqSpIC0K08S4 E4MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=5H8DqFloPEjfJBhKxTwGgfJCjIlCnXK/P3yqfaJ+iQM=; b=yeumRHBP92knpXM2AtM31pMXaw1aAoorUJ5BQoUdx6FEpvXWqZt13lutQbYg1TA7dw nxZtIGmheXm1Z8rB1XyQOdo/gMqCbj/MD0p7GeXKmqIOGwxY5i1cfl3K41fSvBmBCsjB WCulU2ALVN0/Rzyje2Q/PWypnB9geGrZqLy1JtYGZhATzBki86ngIWxxamPwisVUO7ll oVVbXcZAUVxUUG/+HK0FoxKIVH6LCQRhWWqsq/+v+p7TDtyg2OAfZhVtd5tgUBl74KMD WE+WmzXVzh/Vpbbh4imGQ8zJeE47ZXhzztrclFteb1w3VJR+PlJRqQQpwEMOTvq2Xr9L HI9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a656911000000b00521075bf591si2236305pgq.534.2023.04.22.06.55.14; Sat, 22 Apr 2023 06:55:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjDVNim (ORCPT + 99 others); Sat, 22 Apr 2023 09:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjDVNik (ORCPT ); Sat, 22 Apr 2023 09:38:40 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28BA110F0; Sat, 22 Apr 2023 06:38:37 -0700 (PDT) Received: from ubuntu.localdomain ([10.12.170.113]) (user=jkluo@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33MDYvAe029951-33MDYvAf029951 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sat, 22 Apr 2023 21:35:08 +0800 From: Jiakai Luo To: Jonathan Cameron , Lars-Peter Clausen , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Lee Jones , Marek Vasut , Ksenija Stanojevic Cc: hust-os-kernel-patches@googlegroups.com, Jiakai Luo , linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] iio: adc: mxs-lradc: fix the order of two cleanup operations Date: Sat, 22 Apr 2023 06:34:06 -0700 Message-Id: <20230422133407.72908-1-jkluo@hust.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230416132906.4ec56e47@jic23-huawei> References: <20230416132906.4ec56e47@jic23-huawei> X-FEAS-AUTH-USER: jkluo@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Dongliang Mu --- The issue is found by static analysis and remains untested. --- drivers/iio/adc/mxs-lradc-adc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/mxs-lradc-adc.c b/drivers/iio/adc/mxs-lradc-adc.c index bca79a93cbe4..85882509b7d9 100644 --- a/drivers/iio/adc/mxs-lradc-adc.c +++ b/drivers/iio/adc/mxs-lradc-adc.c @@ -757,13 +757,13 @@ static int mxs_lradc_adc_probe(struct platform_device *pdev) ret = mxs_lradc_adc_trigger_init(iio); if (ret) - goto err_trig; + return ret; ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, &mxs_lradc_adc_trigger_handler, &mxs_lradc_adc_buffer_ops); if (ret) - return ret; + goto err_trig; adc->vref_mv = mxs_lradc_adc_vref_mv[lradc->soc]; @@ -801,9 +801,9 @@ static int mxs_lradc_adc_probe(struct platform_device *pdev) err_dev: mxs_lradc_adc_hw_stop(adc); - mxs_lradc_adc_trigger_remove(iio); -err_trig: iio_triggered_buffer_cleanup(iio); +err_trig: + mxs_lradc_adc_trigger_remove(iio); return ret; } @@ -814,8 +814,8 @@ static int mxs_lradc_adc_remove(struct platform_device *pdev) iio_device_unregister(iio); mxs_lradc_adc_hw_stop(adc); - mxs_lradc_adc_trigger_remove(iio); iio_triggered_buffer_cleanup(iio); + mxs_lradc_adc_trigger_remove(iio); return 0; } -- 2.17.1