Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Frank Li <Frank.li@nxp.com>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Haibo Chen <haibo.chen@nxp.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-iio@vger.kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code
Date: Sat, 9 Nov 2024 13:04:44 +0000	[thread overview]
Message-ID: <20241109130444.78e4c1ec@jic23-huawei> (raw)
In-Reply-To: <Zy5inVdA4xy1qyrT@lizhi-Precision-Tower-5810>

On Fri, 8 Nov 2024 14:12:29 -0500
Frank Li <Frank.li@nxp.com> wrote:

> On Fri, Nov 08, 2024 at 07:13:20AM +0100, Christophe JAILLET wrote:
> > Le 07/11/2024 à 20:49, Frank Li a écrit :  
> > > On Thu, Nov 07, 2024 at 08:38:20PM +0100, Christophe JAILLET wrote:  
> > > > Le 07/11/2024 à 20:18, Frank Li a écrit :  
> > > > > Use devm_* and dev_err_probe() simplify probe function and remove
> > > > > vf610_adc_remove(). Change type of 'vref_uv' to int because
> > > > > regulator_get_voltage() return type is int.
> > > > >
> > > > > Reviewed-by: Haibo Chen <haibo.chen-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
> > > > > Signed-off-by: Frank Li <Frank.Li-3arQi8VN3Tc-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>
> > > > > ---  
> >
> > ...
> >  
> > > >  
> > > > >    	info->vref = devm_regulator_get(&pdev->dev, "vref");  
> > > >
> > > > With the change to devm_regulator_get_enable_read_voltage(), is it still
> > > > needed?  
> > >
> > > Suspend function need vref to disable regulator.  
> >
> > Ok.
> >
> > But why switch to devm_regulator_get_enable_read_voltage() then?
> > Shouldn't keeping regulator_get_voltage() be enough and simpler?  
> 
> Avoid goto err after devm_regulator_get_enable_read_voltage(), if use
> regulator_enable(), it needs regulator_disable() in err handle branch after
> it.

Don't get the same regulator twice - that works but is likely to be error
prone in the long run and is a bit too subtle.

This isn't an appropriate use of devm_regulator_get_enable_read_voltage()
Instead just use a local callback and
devm_add_action_or_reset() to disable the regulator in the devm tear down path.

Jonathan

> 
> Frank
> 
> >
> > CJ
> >  
> > >  
> > > >
> > > > CJ
> > > >  
> > > > >    	if (IS_ERR(info->vref))
> > > > >    		return PTR_ERR(info->vref);
> > > > > -	ret = regulator_enable(info->vref);
> > > > > -	if (ret)
> > > > > -		return ret;
> > > > > -
> > > > > -	info->vref_uv = regulator_get_voltage(info->vref);
> > > > > +	info->vref_uv = devm_regulator_get_enable_read_voltage(&pdev->dev, "vref");
> > > > > +	if (info->vref_uv < 0)
> > > > > +		return info->vref_uv;
> > > > >    	device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);  
> > > >
> > > > ...
> > > >  
> > >
> > >  
> >  


  reply	other threads:[~2024-11-09 13:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 19:18 [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Frank Li
2024-11-07 19:18 ` [PATCH v3 2/2] iio: adc: vf610_adc: limit i.MX6SX's channel number to 4 Frank Li
2024-11-09 13:11   ` Jonathan Cameron
2024-11-07 19:38 ` [PATCH v3 1/2] iio: adc: vf610_adc: use devm_* and dev_err_probe() to simple code Christophe JAILLET
2024-11-07 19:49   ` Frank Li
2024-11-08  6:13     ` Christophe JAILLET
2024-11-08 19:12       ` Frank Li
2024-11-09 13:04         ` Jonathan Cameron [this message]
2024-11-09 13:07 ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241109130444.78e4c1ec@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Frank.li@nxp.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=haibo.chen@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox