Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1751017pxb; Mon, 13 Sep 2021 04:53:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTQg6dhB0bnDRbwY9UDtDLc4LLPLAoMU1IQx6V1Q9UbW5dJep3h+H/4rTy0BmkbbMJaLVN X-Received: by 2002:a02:9695:: with SMTP id w21mr9299800jai.64.1631534004568; Mon, 13 Sep 2021 04:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631534004; cv=none; d=google.com; s=arc-20160816; b=XpclM86iBl2hudS+q6yh3gp8GqVwJFEspYkd1FHHSbL+k7qi9x5mYYkZ5e8WAOD8qo aOtUZpOJfxAKHBIkBcznjxWsz1vQaolz9euzNwDAHdVjDz86JfMa+uzt8VuhdS3Rsifp Sr4qECmifohqzt7xw8d97wbe6V75v6Xe8RM5XbfMOjoDe3usl2etHZB7B5GXS6EXnkaQ d73Wii46edSo7b/ccMQVvaIyVYeX+5CkcLVtz39NmT/X5LGtgfK3CnISA/Nelk87iN5V qw1Q+kc06fDt/VPjkjbD0HFZIA9PbkjztBpoXonOv8p406nzKBSEQXS9xyGExQzYMk+e xYew== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=RXAvyIFlCypwleJumirPLWNzM4FoVetFpvyDJQxWSRw=; b=yl3W9czWT8JKtL1mUzKFJlhiI1THJOdPuD5hiGiwkCVeBAUYKyLH/eI/q6b9V5tXex LFTWriW4PD1qXDSMgLgt67xRrb5bcd8jh7acZqyaV5B1J3xthylGN/IRx6uTByBvxZ5g pS3uF7EKhY2kbGuv0UMorfgh13DYWFECxhgUEwdS1xVd/3nnyOoJlvnCOothfjMpslZ2 Ty7ipOiUPB20j0uiUVUBn1bDrQMmy8OG0D8erbw/0Avb0JqTO8VHrhID9v1zKbPA1XDU fjznFaBynOBtFa1SeQ+Tb5/RmlwgcO491th88/NKb/QBs8w1WAAzgNKIM6vsmh3itN2U x/nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b="bo7S/wLU"; 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 123si6479670jay.90.2021.09.13.04.53.11; Mon, 13 Sep 2021 04:53:24 -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="bo7S/wLU"; 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 S239729AbhIMLwy (ORCPT + 99 others); Mon, 13 Sep 2021 07:52:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239737AbhIMLws (ORCPT ); Mon, 13 Sep 2021 07:52:48 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AB21C061762 for ; Mon, 13 Sep 2021 04:51:32 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id c22so12534704edn.12 for ; Mon, 13 Sep 2021 04:51:32 -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:mime-version :content-transfer-encoding; bh=RXAvyIFlCypwleJumirPLWNzM4FoVetFpvyDJQxWSRw=; b=bo7S/wLUwCS0ubAEOARY9BfI/QA6oeUrPPqXzfmsg54xFUThB4vaYyDbcaVAoQrIY4 bt6XlAbz6KVrzY8sELxF7g/nUVpxGifIXrjA5f5eXnqi+gK6OkMZt69HFfMZwgSIvF5q MdP9oEvXuGz8uaorzm+Z8DbEa3vEIeaIUvqgmZzw1Gf/cd41T/Zcq0SKsx4DfZ39kOTr a/goci4pQtjeLRNYIGiV6jcEkW8Pg76qid7dB2vC5eSCVwCaDOjs7JIxhvAyV++dZYgs j1w3JQv1uTrpE9iduRMRYnwha9YCL6q1B4hT4v7xnpLBkM/kg2YffipXkixyGHSuIsNd dhHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RXAvyIFlCypwleJumirPLWNzM4FoVetFpvyDJQxWSRw=; b=PdVRZoEC2OqFVtJLrihrnJiKJNXkdRseStlVj7PNNzzigjiTD2H0y5ImM2KzflW26Q i/6TllNy8kLiN5thNWZye6ZsDNWoIltW4pnTSQ8lvirkb0w9/NglH3kpIRLA6Hc/VTr1 MzQLm23eiUiNwp7YyiYO6vpZzmApEGz+Lce5Flrt2srM7Eewsr738YZ8JFgFAVb3N8t0 94NPszGl7jajY+TqwuVZes2t4/HNY39WwetKx8WCIxvj16dLZHEn+irGsLVP+422SFOl JTY/NKNjdHjXBPp0UJhljYZFTOU3urVLB4zbNlZsAx2eqsFQo1LIDBoblnNiw7vB3ujB wfhg== X-Gm-Message-State: AOAM532Qc1tz/K4v1Zxibak97ZeavR8XfeptLV6SfYqGpBdr8HGJF4jB vhC94/mCS4ezvFpBP2kUd8nzh+RjZ85qQQ== X-Received: by 2002:aa7:d6c7:: with SMTP id x7mr9081537edr.180.1631533890625; Mon, 13 Sep 2021 04:51:30 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id br21sm3070225ejb.112.2021.09.13.04.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 04:51:30 -0700 (PDT) From: Alexandru Ardelean To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, Alexandru Ardelean Subject: [PATCH] iio: dac: ad7303: convert probe to full device-managed Date: Mon, 13 Sep 2021 14:51:21 +0300 Message-Id: <20210913115121.300082-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For this conversion, the regulators need to have some cleanup hooks registered with devm_add_action_or_reset() and then the devm_io_device_register() call can be used. Signed-off-by: Alexandru Ardelean --- drivers/iio/dac/ad7303.c | 47 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c index e1b6a92df12f..91eaaf793b3e 100644 --- a/drivers/iio/dac/ad7303.c +++ b/drivers/iio/dac/ad7303.c @@ -198,6 +198,11 @@ static const struct iio_chan_spec ad7303_channels[] = { AD7303_CHANNEL(1), }; +static void ad7303_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7303_probe(struct spi_device *spi) { const struct spi_device_id *id = spi_get_device_id(spi); @@ -210,7 +215,6 @@ static int ad7303_probe(struct spi_device *spi) return -ENOMEM; st = iio_priv(indio_dev); - spi_set_drvdata(spi, indio_dev); st->spi = spi; @@ -224,18 +228,27 @@ static int ad7303_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7303_reg_disable, st->vdd_reg); + if (ret) + return ret; + st->vref_reg = devm_regulator_get_optional(&spi->dev, "REF"); if (IS_ERR(st->vref_reg)) { ret = PTR_ERR(st->vref_reg); if (ret != -ENODEV) - goto err_disable_vdd_reg; + return ret; st->vref_reg = NULL; } if (st->vref_reg) { ret = regulator_enable(st->vref_reg); if (ret) - goto err_disable_vdd_reg; + return ret; + + ret = devm_add_action_or_reset(&spi->dev, ad7303_reg_disable, + st->vref_reg); + if (ret) + return ret; st->config |= AD7303_CFG_EXTERNAL_VREF; } @@ -246,32 +259,7 @@ static int ad7303_probe(struct spi_device *spi) indio_dev->channels = ad7303_channels; indio_dev->num_channels = ARRAY_SIZE(ad7303_channels); - ret = iio_device_register(indio_dev); - if (ret) - goto err_disable_vref_reg; - - return 0; - -err_disable_vref_reg: - if (st->vref_reg) - regulator_disable(st->vref_reg); -err_disable_vdd_reg: - regulator_disable(st->vdd_reg); - return ret; -} - -static int ad7303_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7303_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - if (st->vref_reg) - regulator_disable(st->vref_reg); - regulator_disable(st->vdd_reg); - - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct of_device_id ad7303_spi_of_match[] = { @@ -292,7 +280,6 @@ static struct spi_driver ad7303_driver = { .of_match_table = ad7303_spi_of_match, }, .probe = ad7303_probe, - .remove = ad7303_remove, .id_table = ad7303_spi_ids, }; module_spi_driver(ad7303_driver); -- 2.31.1