From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 263ABC433EF for ; Sun, 17 Oct 2021 13:34:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DCC1060F8F for ; Sun, 17 Oct 2021 13:34:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DCC1060F8F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=usp.br Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NgvImFQFvT8Fw2guz7QguwL+88anzW6FB4QSMt9/uzk=; b=FK6umV5bzjtt9Z 2iD3BTmUOi1EU5y/NmiwHT9h6k/hQogvfQa/BZawjF3i1NCpFOx7zJr52agXfny5DeVVj8NWwo1WJ k2QtL/pI9bMcZJZgT6mJhYfyEiNshV79mslepJ0Iuq6gK8n3xlEcUV1GB6BHPRcEZx2BAU/UGzTFA tmiUeqxefMOocXrmz8JONL2oIG3pTHqBWuHVIA/NLuQMoJucwAM2YeMpWAw2J6GO6FuhZ2rZFWf+Q BCl0C4GwDJfNslyCLuZmJYbzAVMjGkd0upnnzIIfcIM3fWTY3o50vDlCeCYylzlnmsfdF/RDFxEka a0gDv1PBgdd6tMmb3zzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc6Hw-00CezC-Ig; Sun, 17 Oct 2021 13:33:20 +0000 Received: from mail-ua1-x932.google.com ([2607:f8b0:4864:20::932]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mc6Hr-00Cexy-3h for linux-arm-kernel@lists.infradead.org; Sun, 17 Oct 2021 13:33:18 +0000 Received: by mail-ua1-x932.google.com with SMTP id f4so933584uad.4 for ; Sun, 17 Oct 2021 06:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=jWRL5QHYGlFrwRX9nfH0NjktXPsAElv+E6acDVOY5Wo=; b=qjcieQJ/A8crbHHht2Dmi+g5WnQWFklzzXJxq7mO3JE30SquF61AKESe2W7RnSJY/K UXRybWTl55edYG2Hp6vkavuXrFNMXqZkqdUV6vLO5xPnkIfvXbIpq57NM1bb2GOd3UgX ZA1bQCHYKV8/04lg8ha+tKyCySQwosSXBhnk1vgnmgR5+4VLjdQF0T/vq3K8Kd7LGFhx kCpiDgvIEIyOzB9Y/KNqHDhcWAv01NtOr2zAqr5Ih1XEEnrj4pAYMpFtOrkGPUVk8MyT aVW30JqrWmLp3wAjpyRWnIUPpT7ycXBs7WKjiUZvARuZacQadWeVE2vMP/1+vTUCOyTC cNYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=jWRL5QHYGlFrwRX9nfH0NjktXPsAElv+E6acDVOY5Wo=; b=t71Ce2+20dsYlA8UUvpDOqUkt/wEyVk5ahuvA3N6jZ08NxJHRHIwjAO1ZGGeuZq+Hq Lv1a0/8pT0jEq4H5lbRaDF7CfL+uaNOvq+FjT6hvvvt7eCZYpa9Qdpft4bsWEp9/s+Zf YLrVdTKwWfB+5V8pxrm61l5jDgyS3rd3cphVT71DZJyyM+8ocm2+CnXd1JvcoAJ0Q0MF /8tZN2HaWtQ5qc/b2YTTknkFWuPE9WnHQ6E1IEDd1/5yCY6dBtuPER7RlU0ARpUL8UCS On/tpWIMn500idEGhA2B1aEq4Qtvqqn8xc8KSXR6hSUoUopACFhSfOeqX4ht3QTTSqo1 6v/A== X-Gm-Message-State: AOAM532ZhZye4bdHJz1HiLlE6VZ9M6Ijkk8rzQQ9eBdfJLYaAuCpvya5 jbyzysXmzzQGs1d+8wof+ybSQg== X-Google-Smtp-Source: ABdhPJx3wFK8LQbniuUqDwt6+6Ukbw3fJXLi9Bt4tjRv3cdcV0kSwLUO4P9GhElMXzHZNBl9aWrEOQ== X-Received: by 2002:a67:d78e:: with SMTP id q14mr693980vsj.55.1634477592376; Sun, 17 Oct 2021 06:33:12 -0700 (PDT) Received: from Andryuu.br ([2804:431:c7fd:7238:311d:169e:a665:1173]) by smtp.gmail.com with ESMTPSA id n3sm1728662vsq.28.2021.10.17.06.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Oct 2021 06:33:11 -0700 (PDT) Date: Sun, 17 Oct 2021 10:33:08 -0300 From: =?iso-8859-1?Q?Andr=E9?= Gustavo Nakagomi Lopez To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, 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: References: <20211017123533.33883e16@jic23-huawei> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211017123533.33883e16@jic23-huawei> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211017_063315_709079_8D006C53 X-CRM114-Status: GOOD ( 33.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, Oct 17, 2021 at 12:35:33PM +0100, Jonathan Cameron wrote: > On Fri, 15 Oct 2021 15:47:12 -0300 > Andr=E9 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/initializ= ed. > > 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=E9 Gustavo Nakagomi Lopez > = > Hi Andr=E9 > = > Looks good to me, but I did notice an unrelated issue whilst looking at t= his 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 pro= be 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_ad= c.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 =3D { > > .read_raw =3D lpc18xx_adc_read_raw, > > }; > > = > > +static void lpc18xx_clear_cr_reg(void *data) > > +{ > > + struct lpc18xx_adc *adc =3D 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 =3D iio_priv(indio_dev); > > adc->dev =3D &pdev->dev; > > mutex_init(&adc->lock); > > @@ -163,44 +179,30 @@ static int lpc18xx_adc_probe(struct platform_devi= ce *pdev) > > return ret; > > } > > = > > + ret =3D devm_add_action_or_reset(&pdev->dev, lpc18xx_regulator_disabl= e, adc->vref); > > + if (ret) > > + return ret; > > + > > ret =3D 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 c= lk is turned on. > = > = > > } > > = > > + ret =3D devm_add_action_or_reset(&pdev->dev, lpc18xx_clk_disable, > > + adc->clk); > > + if (ret) > > + return ret; > > + > > adc->cr_reg =3D (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) | > > LPC18XX_ADC_CR_PDN; > > writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR); > > = > > - ret =3D 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 =3D platform_get_drvdata(pdev); > > - struct lpc18xx_adc *adc =3D 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 =3D devm_add_action_or_reset(&pdev->dev, lpc18xx_clear_cr_reg, ad= c); > > + if (ret) > > + return ret; > > = > > - return 0; > > + return devm_iio_device_register(&pdev->dev, indio_dev); > > } > > = > > static const struct of_device_id lpc18xx_adc_match[] =3D { > > @@ -211,7 +213,6 @@ MODULE_DEVICE_TABLE(of, lpc18xx_adc_match); > > = > > static struct platform_driver lpc18xx_adc_driver =3D { > > .probe =3D lpc18xx_adc_probe, > > - .remove =3D lpc18xx_adc_remove, > > .driver =3D { > > .name =3D "lpc18xx-adc", > > .of_match_table =3D lpc18xx_adc_match, > = Ok. Thank you for the review, I will work on the change. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel