All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Marcus Folkesson <marcus.folkesson@gmail.com>,
	Kent Gustavsson <kent@minoris.se>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 02/10] iio: adc: mcp3911: use resource-managed version of iio_device_register
Date: Tue, 28 Jun 2022 14:01:08 +0200	[thread overview]
Message-ID: <CAHp75Vdr87rXRAKHtxftkPEbS+2yAp8a+Cp1Jx0XnozL+WCKVw@mail.gmail.com> (raw)
In-Reply-To: <20220625122429.14e98106@jic23-huawei>

On Sat, Jun 25, 2022 at 1:15 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Fri, 24 Jun 2022 08:29:20 +0200
> Marcus Folkesson <marcus.folkesson@gmail.com> wrote:
>
> > Thank you for your comments (all of them) Andy!
> >
> > On Thu, Jun 23, 2022 at 09:01:59PM +0200, Andy Shevchenko wrote:
> > > On Thu, Jun 23, 2022 at 7:40 PM Marcus Folkesson
> > > <marcus.folkesson@gmail.com> wrote:
> > > >
> > > > Keep using managed resources as much as possible.
> > >
> > > You may not mix devm_ and non-devm_ API calls like this.
> > > So, you rule of thumb that goto is most of the time wrong after devm_ call.
> >
> > Can you please confirm that clocks and regulators are disabled when the
> > resources are handed back?
> > I cannot see where when I'm trying to follow the code.
> Andy isn't arguing that the goto is wrong but rather that you cannot
> in general safely use devm_* calls if their failure leads to having to
> do any cleanup.  The reason is the ordering is hard to reason about. Sometimes
> it's safe, but often enough causes problems that we basically refuse to think
> hard enough to figure out if it is.  Hence basic rule is don't do it.
>
> The issue is this.
> probe() {
>
>         non_devm_call_1();
>         ret = devm_call_2()
>         if (ret)
>                 goto err;
>
>         return 0;
> err:
>         unwind_non_devm_call_1()
> }
>
> remove() {
>         unwind_non_devm_call_1()
> }
>
> remove or error path should unwind in opposite order of what happens in probe.
> On the rare occasion where that isn't the right choice, there should be very
> clear comments to say why.
>
> Order is
>
> remove() -> unwind_non_devm_call_1()
> devm_managed_cleanup() -> unwind_devm_call_2()
>
> Whereas should be
>
> remove()-> unwind_call_2() then unwind_call_1()
>
>
> There are two ways to solve this.  Either only use devm for those
> elements in probe() that happen before the first thing you need to
> unwind manually or make everything devm managed (it unwinds in reverse
> order of setup) devm_add_action_or_reset() allows you to use your
> own devm_ managed callbacks if there isn't a standard one available.

Thanks, Jonathan, that's exactly what I meant!

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2022-06-28 12:01 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 17:08 [PATCH 01/10] iio: adc: mcp3911: correct "microchip,device-addr" property Marcus Folkesson
2022-06-23 17:08 ` [PATCH 02/10] iio: adc: mcp3911: use resource-managed version of iio_device_register Marcus Folkesson
2022-06-23 19:01   ` Andy Shevchenko
2022-06-24  6:29     ` Marcus Folkesson
2022-06-25 11:24       ` Jonathan Cameron
2022-06-28 12:01         ` Andy Shevchenko [this message]
2022-06-23 17:08 ` [PATCH 03/10] iio: adc: mcp3911: add support for buffers Marcus Folkesson
2022-06-23 17:08 ` [PATCH 04/10] iio: adc: mcp3911: add support for interrupts Marcus Folkesson
2022-06-23 19:04   ` Andy Shevchenko
2022-06-24 12:01     ` Marcus Folkesson
2022-06-23 17:08 ` [PATCH 05/10] dt-bindings: iio: adc: mcp3911: add microchip,data-ready-hiz entry Marcus Folkesson
2022-06-24  9:54   ` Krzysztof Kozlowski
2022-06-24 12:10     ` Marcus Folkesson
2022-06-24 17:26   ` Rob Herring
2022-06-23 17:08 ` [PATCH 06/10] iio: adc: mcp3911: add support for oversampling ratio Marcus Folkesson
2022-06-23 19:20   ` Andy Shevchenko
2022-06-24 12:09     ` Marcus Folkesson
2022-06-28 11:56       ` Andy Shevchenko
2022-06-23 17:08 ` [PATCH 07/10] iio: adc: mcp3911: use correct formula for AD conversion Marcus Folkesson
2022-06-23 17:08 ` [PATCH 08/10] iio: adc: mcp3911: add support for phase Marcus Folkesson
2022-06-23 19:07   ` Andy Shevchenko
2022-06-24 12:02     ` Marcus Folkesson
2022-06-25 11:33       ` Jonathan Cameron
2022-06-23 17:08 ` [PATCH 09/10] iio: adc: mcp3911: make use of the sign bit Marcus Folkesson
2022-06-23 17:08 ` [PATCH 10/10] iio: adc: mcp3911: add support to set PGA Marcus Folkesson
2022-06-23 17:26   ` Marcus Folkesson
2022-06-23 19:15   ` Andy Shevchenko
2022-06-24 12:05     ` Marcus Folkesson
2022-06-23 18:59 ` [PATCH 01/10] iio: adc: mcp3911: correct "microchip,device-addr" property Andy Shevchenko

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=CAHp75Vdr87rXRAKHtxftkPEbS+2yAp8a+Cp1Jx0XnozL+WCKVw@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=kent@minoris.se \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcus.folkesson@gmail.com \
    --cc=robh+dt@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 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.