Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3170771pxb; Tue, 24 Aug 2021 17:26:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyda01BhHnX694uUhuobyjnSMnR154/dD8JTL35Q7oIegsyBonJVLJQ5imfprEqUy/ALniQ X-Received: by 2002:a92:d68a:: with SMTP id p10mr28343522iln.179.1629851189988; Tue, 24 Aug 2021 17:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629851189; cv=none; d=google.com; s=arc-20160816; b=Fv0AcpwDWdAEwEXsue2nOwIR5kmqOWfYr+BzLDRmrOuHgpzhkuIqN1+sNkkLQwrJTt YoXWtElLJddW8zI6Gnnh2zLCmcu298ecXsvtk8c174thd9xMae+5pRtEyBTMdi3kU10n Atq61FSKWnlRAqPj9XA/ZdnbjgRtgZS3P6DduDwqhKoD2pmYduRJxNXMhbFUzYGsJMNX sg4ghUU49rQB0VR8E4u2BumPZKHDVNdO/2joEhIr9I4KbqZsLKV6gpjK6Wirgk8y/ApY 7kYM1o2ypn/lZg6EO5UieNyv6c0HONpSN3Cbwaoo8T7uUdkH8aMZKNV+EEZji7DU2flj 7JCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:cc:to:from:message-id; bh=bkwVZvc/0tUKsSa/yaDP9pSnkt9SRc+qtYoJeYGFWTA=; b=iTVVNR/AYzK9YvBmpARd4pqkb7e73ov1G7O4/UC6F1ihgjdNRwm8FDi7E6ZMpEI2Ac 3SrUT/3Iba3SmIpo+xgqfCH9HNcrJHNkLDq8uSg8vtMv0x7VaWX1S6UU1uhzPV+qpFMa klWv/Dvj8QotHEswtLPrLnMA930ufsOi6u+0H1uTVMOThGfXu30nHGn8tIOtGHVdlvYU aR+eBErtEJXFUkpYDWkmzgOflN3luE1IvLhre1Y7IKUnE3ZvV65EzwIVkcfIbD2Z14Ub g/w5tNe/MtsJSRnlqWtLJzhF/2PYDfJCmYot7vfGLMrywdCBBCZft9TyrmB1q7U3f4Wo c4PA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si4797314jat.62.2021.08.24.17.26.18; Tue, 24 Aug 2021 17:26:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236251AbhHYA0H (ORCPT + 99 others); Tue, 24 Aug 2021 20:26:07 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:64446 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236615AbhHYA0G (ORCPT ); Tue, 24 Aug 2021 20:26:06 -0400 Received: (from root@localhost) by twspam01.aspeedtech.com id 17P06jKH097337 for ; Wed, 25 Aug 2021 08:06:45 +0800 (GMT-8) (envelope-from billy_tsai@aspeedtech.com) Message-Id: <202108250006.17P06jKH097337@twspam01.aspeedtech.com> Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 17O8rGgR098397; Tue, 24 Aug 2021 16:53:16 +0800 (GMT-8) (envelope-from billy_tsai@aspeedtech.com) Received: from BillyTsai-pc.aspeed.com (192.168.2.149) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 24 Aug 2021 17:11:48 +0800 From: Billy Tsai To: , , , , , , , , , , , , , CC: Subject: [RESEND v4 09/15] iio: adc: aspeed: Use devm_add_action_or_reset. Date: Tue, 24 Aug 2021 17:12:37 +0800 X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824091243.9393-1-billy_tsai@aspeedtech.com> References: <20210824091243.9393-1-billy_tsai@aspeedtech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.2.149] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 17P06jKH097337 X-MSS: FORWARD@twspam01.aspeedtech.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch use devm_add_action_or_reset to handle the error in probe phase. Signed-off-by: Billy Tsai --- drivers/iio/adc/aspeed_adc.c | 92 +++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c index 52db38be9699..1c87e12a0cab 100644 --- a/drivers/iio/adc/aspeed_adc.c +++ b/drivers/iio/adc/aspeed_adc.c @@ -187,6 +187,27 @@ static const struct iio_info aspeed_adc_iio_info = { .debugfs_reg_access = aspeed_adc_reg_access, }; +static void aspeed_adc_unregister_divider(void *data) +{ + struct clk_hw *clk = data; + + clk_hw_unregister_divider(clk); +} + +static void aspeed_adc_reset_assert(void *data) +{ + struct reset_control *rst = data; + + reset_control_assert(rst); +} + +static void aspeed_adc_clk_disable_unprepare(void *data) +{ + struct clk *clk = data; + + clk_disable_unprepare(clk); +} + static int aspeed_adc_vref_config(struct iio_dev *indio_dev) { struct aspeed_adc_data *data = iio_priv(indio_dev); @@ -232,6 +253,12 @@ static int aspeed_adc_probe(struct platform_device *pdev) &data->clk_lock); if (IS_ERR(data->clk_prescaler)) return PTR_ERR(data->clk_prescaler); + + ret = devm_add_action_or_reset(data->dev, + aspeed_adc_unregister_divider, + data->clk_prescaler); + if (ret) + return ret; snprintf(clk_parent_name, 32, clk_name); scaler_flags = CLK_SET_RATE_PARENT; } @@ -244,23 +271,30 @@ static int aspeed_adc_probe(struct platform_device *pdev) &pdev->dev, clk_name, clk_parent_name, scaler_flags, data->base + ASPEED_REG_CLOCK_CONTROL, 0, data->model_data->scaler_bit_width, 0, &data->clk_lock); - if (IS_ERR(data->clk_scaler)) { - ret = PTR_ERR(data->clk_scaler); - goto scaler_error; - } + if (IS_ERR(data->clk_scaler)) + return PTR_ERR(data->clk_scaler); + + ret = devm_add_action_or_reset(data->dev, aspeed_adc_unregister_divider, + data->clk_scaler); + if (ret) + return ret; data->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); if (IS_ERR(data->rst)) { dev_err(&pdev->dev, "invalid or missing reset controller device tree entry"); - ret = PTR_ERR(data->rst); - goto reset_error; + return PTR_ERR(data->rst); } reset_control_deassert(data->rst); + ret = devm_add_action_or_reset(data->dev, aspeed_adc_reset_assert, + data->rst); + if (ret) + return ret; + ret = aspeed_adc_vref_config(indio_dev); if (ret) - goto vref_config_error; + return ret; if (data->model_data->wait_init_sequence) { /* Enable engine in normal mode. */ @@ -277,13 +311,19 @@ static int aspeed_adc_probe(struct platform_device *pdev) ASPEED_ADC_INIT_POLLING_TIME, ASPEED_ADC_INIT_TIMEOUT); if (ret) - goto poll_timeout_error; + return ret; } /* Start all channels in normal mode. */ ret = clk_prepare_enable(data->clk_scaler->clk); if (ret) - goto clk_enable_error; + return ret; + + ret = devm_add_action_or_reset(data->dev, + aspeed_adc_clk_disable_unprepare, + data->clk_scaler->clk); + if (ret) + return ret; adc_engine_control_reg_val = ASPEED_ADC_CTRL_CHANNEL | @@ -299,41 +339,19 @@ static int aspeed_adc_probe(struct platform_device *pdev) indio_dev->num_channels = data->model_data->num_channels; ret = iio_device_register(indio_dev); - if (ret) - goto iio_register_error; - + if (ret) { + writel(FIELD_PREP(ASPEED_ADC_OP_MODE, + ASPEED_ADC_OP_MODE_PWR_DOWN), + data->base + ASPEED_REG_ENGINE_CONTROL); + return ret; + } return 0; - -iio_register_error: - writel(FIELD_PREP(ASPEED_ADC_OP_MODE, ASPEED_ADC_OP_MODE_PWR_DOWN), - data->base + ASPEED_REG_ENGINE_CONTROL); - clk_disable_unprepare(data->clk_scaler->clk); -clk_enable_error: -poll_timeout_error: -vref_config_error: - reset_control_assert(data->rst); -reset_error: - clk_hw_unregister_divider(data->clk_scaler); -scaler_error: - if (data->model_data->need_prescaler) - clk_hw_unregister_divider(data->clk_prescaler); - return ret; } static int aspeed_adc_remove(struct platform_device *pdev) { struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct aspeed_adc_data *data = iio_priv(indio_dev); - iio_device_unregister(indio_dev); - writel(FIELD_PREP(ASPEED_ADC_OP_MODE, ASPEED_ADC_OP_MODE_PWR_DOWN), - data->base + ASPEED_REG_ENGINE_CONTROL); - clk_disable_unprepare(data->clk_scaler->clk); - reset_control_assert(data->rst); - clk_hw_unregister_divider(data->clk_scaler); - if (data->model_data->need_prescaler) - clk_hw_unregister_divider(data->clk_prescaler); - return 0; } -- 2.25.1