Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp378721pxx; Mon, 26 Oct 2020 10:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2upfUoJtPYWnzk+5GvS3y89xMb06SWiZGx13odTWPuYUgf0BgVwXBp2iSIvBkYNWpUqnI X-Received: by 2002:a17:906:660f:: with SMTP id b15mr17429941ejp.333.1603733567085; Mon, 26 Oct 2020 10:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603733567; cv=none; d=google.com; s=arc-20160816; b=g0xKJ61/WKY4+MhA4/I12NpeV+OlgcqyPO0oJvk5FSDpYFAsrWXw6Jb/J+r9hrG5rb VFzU+Yyq/RYD8VNQgBjHVS68DxkuI2mDbnrEsdGCvhnRItgAQppvbnF8lDKsaYWrT7is WguhAOaWapVIyi9/kLkLolD6BBvsMUUVAkYd0QjKOBB20hSAB5t+PePLY6gFcIt2daIe 4EoSCo64MLhSo/k6h6Mq4hVVWyquZ7OSErV2eOIj3fP9rBJ5+wVRh47jTrEoS2mXg45W 6sObOYQFiBjIFtEcl3xPeTCYOagIkQ6L1EHgvRy+zAxS8SCbcdxwM950JOWRLTziQo7Q eIXw== 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:message-id:date:subject:cc:to:from :dkim-signature; bh=k40eJc8Lhw98TUMyUtqdBZVrG65XsNSVzHSaCNt0jHc=; b=wPJkIbFOkgt6pC408UqLwirueXwThWwstqo307dESaEUGUEgMTSKFXCkbTlIbxHTUs yHrCyaccbjfpiOdXzDZHgz2HQ0Norjx3Et+aOjtj9ZB6gWxbDdrW2vnRqm3OLlfdooSw ivAJPO4t2ELFT7YyaMtt0LU4xfOhDzFJaIukLDgAIBt0sXvyW1Rf5akIyhP9h6kmDPjp nt0dquffTZz4ZPNzJE3biFCz8o1kYn6P0UKMWxdcwfoOO6oyP6s95yiG8dHiIa0JekeW A+fxw5w9xwWj0KBIGriHaSwbuIREeVyx/2NJiOfaZ/0AHxrHhzH6deRIls95/mA3kTGe Vhew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=xULoTkoU; 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 qk3si9662197ejb.700.2020.10.26.10.32.22; Mon, 26 Oct 2020 10:32:47 -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; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=xULoTkoU; 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 S1780279AbgJZNgk (ORCPT + 99 others); Mon, 26 Oct 2020 09:36:40 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36985 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1775675AbgJZNga (ORCPT ); Mon, 26 Oct 2020 09:36:30 -0400 Received: by mail-wr1-f67.google.com with SMTP id h7so12604288wre.4 for ; Mon, 26 Oct 2020 06:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k40eJc8Lhw98TUMyUtqdBZVrG65XsNSVzHSaCNt0jHc=; b=xULoTkoUGRbnpHi6ZghaIZ1Q5yiAkgzBSZomS+pZDERJpF71+9WHNz7PkKFZCppqnR E8TvUVRzJBWf61WOq6yMPk1rtsL/mjsrHd984WeDRag1X84yfn9JZ3/BUdFfpsyAhr9i r+3jGNJKjnN9NhccBQ3VVT/UqJwJoQO0rwTYfNAdIj3OK+AX71r8AOVUI8mt+ZO9CAjl crYeJmkgxX/876FoIJU0Li4C6oO8FT+cCgFCyan2kbT99hhNS3i2Q9r4i1ccDmqKiRT0 mMHQBprSDMOBi94y3N82AbCwRWdMXNsHegunbPSFZH3U49aHEKpZXieoIckKWFPib/GG 7/eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k40eJc8Lhw98TUMyUtqdBZVrG65XsNSVzHSaCNt0jHc=; b=VeDIGyFACH4Vrm7xZiYhCx1kmJ9SvH6wKNEa1Hm1Okm9qgTJsYdmyhkTKko69YYvqo AW6WHJvgeFHYYVT6J7G+WFq8ccvGTtJJHMi6vRuzXrezyATOInFRnsBG2xDsHpX+7sz8 lzcRtgtQG7r9OMm9LsQ8TObmD739AcxxEmQYn+MQsOAkNn0Ydqeg7ZE1EnVKGlpewUL0 J2DOQfEibJSDUc87lcYgN5letbAwNEeqA7LmAw1n3FfXkxYWlyH95H3zqHBE5xDmWJgz 6YZ3eHenOswBG/mrOceEHG1jkcdfMow/hJ9CPw6rjOsx44ndJYjr00acqR7U1QL6HSfH lWnw== X-Gm-Message-State: AOAM530VAen1TI7YAniK5u1XIH61Fqnj3SJ2XX0XN01aWTFElVZW0K5A ATKDSgOZjDCzuzIegRs+Fx13N0Y0aVN+hA== X-Received: by 2002:a5d:5344:: with SMTP id t4mr17501589wrv.267.1603719387795; Mon, 26 Oct 2020 06:36:27 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-190-206.w2-15.abo.wanadoo.fr. [2.15.39.206]) by smtp.gmail.com with ESMTPSA id f7sm23688991wrx.64.2020.10.26.06.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 06:36:27 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek Cc: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/5] iio: adc: xilinx: use iio devres helpers Date: Mon, 26 Oct 2020 14:36:09 +0100 Message-Id: <20201026133609.24262-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201026133609.24262-1-brgl@bgdev.pl> References: <20201026133609.24262-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Shrink the code by using devres variants of all iio routines. This allows us to entirely drop the remove() callback as well as significantly simplifies error paths in probe(). Signed-off-by: Bartosz Golaszewski --- drivers/iio/adc/xilinx-xadc-core.c | 97 ++++++++++-------------------- 1 file changed, 32 insertions(+), 65 deletions(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 4440b7a9bd36..c17705205456 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -706,11 +706,12 @@ static const struct iio_trigger_ops xadc_trigger_ops = { static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev, const char *name) { + struct device *dev = indio_dev->dev.parent; struct iio_trigger *trig; int ret; - trig = iio_trigger_alloc("%s%d-%s", indio_dev->name, - indio_dev->id, name); + trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name, + indio_dev->id, name); if (trig == NULL) return ERR_PTR(-ENOMEM); @@ -718,15 +719,11 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev, trig->ops = &xadc_trigger_ops; iio_trigger_set_drvdata(trig, iio_priv(indio_dev)); - ret = iio_trigger_register(trig); + ret = devm_iio_trigger_register(dev, trig); if (ret) - goto error_free_trig; + return ERR_PTR(ret); return trig; - -error_free_trig: - iio_trigger_free(trig); - return ERR_PTR(ret); } static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode) @@ -1247,39 +1244,35 @@ static int xadc_probe(struct platform_device *pdev) return ret; if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { - ret = iio_triggered_buffer_setup(indio_dev, - &iio_pollfunc_store_time, &xadc_trigger_handler, - &xadc_buffer_ops); + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + &iio_pollfunc_store_time, + &xadc_trigger_handler, + &xadc_buffer_ops); if (ret) return ret; xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst"); - if (IS_ERR(xadc->convst_trigger)) { - ret = PTR_ERR(xadc->convst_trigger); - goto err_triggered_buffer_cleanup; - } + if (IS_ERR(xadc->convst_trigger)) + return PTR_ERR(xadc->convst_trigger); + xadc->samplerate_trigger = xadc_alloc_trigger(indio_dev, "samplerate"); - if (IS_ERR(xadc->samplerate_trigger)) { - ret = PTR_ERR(xadc->samplerate_trigger); - goto err_free_convst_trigger; - } + if (IS_ERR(xadc->samplerate_trigger)) + return PTR_ERR(xadc->samplerate_trigger); } xadc->clk = devm_clk_get(dev, NULL); - if (IS_ERR(xadc->clk)) { - ret = PTR_ERR(xadc->clk); - goto err_free_samplerate_trigger; - } + if (IS_ERR(xadc->clk)) + return PTR_ERR(xadc->clk); ret = clk_prepare_enable(xadc->clk); if (ret) - goto err_free_samplerate_trigger; + return ret; ret = devm_add_action_or_reset(dev, xadc_clk_disable_unprepare, xadc->clk); if (ret) - goto err_free_samplerate_trigger; + return ret; /* * Make sure not to exceed the maximum samplerate since otherwise the @@ -1288,27 +1281,28 @@ static int xadc_probe(struct platform_device *pdev) if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { ret = xadc_read_samplerate(xadc); if (ret < 0) - goto err_free_samplerate_trigger; + return ret; + if (ret > XADC_MAX_SAMPLERATE) { ret = xadc_write_samplerate(xadc, XADC_MAX_SAMPLERATE); if (ret < 0) - goto err_free_samplerate_trigger; + return ret; } } ret = devm_request_irq(dev, xadc->irq, xadc->ops->interrupt_handler, 0, dev_name(dev), indio_dev); if (ret) - goto err_free_samplerate_trigger; + return ret; ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, &xadc->zynq_unmask_work); if (ret) - goto err_free_samplerate_trigger; + return ret; ret = xadc->ops->setup(pdev, indio_dev, xadc->irq); if (ret) - goto err_free_samplerate_trigger; + return ret; for (i = 0; i < 16; i++) xadc_read_adc_reg(xadc, XADC_REG_THRESHOLD(i), @@ -1316,7 +1310,7 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_CONF0, conf0); if (ret) - goto err_free_samplerate_trigger; + return ret; bipolar_mask = 0; for (i = 0; i < indio_dev->num_channels; i++) { @@ -1326,17 +1320,18 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_INPUT_MODE(0), bipolar_mask); if (ret) - goto err_free_samplerate_trigger; + return ret; + ret = xadc_write_adc_reg(xadc, XADC_REG_INPUT_MODE(1), bipolar_mask >> 16); if (ret) - goto err_free_samplerate_trigger; + return ret; /* Disable all alarms */ ret = xadc_update_adc_reg(xadc, XADC_REG_CONF1, XADC_CONF1_ALARM_MASK, XADC_CONF1_ALARM_MASK); if (ret) - goto err_free_samplerate_trigger; + return ret; /* Set thresholds to min/max */ for (i = 0; i < 16; i++) { @@ -1351,51 +1346,23 @@ static int xadc_probe(struct platform_device *pdev) ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i), xadc->threshold[i]); if (ret) - goto err_free_samplerate_trigger; + return ret; } /* Go to non-buffered mode */ xadc_postdisable(indio_dev); - ret = iio_device_register(indio_dev); + ret = devm_iio_device_register(dev, indio_dev); if (ret) - goto err_free_samplerate_trigger; + return ret; platform_set_drvdata(pdev, indio_dev); - return 0; - -err_free_samplerate_trigger: - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) - iio_trigger_free(xadc->samplerate_trigger); -err_free_convst_trigger: - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) - iio_trigger_free(xadc->convst_trigger); -err_triggered_buffer_cleanup: - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) - iio_triggered_buffer_cleanup(indio_dev); - - return ret; -} - -static int xadc_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct xadc *xadc = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { - iio_trigger_free(xadc->samplerate_trigger); - iio_trigger_free(xadc->convst_trigger); - iio_triggered_buffer_cleanup(indio_dev); - } - return 0; } static struct platform_driver xadc_driver = { .probe = xadc_probe, - .remove = xadc_remove, .driver = { .name = "xadc", .of_match_table = xadc_of_match_table, -- 2.29.1