Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2620094pxb; Sun, 17 Oct 2021 20:43:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcjk72G/43uq0nyvwMdXk1NSZClF3aNTVNLrhP4/2JhFptx8FaBy1ABBJgjspM00wuAxcT X-Received: by 2002:a17:90b:3684:: with SMTP id mj4mr45178298pjb.3.1634528612414; Sun, 17 Oct 2021 20:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528612; cv=none; d=google.com; s=arc-20160816; b=v14wujBinUz28HVWa2HmfGkpG40kX/uJBHZLy1wqJ6TTACgqC9KEj2afdtvQQpoAwS FVxC/bgv8+d8PiUObQdA/739BapHobrIBiqmPIRx0x8Ls3dPLQJ0y1HSv/4mA672y5cE uR4HpuMKLxFvwNRfoLtlFcaMwwtpLpzQHC0hxua64m2iVoPyoxvb0IuOEvu4/pm3oTp6 vcAvetx36NfxBDMoQEmQDehbY0CuIF38FaONBFa0yz2djgCS9UUIi+l0TiWb2mBp749t AfokJJcE+pPGvYA9yYsrkpoNpRxxYRi2psxWtxlvDL+CJu7v7hL6EqtYjXLQ8aJF8Wq0 EjuA== 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=9IkgC/3P22vfQGNlRqzxlMyAmaSRZ85eJSHA7IvPA2A=; b=uc6C7atoeKTb53uXquK61uHBpztMrWXjY/O/FqlmlW8i/doDRbxVQR0KvrZs5htBvi iwh7G7bfJvDsEZnA971Az/eMEcIZdP1Df5YCwZzm5NC4u8cYE/7fAMjxeAXeqlBVlbc8 1jfr58YN+6Oqu5GFLNKgBYjTGksdjknH91+ViBOp7rCPw3XKTuYIKoes6M0+eO+soN7l KL70adTuvJZbFyeB9D1BsdLglnU9XvFoJsAu5cEWiD0K10b9hhPXZgpHaGd9/+2tnto0 ftLMinONJaPfO2Hu0QfdL7BJgbNN3G+JyObDY9BbHliv5LLV4dWoJd4I52Urpr6b+5Ad uDdA== 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 u10si23390746pgg.339.2021.10.17.20.43.20; Sun, 17 Oct 2021 20:43:32 -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 S245522AbhJQLdb convert rfc822-to-8bit (ORCPT + 98 others); Sun, 17 Oct 2021 07:33:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242003AbhJQLda (ORCPT ); Sun, 17 Oct 2021 07:33:30 -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 41E3A61252; Sun, 17 Oct 2021 11:31:18 +0000 (UTC) Date: Sun, 17 Oct 2021 12:35:33 +0100 From: Jonathan Cameron To: =?UTF-8?B?QW5kcsOp?= Gustavo Nakagomi Lopez , linux-iio@vger.kernel.org Cc: lars@metafoo.de, vz@mleia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] iio: adc: lpc18xx_adc: Convert probe to device managed version Message-ID: <20211017123533.33883e16@jic23-huawei> In-Reply-To: References: 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=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 15 Oct 2021 15:47:12 -0300 André Gustavo Nakagomi Lopez wrote: > The remove function and the goto sections are not necessary if devm > functions are used. > > Convert device register to devm version. Add hook functions to release > device resources, and use them inside probe with devm_add_action, > which will release resources on driver detach. > > To maintain the order of which device resources were released/reseted, > register the hook functions as soon as resources are obtained/initialized. > Since devres actions are called on driver detach, the remove > function and the error-handling goto sections are no longer necessary. > > Signed-off-by: André Gustavo Nakagomi Lopez Hi André Looks good to me, but I did notice an unrelated issue whilst looking at this driver. Comment on that inline. Follow up patch welcome! Applied to the togreg branch of iio.git and pushed out as testing to let 0-day see if it can find anything we missed. Thanks, Jonathan > --- > Change log V1 -> V2: > -Renamed lpc18xx_clk_disable_unprepare function > -Removed platform_set_drvdata(pdev, indio_dev) > -Renamed lpc18xx_writel to lpc18xx_clear_cr_reg > -devm_iio_device_register now returns directly in the end of probe function > drivers/iio/adc/lpc18xx_adc.c | 61 ++++++++++++++++++----------------- > 1 file changed, 31 insertions(+), 30 deletions(-) > > diff --git a/drivers/iio/adc/lpc18xx_adc.c b/drivers/iio/adc/lpc18xx_adc.c > index 3566990ae87d..7d50107427ac 100644 > --- a/drivers/iio/adc/lpc18xx_adc.c > +++ b/drivers/iio/adc/lpc18xx_adc.c > @@ -115,6 +115,23 @@ static const struct iio_info lpc18xx_adc_info = { > .read_raw = lpc18xx_adc_read_raw, > }; > > +static void lpc18xx_clear_cr_reg(void *data) > +{ > + struct lpc18xx_adc *adc = data; > + > + writel(0, adc->base + LPC18XX_ADC_CR); > +} > + > +static void lpc18xx_clk_disable(void *clk) > +{ > + clk_disable_unprepare(clk); > +} > + > +static void lpc18xx_regulator_disable(void *vref) > +{ > + regulator_disable(vref); > +} > + > static int lpc18xx_adc_probe(struct platform_device *pdev) > { > struct iio_dev *indio_dev; > @@ -127,7 +144,6 @@ static int lpc18xx_adc_probe(struct platform_device *pdev) > if (!indio_dev) > return -ENOMEM; > > - platform_set_drvdata(pdev, indio_dev); > adc = iio_priv(indio_dev); > adc->dev = &pdev->dev; > mutex_init(&adc->lock); > @@ -163,44 +179,30 @@ static int lpc18xx_adc_probe(struct platform_device *pdev) > return ret; > } > > + ret = devm_add_action_or_reset(&pdev->dev, lpc18xx_regulator_disable, adc->vref); > + if (ret) > + return ret; > + > ret = clk_prepare_enable(adc->clk); > if (ret) { > dev_err(&pdev->dev, "unable to enable clock\n"); > - goto dis_reg; > + return ret; Unrelated but clk_get_rate() as called before the clk_prepare_enable() is not guaranteed to work. So a good follow up patch would reorder that to be after the clk is turned on. > } > > + ret = devm_add_action_or_reset(&pdev->dev, lpc18xx_clk_disable, > + adc->clk); > + if (ret) > + return ret; > + > adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) | > LPC18XX_ADC_CR_PDN; > writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR); > > - ret = iio_device_register(indio_dev); > - if (ret) { > - dev_err(&pdev->dev, "unable to register device\n"); > - goto dis_clk; > - } > - > - return 0; > - > -dis_clk: > - writel(0, adc->base + LPC18XX_ADC_CR); > - clk_disable_unprepare(adc->clk); > -dis_reg: > - regulator_disable(adc->vref); > - return ret; > -} > - > -static int lpc18xx_adc_remove(struct platform_device *pdev) > -{ > - struct iio_dev *indio_dev = platform_get_drvdata(pdev); > - struct lpc18xx_adc *adc = iio_priv(indio_dev); > - > - iio_device_unregister(indio_dev); > - > - writel(0, adc->base + LPC18XX_ADC_CR); > - clk_disable_unprepare(adc->clk); > - regulator_disable(adc->vref); > + ret = devm_add_action_or_reset(&pdev->dev, lpc18xx_clear_cr_reg, adc); > + if (ret) > + return ret; > > - return 0; > + return devm_iio_device_register(&pdev->dev, indio_dev); > } > > static const struct of_device_id lpc18xx_adc_match[] = { > @@ -211,7 +213,6 @@ MODULE_DEVICE_TABLE(of, lpc18xx_adc_match); > > static struct platform_driver lpc18xx_adc_driver = { > .probe = lpc18xx_adc_probe, > - .remove = lpc18xx_adc_remove, > .driver = { > .name = "lpc18xx-adc", > .of_match_table = lpc18xx_adc_match,