Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3170475pxb; Tue, 24 Aug 2021 17:25:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMbYqVo9sY9ZIMtRt3CR2Zc9c8wkAzPjXZ/cU7WBtLcL5RyXm4CptnRj0mw21xfFLOqMLA X-Received: by 2002:a6b:296:: with SMTP id 144mr33334048ioc.114.1629851158010; Tue, 24 Aug 2021 17:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629851158; cv=none; d=google.com; s=arc-20160816; b=xmDdlZQqJw2edwMYHCULRrqSLYwk+qZ3/LHujLtmvA/pYTEAlEcKLLxEk/6mgXJd0J 2d8nnunYpre+gW0YWuRlnPRWIkGrAZ2s7DD0+4JvJsqw48+Knog3p3eaiZldzFXtJs7d 14U2GCkEsJ9zt04vJa5QLpKwFXzOWYeaO+HLE+LFYeHLPnoNMkxm1mk4t1Rw+HKkgQqA xbUGcnk7mfrNIu8m8nfZu3Ak5mvAlDVwo4vAotXX0b35GPd5zTB1os0TfdQIBSp+aHxh G7WqDvU7NejKHhcngYn/fOCioBedhdK11OLChnlrh/eohNeGH1JbkoBEG0cVzcneQt4N Avmg== 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=dn0AtQjhEdKQfB9SJMLpFoESfZ+r0aPpN24chJVO4Kbo4ZtjhzJDdXM+r66/zulLDr DJ/hkA2JHkI2KMKN1+Lu3v4Rnfpgi+W01eSstaP52nZrkh4s3GXsw1jNx7Ua8ZIKjaQi BGnBJvMlv5xajpMVTX2Fqdt5QfScdVoeTMsBfrCadIPQjZerVuLESsk9znqZWHOeZrKZ gsprfIaFPf5bADBzZoy4AjTd/6f1722gN0suOq19emNNap5zQwMCZ6TQETryAaljHpWh fSd/Z0tiFX/684lDCQ97Jtp+hfJnCsCUlCFvtS+Nkdxv6EtLxouplR0vBlopD/yetMf4 r0cA== 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 e11si18302397iot.82.2021.08.24.17.25.46; Tue, 24 Aug 2021 17:25:57 -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 S236442AbhHYAZR (ORCPT + 99 others); Tue, 24 Aug 2021 20:25:17 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:40711 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236318AbhHYAZR (ORCPT ); Tue, 24 Aug 2021 20:25:17 -0400 Received: (from root@localhost) by twspam01.aspeedtech.com id 17P05vAV096607 for ; Wed, 25 Aug 2021 08:05:57 +0800 (GMT-8) (envelope-from billy_tsai@aspeedtech.com) Message-Id: <202108250005.17P05vAV096607@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 17P05vAV096607 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