Linux-IIO Archive mirror
 help / color / mirror / Atom feed
From: ChiYuan Huang <cy_huang@richtek.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Gabriel Schwartz <gschwartz@usp.br>, <linux-iio@vger.kernel.org>
Subject: Re: [PATCH] iio: adc: rtq6056: Use automated cleanup for mode handling in write_raw
Date: Mon, 29 Apr 2024 09:52:37 +0800	[thread overview]
Message-ID: <340CF1714359733000.cy_huang@richtek.com> (raw)
In-Reply-To: <20240428125129.1605a09d@jic23-huawei>

On Sun, Apr 28, 2024 at 12:51:29PM +0100, Jonathan Cameron wrote:
> On Fri, 26 Apr 2024 17:01:14 -0300
> Gabriel Schwartz <gschwartz@usp.br> wrote:
> 
> > Using iio_device_claim_direct_scoped() to automate mode claim and release
> > simplifies code flow and allows for straight-forward error handling with
> > direct returns on errors.
> > 
> > Signed-off-by: Gabriel Schwartz <gschwartz@usp.br>
Hi,

Patch looks good. Thanks.

Reviewed-by: ChiYuan Huang <cy_huang@richtek.com>

> +CC driver author.  This is a fairly recent driver, so like they are still
> around.
> 
> Patch looks good so I'll apply it but if ChiYuan Huang gives a review that would
> be great.
> 
> Thanks,
> 
> Jonathan
> 
> 
> > ---
> >  drivers/iio/adc/rtq6056.c | 34 +++++++++++-----------------------
> >  1 file changed, 11 insertions(+), 23 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/rtq6056.c b/drivers/iio/adc/rtq6056.c
> > index a5464737e..bcb129840 100644
> > --- a/drivers/iio/adc/rtq6056.c
> > +++ b/drivers/iio/adc/rtq6056.c
> > @@ -520,32 +520,20 @@ static int rtq6056_adc_write_raw(struct iio_dev *indio_dev,
> >  {
> >  	struct rtq6056_priv *priv = iio_priv(indio_dev);
> >  	const struct richtek_dev_data *devdata = priv->devdata;
> > -	int ret;
> >  
> > -	ret = iio_device_claim_direct_mode(indio_dev);
> > -	if (ret)
> > -		return ret;
> > -
> > -	switch (mask) {
> > -	case IIO_CHAN_INFO_SAMP_FREQ:
> > -		if (devdata->fixed_samp_freq) {
> > -			ret = -EINVAL;
> > -			break;
> > +	iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> > +		switch (mask) {
> > +		case IIO_CHAN_INFO_SAMP_FREQ:
> > +			if (devdata->fixed_samp_freq)
> > +				return -EINVAL;
> > +			return rtq6056_adc_set_samp_freq(priv, chan, val);
> > +		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > +			return devdata->set_average(priv, val);
> > +		default:
> > +			return -EINVAL;
> >  		}
> > -
> > -		ret = rtq6056_adc_set_samp_freq(priv, chan, val);
> > -		break;
> > -	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> > -		ret = devdata->set_average(priv, val);
> > -		break;
> > -	default:
> > -		ret = -EINVAL;
> > -		break;
> >  	}
> > -
> > -	iio_device_release_direct_mode(indio_dev);
> > -
> > -	return ret;
> > +	unreachable();
> >  }
> >  
> >  static const char *rtq6056_channel_labels[RTQ6056_MAX_CHANNEL] = {
> 

      reply	other threads:[~2024-04-29  3:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26 20:01 [PATCH] iio: adc: rtq6056: Use automated cleanup for mode handling in write_raw Gabriel Schwartz
2024-04-27 11:35 ` Marcelo Schmitt
2024-04-28 11:51 ` Jonathan Cameron
2024-04-29  1:52   ` ChiYuan Huang [this message]

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=340CF1714359733000.cy_huang@richtek.com \
    --to=cy_huang@richtek.com \
    --cc=gschwartz@usp.br \
    --cc=jic23@kernel.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).