From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Lino Sanfilippo <LinoSanfilippo@gmx.de>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald <pmeerw@pmeerw.net>,
linux-iio <linux-iio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] iio:core: In map_array_register() cleanup in case of error
Date: Sun, 18 Oct 2020 10:56:31 +0100 [thread overview]
Message-ID: <20201018105631.5cb34b1d@archlinux> (raw)
In-Reply-To: <CAHp75VfQ=fFn_r43VPV0uPCkozS2K=VQsuSEyj0mF+7QVsFQuA@mail.gmail.com>
On Fri, 16 Oct 2020 18:09:48 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Sun, Oct 11, 2020 at 9:24 PM Lino Sanfilippo <LinoSanfilippo@gmx.de> wrote:
> >
> > In function map_array_register() properly rewind in case of error.
> > Furthermore remove the now superfluous initialization of "ret" with 0.
>
> > int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
> > {
> > - int i = 0, ret = 0;
> > + int i = 0, ret;
> > struct iio_map_internal *mapi;
> >
> > if (maps == NULL)
> > @@ -44,7 +44,18 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
> > list_add_tail(&mapi->l, &iio_map_list);
> > i++;
> > }
> > + mutex_unlock(&iio_map_list_lock);
> > +
> > + return 0;
> > +
> > error_ret:
>
> Wait a bit.
> First of all we linked all successfully added items to the list.
> From this we have two ways to go:
> - leave with as many maps as we registered
> - clean up and bail out
>
> I dunno which one would play better in IIO, but you seem to go with
> the latter one.
Better to cleanup and bail out I think. It's fairly unlikely
a consumer is going to be ready to cope with getting a partial
set of the channels it's expecting.
>
> > + /* undo */
> > + while (i--) {
> > + mapi = list_last_entry(&iio_map_list, struct iio_map_internal,
> > + l);
> > + list_del(&mapi->l);
> > + kfree(mapi);
> > + }
>
> We have iio_map_array_unregister(). Why not use it?
>
> > mutex_unlock(&iio_map_list_lock);
>
> I would rather drop a label with replacement goto -> break inside the
> loop and call the following
I argued for the goto, but it is indeed less obviously the right
thing to do once we are using iio_map_array_unregister.
>
>
> mutex_unlock(&iio_map_list_lock);
> if (ret)
> iio_map_array_unregister();
> return ret;
>
> Sounds like only a few LOCs are needed.
>
prev parent reply other threads:[~2020-10-18 9:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-11 12:41 [PATCH] iio:core: In map_array_register() cleanup in case of error Lino Sanfilippo
2020-10-11 15:07 ` Jonathan Cameron
2020-10-11 18:05 ` Lino Sanfilippo
2020-10-11 18:22 ` [PATCH v2] " Lino Sanfilippo
2020-10-16 15:09 ` Andy Shevchenko
2020-10-18 1:11 ` Lino Sanfilippo
2020-10-18 1:11 ` [PATCH 1/2] iio:core: Introduce unlocked version of iio_map_array_unregister() Lino Sanfilippo
2020-10-18 18:21 ` Andy Shevchenko
2020-10-18 1:11 ` [PATCH 2/2] iio:core: In iio_map_array_register() cleanup in case of error Lino Sanfilippo
2020-10-18 9:56 ` Jonathan Cameron [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=20201018105631.5cb34b1d@archlinux \
--to=jic23@kernel.org \
--cc=LinoSanfilippo@gmx.de \
--cc=andy.shevchenko@gmail.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.