From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Nuno Sa <nuno.sa@analog.com>, <linux-iio@vger.kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v3 3/4] iio: buffer: iio: core: move to the cleanup.h magic
Date: Mon, 18 Mar 2024 12:35:39 +0000 [thread overview]
Message-ID: <20240318123539.000057b6@Huawei.com> (raw)
In-Reply-To: <ZfX1HGqT1LwA2b73@surfacebook.localdomain>
On Sat, 16 Mar 2024 21:38:04 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> Thu, Feb 29, 2024 at 04:10:27PM +0100, Nuno Sa kirjoitti:
> > Use the new cleanup magic for handling mutexes in IIO. This allows us to
> > greatly simplify some code paths.
>
> ...
>
> > ret = iio_scan_mask_query(indio_dev, buffer, this_attr->address);
> > if (ret < 0)
> > - goto error_ret;
> > - if (!state && ret) {
> > - ret = iio_scan_mask_clear(buffer, this_attr->address);
> > - if (ret)
> > - goto error_ret;
> > - } else if (state && !ret) {
> > + return ret;
> > +
> > + if (state && ret)
> > + return len;
>
> I would leave the original checks. It's natural pattern
>
> if (foo && !bar)
> if (!foo && bar) // or 'else if' depending on the context
>
> > + if (state)
> > ret = iio_scan_mask_set(indio_dev, buffer, this_attr->address);
> > - if (ret)
> > - goto error_ret;
> > - }
> > + else
> > + ret = iio_scan_mask_clear(buffer, this_attr->address);
> > + if (ret)
> > + return ret;
> >
> > -error_ret:
> > - mutex_unlock(&iio_dev_opaque->mlock);
> > -
> > - return ret < 0 ? ret : len;
> > + return len;
>
> ...
>
> > /* Already in desired state */
> > if (inlist == requested_state)
> > - goto done;
> > + return len;
>
> Returning error code immediately is fine, but splitting return success seems to
> me a bit too much. It is harder to follow (you really need to understand how many
> "success" variants can be).
The pattern of detecting 'nothing to do' and existing early is pretty common.
I agree that it gets dubious if there are lots of early 'success' exits, but
this one case seems reasonable to me.
Jonathan
>
> > if (requested_state)
> > ret = __iio_update_buffers(indio_dev, buffer, NULL);
> > else
> > ret = __iio_update_buffers(indio_dev, NULL, buffer);
> > + if (ret)
> > + return ret;
> >
> > -done:
> > - mutex_unlock(&iio_dev_opaque->mlock);
> > - return (ret < 0) ? ret : len;
> > + return len;
> > }
>
next prev parent reply other threads:[~2024-03-18 12:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 15:10 [PATCH v3 0/4] iio: move IIO to the cleanup.h magic Nuno Sa
2024-02-29 15:10 ` [PATCH v3 1/4] iio: core: move to " Nuno Sa
2024-02-29 15:10 ` [PATCH v3 2/4] iio: trigger: move to the " Nuno Sa
2024-03-16 19:32 ` Andy Shevchenko
2024-03-18 12:33 ` Jonathan Cameron
2024-03-18 13:12 ` Andy Shevchenko
2024-03-18 14:15 ` Jonathan Cameron
2024-03-16 19:39 ` Andy Shevchenko
2024-03-18 9:22 ` Nuno Sá
2024-02-29 15:10 ` [PATCH v3 3/4] iio: buffer: iio: core: " Nuno Sa
2024-03-16 19:38 ` Andy Shevchenko
2024-03-18 9:23 ` Nuno Sá
2024-03-18 12:35 ` Jonathan Cameron [this message]
2024-03-16 19:49 ` Andy Shevchenko
2024-02-29 15:10 ` [PATCH v3 4/4] iio: inkern: " Nuno Sa
2024-03-03 14:24 ` Jonathan Cameron
2024-03-04 8:04 ` Nuno Sá
2024-03-09 17:41 ` Jonathan Cameron
2024-03-16 13:26 ` Jonathan Cameron
2024-03-16 19:48 ` Andy Shevchenko
2024-03-18 9:20 ` Nuno Sá
2024-03-23 18:09 ` 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=20240318123539.000057b6@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=andy.shevchenko@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--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