Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp912983pxb; Sat, 18 Sep 2021 23:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUymr/4PVk1JkxDAHGu3YolAFcK/flMOcu2V2y8bhOp1W8DOBua6hdbAZIHiVFA7B185qg X-Received: by 2002:a6b:7b4a:: with SMTP id m10mr2237667iop.125.1632034453259; Sat, 18 Sep 2021 23:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632034453; cv=none; d=google.com; s=arc-20160816; b=zHsl4B4Wkg2yMk3+XJm58LZF/dFu+eSRJvy6C2Am2FBUz7SGF7G5rUmY/voltS9bOE l0yGNY7GtpDzGeXnCpyBi1Ak8dO724KTDjjU/sxjU4BGe5CqDVUix+20+66zwsS977FL 3ThfNfnmpIiGG+JUBUyF1XDy3E5JyMY83Wp9DLad5v3TryjGAvMSUiVwnvy6cIZ4OTbH k8PxbkW0kgVoWb3sp/wrfz/fnSF2NPt2PgEXd/b2X7e/DxHLbtH8OwawAxDTa5yvoazS xST8O2jKsjMDQi9yC0U5X4r+CV5+LGEA8WqJ3s91+qxMC/5MBZyktFj1Tb16hmL2bres JcHA== 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:subject:cc:to:from:date; bh=jBXV360nThgpitjYYzNvbMRreCS3VT2YBhj5/cnt1f4=; b=L/6f8DZAYm/EK9GWT2lzxTJKkdSdppWbpjHA5y5eK7YwTgkbE1tOV3mbQ7SHzkbZdn 67KHuDM3uxM9z3FCQ0r4/J6G+Biq2JS4ZnMMlW1u8VL//94xlM16uVaN5xs2wc+WPR2i F78A55H4UsAQN3LpTpryrDAyzi+1PMrPFV1SXf66CiUDfXQP+CLu4/0CVllQ92UMzLGV FAGLlpCpWepqaOwhzqvcYTdAfnR46C10G1C3xrCdDS+olGK1B8+awQY5tezHpPrj/gd4 XfbaR/fHL6agRdWNahoshwKx8g216T0HpnVswHpNW06DnNUaexxrj57i6Hybu5Bv7fL7 bMBQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si13825570jag.18.2021.09.18.23.54.02; Sat, 18 Sep 2021 23:54:13 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237981AbhIRSBs (ORCPT + 99 others); Sat, 18 Sep 2021 14:01:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:56088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231576AbhIRSBs (ORCPT ); Sat, 18 Sep 2021 14:01:48 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 09FBC6101B; Sat, 18 Sep 2021 18:00:22 +0000 (UTC) Date: Sat, 18 Sep 2021 19:04:02 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Subject: Re: [PATCH] staging: iio: ad9832: convert probe to device-managed Message-ID: <20210918190402.379e2972@jic23-huawei> In-Reply-To: <20210913115209.300665-1-aardelean@deviqon.com> References: <20210913115209.300665-1-aardelean@deviqon.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 13 Sep 2021 14:52:09 +0300 Alexandru Ardelean wrote: > This change does a conversion of the driver to use device-managed init > functions. The 2 regulators and the clock inits are converted to use > devm_add_action_or_reset() callbacks for de-initializing them when the > driver unloads. > > And finally the devm_iio_device_register() function can be use to register > the device. > > The remove hook can finally be removed and the spi_set_drvdata() call can > also be removed as the private data is no longer used. > > Signed-off-by: Alexandru Ardelean Applied to the togreg branch of iio.git and pushed out as testing. Thanks, Jonathan > --- > drivers/staging/iio/frequency/ad9832.c | 82 +++++++++++--------------- > 1 file changed, 36 insertions(+), 46 deletions(-) > > diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c > index 3f1981e287f5..f43464db618a 100644 > --- a/drivers/staging/iio/frequency/ad9832.c > +++ b/drivers/staging/iio/frequency/ad9832.c > @@ -294,6 +294,16 @@ static const struct iio_info ad9832_info = { > .attrs = &ad9832_attribute_group, > }; > > +static void ad9832_reg_disable(void *reg) > +{ > + regulator_disable(reg); > +} > + > +static void ad9832_clk_disable(void *clk) > +{ > + clk_disable_unprepare(clk); > +} > + > static int ad9832_probe(struct spi_device *spi) > { > struct ad9832_platform_data *pdata = dev_get_platdata(&spi->dev); > @@ -310,7 +320,6 @@ static int ad9832_probe(struct spi_device *spi) > if (!indio_dev) > return -ENOMEM; > > - spi_set_drvdata(spi, indio_dev); > st = iio_priv(indio_dev); > > st->avdd = devm_regulator_get(&spi->dev, "avdd"); > @@ -323,27 +332,35 @@ static int ad9832_probe(struct spi_device *spi) > return ret; > } > > + ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->avdd); > + if (ret) > + return ret; > + > st->dvdd = devm_regulator_get(&spi->dev, "dvdd"); > - if (IS_ERR(st->dvdd)) { > - ret = PTR_ERR(st->dvdd); > - goto error_disable_avdd; > - } > + if (IS_ERR(st->dvdd)) > + return PTR_ERR(st->dvdd); > > ret = regulator_enable(st->dvdd); > if (ret) { > dev_err(&spi->dev, "Failed to enable specified DVDD supply\n"); > - goto error_disable_avdd; > + return ret; > } > > + ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->dvdd); > + if (ret) > + return ret; > + > st->mclk = devm_clk_get(&spi->dev, "mclk"); > - if (IS_ERR(st->mclk)) { > - ret = PTR_ERR(st->mclk); > - goto error_disable_dvdd; > - } > + if (IS_ERR(st->mclk)) > + return PTR_ERR(st->mclk); > > ret = clk_prepare_enable(st->mclk); > if (ret < 0) > - goto error_disable_dvdd; > + return ret; > + > + ret = devm_add_action_or_reset(&spi->dev, ad9832_clk_disable, st->mclk); > + if (ret) > + return ret; > > st->spi = spi; > mutex_init(&st->lock); > @@ -394,60 +411,34 @@ static int ad9832_probe(struct spi_device *spi) > ret = spi_sync(st->spi, &st->msg); > if (ret) { > dev_err(&spi->dev, "device init failed\n"); > - goto error_unprepare_mclk; > + return ret; > } > > ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0); > if (ret) > - goto error_unprepare_mclk; > + return ret; > > ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1); > if (ret) > - goto error_unprepare_mclk; > + return ret; > > ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0); > if (ret) > - goto error_unprepare_mclk; > + return ret; > > ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1); > if (ret) > - goto error_unprepare_mclk; > + return ret; > > ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2); > if (ret) > - goto error_unprepare_mclk; > + return ret; > > ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3); > if (ret) > - goto error_unprepare_mclk; > - > - ret = iio_device_register(indio_dev); > - if (ret) > - goto error_unprepare_mclk; > - > - return 0; > - > -error_unprepare_mclk: > - clk_disable_unprepare(st->mclk); > -error_disable_dvdd: > - regulator_disable(st->dvdd); > -error_disable_avdd: > - regulator_disable(st->avdd); > - > - return ret; > -} > - > -static int ad9832_remove(struct spi_device *spi) > -{ > - struct iio_dev *indio_dev = spi_get_drvdata(spi); > - struct ad9832_state *st = iio_priv(indio_dev); > - > - iio_device_unregister(indio_dev); > - clk_disable_unprepare(st->mclk); > - regulator_disable(st->dvdd); > - regulator_disable(st->avdd); > + return ret; > > - return 0; > + return devm_iio_device_register(&spi->dev, indio_dev); > } > > static const struct spi_device_id ad9832_id[] = { > @@ -462,7 +453,6 @@ static struct spi_driver ad9832_driver = { > .name = "ad9832", > }, > .probe = ad9832_probe, > - .remove = ad9832_remove, > .id_table = ad9832_id, > }; > module_spi_driver(ad9832_driver);