Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2196323pxf; Sat, 13 Mar 2021 10:58:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyWCaEPme/KGwayaeEF6e56WhJOdFDCTqauKgmCh59/msCBr+7QhmGDCFZQBlHRUVhay3l X-Received: by 2002:a17:906:400b:: with SMTP id v11mr15145568ejj.194.1615661894924; Sat, 13 Mar 2021 10:58:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615661894; cv=none; d=google.com; s=arc-20160816; b=LSPZSBVIlovs1s8nH6LAPSIJsMcQS9pKJbhbm5BVSbYwMhpHkMsYbOhxv7cH2fTk+U kvKwuMC09rI0j0+w2pozIh/4mj6BmaW3vYV1CSU6zyWmiBidCmGSf0KQN7Cb5bgB9wAa uTaads88CEhlbVJsgHnN8Ru27Uw5hIsLxhtwkNyMKruv1eGcHhRIhtYGuuuCgLJwt83m YI3y1XZt4YJmzkUp9v70K9D9hq0t6MGWdCqXn8xWRL6qdxvMK2I7C/D7HuWqlmAJaLW9 bFUXdcaj5dkOnIHIkBhokdkzi3H/n7J5YlCs8YcLu+0iu/PuvCiLFA0iYDGGJe03EKtJ WVtw== 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=K9dci0Z0u/V7yfQNKHCmE8VKWarirDq5Crfrm4/KRIU=; b=BVfJulAG1xcbX0D5Y228+qmkhgc34D6PLEK811HiHh+WmxFvxfeQoYqTPJKOjKxbFA a+Yau3GxiSiL2kIur67qvKjfvXeeMDdGo2SWn8noZBIJyONusUH/+gCRPmRWniVSaoFN TMLK+VHV/4UK3iRtDUMlDayaI6t0OmFN/GZJ9HRkd0/LobNZdiP3/Kg2IpzQEBE8xwBl E2rYvuqJDjD/0ctjBtLsV7pdu/oLph4VHnNcGEQtN1s7pk1nhSSFhArCGiR/1zJPcW+6 FYRKWYX3jnUKehtWkmuLy46dLO2e98Po+yKv0SZmGrOQv7QAnoU5swIHA2FQy6PfMS8o n8DA== 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 f11si6919028ejr.284.2021.03.13.10.57.52; Sat, 13 Mar 2021 10:58:14 -0800 (PST) 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 S234367AbhCMSzA (ORCPT + 99 others); Sat, 13 Mar 2021 13:55:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:40560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234329AbhCMSy6 (ORCPT ); Sat, 13 Mar 2021 13:54:58 -0500 Received: from archlinux (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 523AE64E54; Sat, 13 Mar 2021 18:54:56 +0000 (UTC) Date: Sat, 13 Mar 2021 18:54:53 +0000 From: Jonathan Cameron To: Alexandru Ardelean Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Michael.Hennerich@analog.com, gregkh@linuxfoundation.org, linux@deviqon.com Subject: Re: [PATCH] staging: iio: ad9834: convert to device-managed functions in probe Message-ID: <20210313185453.76f2518c@archlinux> In-Reply-To: <20210310095131.47476-1-aardelean@deviqon.com> References: <20210310095131.47476-1-aardelean@deviqon.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; 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 Wed, 10 Mar 2021 11:51:31 +0200 Alexandru Ardelean wrote: > This change converts the driver to use device-managed functions in the > probe function. For the clock and regulator disable, some > devm_add_action_or_reset() calls are required, and then > devm_iio_device_register() function can be used register the IIO device. > > The final aim here would be for IIO to export only the device-managed > functions of it's API. That's a long way to go and this a small step in > that direction. > > Signed-off-by: Alexandru Ardelean I tweaked this a little to drop st->reg as it's no longer used. Applied to the togreg branch of iio.git and pushed out as testing for allow the autobuilders to poke randomly at it. Thanks, Jonathan > --- > drivers/staging/iio/frequency/ad9834.c | 64 +++++++++++++------------- > 1 file changed, 31 insertions(+), 33 deletions(-) > > diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c > index 262c3590e64e..b063cfd0e0e1 100644 > --- a/drivers/staging/iio/frequency/ad9834.c > +++ b/drivers/staging/iio/frequency/ad9834.c > @@ -390,6 +390,20 @@ static const struct iio_info ad9833_info = { > .attrs = &ad9833_attribute_group, > }; > > +static void ad9834_disable_reg(void *data) > +{ > + struct regulator *reg = data; > + > + regulator_disable(reg); > +} > + > +static void ad9834_disable_clk(void *data) > +{ > + struct clk *clk = data; > + > + clk_disable_unprepare(clk); > +} > + > static int ad9834_probe(struct spi_device *spi) > { > struct ad9834_state *st; > @@ -407,26 +421,33 @@ static int ad9834_probe(struct spi_device *spi) > return ret; > } > > + ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_reg, reg); > + if (ret) > + return ret; > + > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); > if (!indio_dev) { > ret = -ENOMEM; > - goto error_disable_reg; > + return ret; > } > - spi_set_drvdata(spi, indio_dev); > st = iio_priv(indio_dev); > mutex_init(&st->lock); > st->mclk = devm_clk_get(&spi->dev, NULL); > if (IS_ERR(st->mclk)) { > ret = PTR_ERR(st->mclk); > - goto error_disable_reg; > + return ret; > } > > ret = clk_prepare_enable(st->mclk); > if (ret) { > dev_err(&spi->dev, "Failed to enable master clock\n"); > - goto error_disable_reg; > + return ret; > } > > + ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_clk, st->mclk); > + if (ret) > + return ret; > + > st->spi = spi; > st->devid = spi_get_device_id(spi)->driver_data; > st->reg = reg; > @@ -470,48 +491,26 @@ static int ad9834_probe(struct spi_device *spi) > ret = spi_sync(st->spi, &st->msg); > if (ret) { > dev_err(&spi->dev, "device init failed\n"); > - goto error_clock_unprepare; > + return ret; > } > > ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, 1000000); > if (ret) > - goto error_clock_unprepare; > + return ret; > > ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, 5000000); > if (ret) > - goto error_clock_unprepare; > + return ret; > > ret = ad9834_write_phase(st, AD9834_REG_PHASE0, 512); > if (ret) > - goto error_clock_unprepare; > + return ret; > > ret = ad9834_write_phase(st, AD9834_REG_PHASE1, 1024); > if (ret) > - goto error_clock_unprepare; > - > - ret = iio_device_register(indio_dev); > - if (ret) > - goto error_clock_unprepare; > - > - return 0; > -error_clock_unprepare: > - clk_disable_unprepare(st->mclk); > -error_disable_reg: > - regulator_disable(reg); > - > - return ret; > -} > - > -static int ad9834_remove(struct spi_device *spi) > -{ > - struct iio_dev *indio_dev = spi_get_drvdata(spi); > - struct ad9834_state *st = iio_priv(indio_dev); > - > - iio_device_unregister(indio_dev); > - clk_disable_unprepare(st->mclk); > - regulator_disable(st->reg); > + return ret; > > - return 0; > + return devm_iio_device_register(&spi->dev, indio_dev); > } > > static const struct spi_device_id ad9834_id[] = { > @@ -539,7 +538,6 @@ static struct spi_driver ad9834_driver = { > .of_match_table = ad9834_of_match > }, > .probe = ad9834_probe, > - .remove = ad9834_remove, > .id_table = ad9834_id, > }; > module_spi_driver(ad9834_driver);