devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Nuno Sa <nuno.sa@analog.com>,
	linux-iio@vger.kernel.org,  devicetree@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>,
	 Michael Hennerich <Michael.Hennerich@analog.com>,
	Rob Herring <robh+dt@kernel.org>,
	 Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	 Frank Rowand <frowand.list@gmail.com>,
	Olivier Moysan <olivier.moysan@foss.st.com>
Subject: Re: [PATCH v10 5/7] iio: add the IIO backend framework
Date: Sat, 10 Feb 2024 18:45:53 +0200	[thread overview]
Message-ID: <CAHp75VfVK_9wr+fVLkMLoQk+ONgKNdpTdBodJSXE6msim_woaw@mail.gmail.com> (raw)
In-Reply-To: <20240210164152.49d5406a@jic23-huawei>

On Sat, Feb 10, 2024 at 6:42 PM Jonathan Cameron <jic23@kernel.org> wrote:
> On Fri, 9 Feb 2024 18:30:53 +0200
> Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> > On Fri, Feb 9, 2024 at 5:26 PM Nuno Sa <nuno.sa@analog.com> wrote:

...

> > > +struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name)
> > > +{
> > > +       struct fwnode_handle *fwnode;
> > > +       struct iio_backend *back;
> > > +       unsigned int index;
> > > +       int ret;
> > > +
> > > +       if (name) {
> > > +               ret = device_property_match_string(dev, "io-backend-names",
> > > +                                                  name);
> > > +               if (ret < 0)
> > > +                       return ERR_PTR(ret);
> > > +               index = ret;
> > > +       } else {
> > > +               index = 0;
> > > +       }
> > > +
> > > +       fwnode = fwnode_find_reference(dev_fwnode(dev), "io-backends", index);
> > > +       if (IS_ERR(fwnode)) {
> > > +               dev_err_probe(dev, PTR_ERR(fwnode),
> > > +                             "Cannot get Firmware reference\n");
> > > +               return ERR_CAST(fwnode);
> > > +       }
> > > +
> > > +       guard(mutex)(&iio_back_lock);
> > > +       list_for_each_entry(back, &iio_back_list, entry) {
> > > +               if (!device_match_fwnode(back->dev, fwnode))
> > > +                       continue;
> >
> > > +               fwnode_handle_put(fwnode);
> > > +               ret = __devm_iio_backend_get(dev, back);
> >
> > This order makes me think about the reference counting. So, fwnode is
> > the one of the backend devices to which the property points to.
> > Another piece is the local (to this framework) list that keeps backend
> > devices. So, fwnode reference can be  dropped earlier, while the usual
> > pattern to interleave gets and puts in a chain. Dunno if above needs a
> > comment, reordering or nothing.
> >
> I'm lost. Why don't we need to hold fwnode reference for the
> device_match_fwnode() just before here?

> Or do you mean that we are safe here with the fwnode_handle_put() being
> before the __devm_iio_backend_get()?

This one.

> I think you are correct that the
> lifetimes are fine as we switched from the fwnode to the
> iio_backend from the list at this point.
>
> > > +               if (ret)
> > > +                       return ERR_PTR(ret);
> > > +
> > > +               return back;
> > > +       }
> > > +
> > > +       fwnode_handle_put(fwnode);
> > > +       return ERR_PTR(-EPROBE_DEFER);
> >
> > While thinking about the above, I noticed the room to refactor.
> >
> >   list_for_each_entry(...) {
> >     if (...)
> >       break;
> >   }
> >   fwnode_handle_put(...);
> >   // Yes, we may use the below macro as the (global) pointers are
> > protected by a mutex.
> >   if (list_entry_is_head(...))
>
> Knowing that means we failed to match is a bit obscure.
>
> >     return ERR_PTR(...);
> >
> >   ret = __devm_iio_backend_get(...);
> >   ...
>
> Maybe - it's a little ugly either way.  I don't think we care about
> potentially holding the fwnode handle too long, so flipping over to
> the cleanup.h handling (I need to get back to that sometime this week)
> will make this all simpler.

Yes, I agree with your point of view. That's why I'm not insisting on
this change.

> > > +}


-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2024-02-10 16:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 15:28 [PATCH v10 0/7] iio: add new backend framework Nuno Sa
2024-02-09 15:28 ` [PATCH v10 1/7] dt-bindings: adc: ad9467: add new io-backend property Nuno Sa
2024-02-09 15:28 ` [PATCH v10 2/7] dt-bindings: adc: axi-adc: update bindings for backend framework Nuno Sa
2024-02-09 15:28 ` [PATCH v10 3/7] of: property: add device link support for io-backends Nuno Sa
2024-02-09 15:28 ` [PATCH v10 4/7] iio: buffer-dmaengine: export buffer alloc and free functions Nuno Sa
2024-02-09 15:28 ` [PATCH v10 5/7] iio: add the IIO backend framework Nuno Sa
2024-02-09 16:19   ` Andy Shevchenko
2024-02-09 16:30   ` Andy Shevchenko
2024-02-10 16:41     ` Jonathan Cameron
2024-02-10 16:45       ` Andy Shevchenko [this message]
2024-02-09 15:28 ` [PATCH v10 6/7] iio: adc: ad9467: convert to " Nuno Sa
2024-02-09 16:37   ` Andy Shevchenko
2024-02-10 20:58     ` Nuno Sá
2024-02-09 15:28 ` [PATCH v10 7/7] iio: adc: adi-axi-adc: move " Nuno Sa
2024-02-09 16:45   ` Andy Shevchenko
2024-02-10 20:58     ` Nuno Sá
2024-02-09 16:46 ` [PATCH v10 0/7] iio: add new " 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=CAHp75VfVK_9wr+fVLkMLoQk+ONgKNdpTdBodJSXE6msim_woaw@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=olivier.moysan@foss.st.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 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 NNTP newsgroup(s).