Linux kernel staging patches
 help / color / mirror / Atom feed
From: Tomas Borquez <tomasborquez13@gmail.com>
To: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-staging@lists.linux.dev
Subject: Re: [PATCH 2/5] staging: iio: ad9832: convert to guard(mutex)
Date: Thu, 18 Dec 2025 12:16:32 -0300	[thread overview]
Message-ID: <aUQa0IBuE7EITq9G@Lewboski.localdomain> (raw)
In-Reply-To: <aUQQ3YnaZau2RO2d@debian-BULLSEYE-live-builder-AMD64>

On Thu, Dec 18, 2025 at 11:34:05AM -0300, Marcelo Schmitt wrote:
> On 12/15, Tomas Borquez wrote:
...
> > -	mutex_lock(&st->lock);
> > +	guard(mutex)(&st->lock);
> >  	switch ((u32)this_attr->address) {
> >  	case AD9832_FREQ0HM:
> >  	case AD9832_FREQ1HM:
> > @@ -203,22 +205,18 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
> >  		ret = spi_sync(st->spi, &st->msg);
> >  		break;
> >  	case AD9832_FREQ_SYM:
> > -		if (val == 1 || val == 0) {
> > -			st->ctrl_fp &= ~AD9832_FREQ;
> > -			st->ctrl_fp |= FIELD_PREP(AD9832_FREQ, val ? 1 : 0);
> > -		} else {
> > -			ret = -EINVAL;
> > -			break;
> > -		}
> > +		if (val != 1 && val != 0)
> > +			return -EINVAL;
> > +
> > +		st->ctrl_fp &= ~AD9832_FREQ;
> > +		st->ctrl_fp |= FIELD_PREP(AD9832_FREQ, val ? 1 : 0);
> >  		st->data = cpu_to_be16(FIELD_PREP(AD9832_CMD_MSK, AD9832_CMD_FPSELECT) |
> >  						  st->ctrl_fp);
> >  		ret = spi_sync(st->spi, &st->msg);
> >  		break;
> Since we now have the mutex unlock handled by guard, why not returning directly
> from each case?
> E.g.
> 	case AD9832_FREQ1HM:
> -		ret = ad9832_write_frequency(st, this_attr->address, val);
> -		break;
> +		return ad9832_write_frequency(st, this_attr->address, val);
> I think the last return (outside the default clause) won't be needed anymore.
Wouldn't work because we need to return len too, so it would be more like:

 case AD9832_FREQ1HM:
		 ret = ad9832_write_frequency(st, this_attr->address, val);
+    return ret ?: len;

Which is a bit more repetitive than just returning at the end ret ?: len,
but lemme know what you think.

>
> And, since you are touching the lock, you may also update to use
> devm_mutex_init() (that would probably be best appreciated as a separate patch).

Yup, sounds good :)

Tomas

  reply	other threads:[~2025-12-18 15:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 19:08 [PATCH 0/5] staging: ad9832: driver cleanup Tomas Borquez
2025-12-15 19:08 ` [PATCH 1/5] staging: iio: ad9832: clean up whitespace Tomas Borquez
2025-12-18 14:27   ` Marcelo Schmitt
2025-12-21 19:17     ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 2/5] staging: iio: ad9832: convert to guard(mutex) Tomas Borquez
2025-12-18 14:34   ` Marcelo Schmitt
2025-12-18 15:16     ` Tomas Borquez [this message]
2025-12-21 19:22       ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 3/5] staging: iio: ad9832: cleanup dev_err_probe() Tomas Borquez
2025-12-18 14:38   ` Marcelo Schmitt
2025-12-21 19:25     ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 4/5] staging: iio: ad9832: convert to iio channels and ext_info attrs Tomas Borquez
2025-12-18 15:04   ` Marcelo Schmitt
2025-12-18 15:46     ` Tomas Borquez
2025-12-21 19:36   ` Jonathan Cameron
2025-12-15 19:08 ` [PATCH 5/5] staging: iio: ad9832: add sysfs documentation Tomas Borquez
2025-12-18 15:10   ` Marcelo Schmitt
2025-12-21 19:43     ` 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=aUQa0IBuE7EITq9G@Lewboski.localdomain \
    --to=tomasborquez13@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=nuno.sa@analog.com \
    /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