Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2576364pxj; Mon, 10 May 2021 06:15:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrTbGurF/0fpak4dBO4e/cELXN3LsdT0SiWpTY8329q8ADbU0rQhsvgDF3Keky4GlEPqgj X-Received: by 2002:a17:907:2d0d:: with SMTP id gs13mr24957507ejc.266.1620652539825; Mon, 10 May 2021 06:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620652539; cv=none; d=google.com; s=arc-20160816; b=GaxO3fAmw3zoGCjkmWwU3Q0O6S4N5x7yelsBToLbZs9WVMhQQwnj4gSMJXgbDjrPn9 k6q47BHq53LznSDo3s0npvkjq2Ztm8dab7PhT7ZOp1FB3awzQvp6WnV3OgbHIOF8u2Tc Fh4owt6rgrxD7xG3ynPOX71PrzsMq3TjCblaDdXhzo7ZglEcMv3bDAJRg+CjR28b32UB p7mO6bM0M3iO6wfxPhjSooTaMu+Zc3jgzyBo9/W3ABbx3rQShGCfcf3peYscZ/l5lxER GAPLDGQ8bDm0dJgf8HlY+OjAwILptDyKfHw6r3rbvOUJb4o2H/AkQL+25My9E/wisfeM RlRQ== 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=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=K+hqQNKxMpi1BNtqZ/XwtkF1pbFA4uT2VXf9O6so4O39fIXB95KJvxxFaILKeZhLO2 +SqxYbvIEnQf/AOcOpEbcJGNZEPdUTw90xQyvNn32JE8Mb+cmph1TLuzU5cYJslmBZXq GFUDfwWCK0oGG5Ey3ngTUSf8RFhEP1A6gt+CTeEkyTqiYcojO52hAZoArc4HrfNF9vGG UEOuQbyB6z4Tqqw56KPXLbVi9k+x6eOYeWfcHylR8SiLZdsYInfFi6bUnce37IvPdZ10 +br3Gh0e3ipEUucwHPrb5DxfLqNSf9WT61JxNaB6n/mWOcIDsBtaaQHMy1bBMbU5m+HJ 9/cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=NgPgdNaR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si7862925eja.202.2021.05.10.06.15.14; Mon, 10 May 2021 06:15:39 -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=@deviqon.com header.s=google header.b=NgPgdNaR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351279AbhEJNFy (ORCPT + 99 others); Mon, 10 May 2021 09:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351123AbhEJNC7 (ORCPT ); Mon, 10 May 2021 09:02:59 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD5BC061351 for ; Mon, 10 May 2021 05:55:54 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id g65so9133586wmg.2 for ; Mon, 10 May 2021 05:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=NgPgdNaRR89izT+ZilXkhdNmMCfCDwY9ZnQFZb/YitvdWfcQP2dt+yDMQDz2fXcbUf RXp0uXHoVzmmohvPKACGnUKTAxocsdviAfErO/9dOQOMB+kATRPx4SCXEs6v9UThFAcp wm8cMQX0rUwYBgv+M+xaozDs2ZgmgiABiUSjnPcrAtBzYodp/0srwtJW5MK91mczHD7L JwpiMM0E6vhExd6B2RRMsnrxp+olFebkoVyDQY6vC7L/QN/G4tNhvyh4G4Q0DMoNGT9i r5bJfLHyC5OvNg6mu77ySP7BtkisA+Ys3oGcjK3UtiVekCPJ88C+1YQW6hW1avNYayid xoUQ== 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=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=ihgA4kTSS1uPVZd9km0hYxnI55jREsjqz+hz68zU4AEEJHzR8ViT/+CbF2r4NoCvPf 0fqNBaOOfw5E/t+9nTpoiujDto1tTcz6bCG70ktlzMOc8D2ve/vwNJw309VRYEEumDTB wHID/oBmTBhjZYrv0Vdu06qTWjEQZ5yS3TjhRsxipzeZrOHO2HQ1owLnob8eojnf7y5r gzh2EsX2ayNDS1VjNQIPpqwZSgcA/N3pX1U4HwEYvk+b+y2hImLyG9X4QLqd3f5BfCgB mA2bEQsS75dHjeVwPwsymzjzIM4gK7UG2KTGw07vPHXcN4jV9+C3gGatOfnjBBserjkX tyVA== X-Gm-Message-State: AOAM530bMj6NSre4Dams+GyYueP4edT4uvAApME4CQMCLuu/ncUIWAF8 TPJvlx2edBX0sq2h7OnT6DdrPQ== X-Received: by 2002:a7b:cc83:: with SMTP id p3mr25727363wma.170.1620651352974; Mon, 10 May 2021 05:55:52 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id n2sm23134329wmb.32.2021.05.10.05.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 05:55:52 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 02/11] iio: adc: ad7793: convert to device-managed functions Date: Mon, 10 May 2021 15:55:14 +0300 Message-Id: <20210510125523.1271237-3-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510125523.1271237-1-aardelean@deviqon.com> References: <20210510125523.1271237-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the devm_ad_sd_setup_buffer_and_trigger() helper, it's a bit easier now to convert the probe of the AD7793 driver to use device-managed functions. Only the regulator disable requires a devm_add_action_or_reset() callback. This change does that, cleaning up the driver a bit. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7793.c | 53 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index 5e980a06258e..5dab2e5b5bac 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -768,6 +768,11 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = { }, }; +static void ad7793_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7793_probe(struct spi_device *spi) { const struct ad7793_platform_data *pdata = spi->dev.platform_data; @@ -802,11 +807,13 @@ static int ad7793_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7793_reg_disable, st->reg); + if (ret) + return ret; + vref_mv = regulator_get_voltage(st->reg); - if (vref_mv < 0) { - ret = vref_mv; - goto error_disable_reg; - } + if (vref_mv < 0) + return vref_mv; vref_mv /= 1000; } else { @@ -816,50 +823,21 @@ static int ad7793_probe(struct spi_device *spi) st->chip_info = &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - spi_set_drvdata(spi, indio_dev); - indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = st->chip_info->channels; indio_dev->num_channels = st->chip_info->num_channels; indio_dev->info = st->chip_info->iio_info; - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret) - goto error_disable_reg; + return ret; ret = ad7793_setup(indio_dev, pdata, vref_mv); if (ret) - goto error_remove_trigger; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_remove_trigger; - - return 0; - -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - if (pdata->refsel != AD7793_REFSEL_INTERNAL) - regulator_disable(st->reg); - - return ret; -} - -static int ad7793_remove(struct spi_device *spi) -{ - const struct ad7793_platform_data *pdata = spi->dev.platform_data; - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7793_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - if (pdata->refsel != AD7793_REFSEL_INTERNAL) - regulator_disable(st->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7793_id[] = { @@ -881,7 +859,6 @@ static struct spi_driver ad7793_driver = { .name = "ad7793", }, .probe = ad7793_probe, - .remove = ad7793_remove, .id_table = ad7793_id, }; module_spi_driver(ad7793_driver); -- 2.31.1