devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Daniel Scally <djrscally@gmail.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Hans de Goede <hdegoede@redhat.com>,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Subject: Re: [PATCH v2 1/6] device property: Helper to match multiple connections
Date: Mon, 21 Feb 2022 19:19:22 +0200	[thread overview]
Message-ID: <YhPJmiFSH8s94il7@smile.fi.intel.com> (raw)
In-Reply-To: <YhMbLsvF8p/ce+mg@ripper>

On Sun, Feb 20, 2022 at 08:55:10PM -0800, Bjorn Andersson wrote:
> On Sun 20 Feb 03:16 PST 2022, Andy Shevchenko wrote:
> > On Fri, Feb 18, 2022 at 11:00:45AM -0800, Bjorn Andersson wrote:
> > > On Wed 09 Feb 04:30 PST 2022, Andy Shevchenko wrote:
> > > > On Mon, Feb 07, 2022 at 07:19:39PM -0800, Bjorn Andersson wrote:

...

> > > > > +int fwnode_connection_find_matches(struct fwnode_handle *fwnode,
> > > > > +				   const char *con_id, void *data,
> > > > > +				   devcon_match_fn_t match,
> > > > > +				   void **matches, unsigned int matches_len)
> > > > > +{
> > > > > +	unsigned int count;
> > > > > +
> > > > > +	if (!fwnode || !match || !matches)
> > > > 
> > > > !matches case may be still useful to get the count and allocate memory by
> > > > caller. Please, consider this case.
> > > 
> > > As discussed in previous version, and described in the commit message,
> > > the returned value of "match" is a opaque pointer to something which
> > > has to be passed back to the caller in order to be cleaned up.
> > > 
> > > E.g. the typec mux code returns a pointer to a typec_mux/switch object
> > > with a refcounted struct device within, or an ERR_PTR().
> > > 
> > > So unfortunately we can must gather the results into matches and pass it
> > > back to the caller to take consume or clean up.
> > 
> > It's fine. You have **matches, means pointer of an opaque pointer.
> > What I'm talking about is memory allocation for and array of _pointers_.
> > That's what caller very much aware of and can allocate on heap. So, please
> > consider this case.
> 
> I'm sorry, but I'm not sure what you're looking for.
> 
> 
> I still interpret your comment as that it would be nice to be able to do
> something like:
> 
> count = fwnode_connection_find_matches(fwnode, "orientation-switch",
> 				       NULL, typec_switch_match, NULL, 0);
> 
> based on the returned value the caller could allocate an array of
> "count" pointers and then call the function again to actually fill out
> the count elements.

Yes, that's what I want from the generic fwnode APIs.
(Keyword: generic)

> The problem with this is that, typec_switch_match() does:

As you stated, the problem is in the typec_switch_match(). So, it's not related
to the fwnode, but how you are using it.

> void *typec_switch_match(fwnode, id, data) {
> 	struct device *dev = find_struct_device(fwnode, id);
> 	if (!dev)
> 		return NULL;
> 	get_device(dev);
> 	return container_of(dev, struct typec_switch, dev);
> }
> 
> So if we call the match function and if that finds a "dev" it will
> return a struct typec_switch with a refcounted struct device within.

fwnode (as being an abstraction on top of the others) has no knowledge
about this. And more important should not know that.

> We can see if that's NULL or not and will be able to return a "count",
> but we have no way of releasing the reference acquired - we must return
> the void pointer back to the client, so that it can release it.

The caller (if it wants to!) may create different callbacks for count and real
matching, no?

> My claim is that this is not a problem, because this works fine with any
> reasonable size of fwnode graphs we might run into - and the client will
> in general have a sense of the worst case number of matches (in this
> series its 3, as there's 3 types of lanes that can be switched/muxed
> coming out of a USB connector).

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-02-21 17:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08  3:19 [PATCH v2 0/6] typec: mux: Introduce support for multiple TypeC muxes Bjorn Andersson
2022-02-08  3:19 ` [PATCH v2 1/6] device property: Helper to match multiple connections Bjorn Andersson
2022-02-09 12:30   ` Andy Shevchenko
2022-02-18 19:00     ` Bjorn Andersson
2022-02-20 11:16       ` Andy Shevchenko
2022-02-21  4:55         ` Bjorn Andersson
2022-02-21 17:19           ` Andy Shevchenko [this message]
2022-02-21 19:08             ` Bjorn Andersson
2022-02-08  3:19 ` [PATCH v2 2/6] device property: Use multi-connection matchers for single case Bjorn Andersson
2022-02-08  3:19 ` [PATCH v2 3/6] typec: mux: Introduce indirection Bjorn Andersson
2022-02-18 10:39   ` Heikki Krogerus
2022-02-08  3:19 ` [PATCH v2 4/6] typec: mux: Allow multiple mux_devs per mux Bjorn Andersson
2022-02-18 10:40   ` Heikki Krogerus
2022-02-08  3:19 ` [PATCH v2 5/6] dt-bindings: usb: Add binding for fcs,fsa4480 Bjorn Andersson
2022-02-11 16:35   ` Rob Herring
2022-02-08  3:19 ` [PATCH v2 6/6] usb: typec: mux: Add On Semi fsa4480 driver Bjorn Andersson
2022-02-08 13:24   ` Andy Shevchenko
2022-02-10 10:00 ` [PATCH v2 0/6] typec: mux: Introduce support for multiple TypeC muxes Hans de Goede

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=YhPJmiFSH8s94il7@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=djrscally@gmail.com \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@linux.intel.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;
as well as URLs for NNTP newsgroup(s).