From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jun Li <jun.li@nxp.com>, Hans de Goede <hdegoede@redhat.com>,
USB <linux-usb@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: typec: mux: Fix matching with typec_altmode_desc
Date: Mon, 17 May 2021 10:44:33 -0500 [thread overview]
Message-ID: <20210517154433.GU2484@yoga> (raw)
In-Reply-To: <CAHp75VdmTKLnGrm19UF5TqYDcNtqCmjt8NWVEDv__5qHsvnF3A@mail.gmail.com>
On Mon 17 May 10:37 CDT 2021, Andy Shevchenko wrote:
> On Mon, May 17, 2021 at 6:14 PM Bjorn Andersson
> <bjorn.andersson@linaro.org> wrote:
> > On Mon 17 May 04:13 CDT 2021, Andy Shevchenko wrote:
> > > On Sun, May 16, 2021 at 6:47 AM Bjorn Andersson
> > > <bjorn.andersson@linaro.org> wrote:
> > > >
> > > > In typec_mux_match() "nval" is assigned the number of elements in the
> > > > "svid" fwnode property, then the variable is used to store the success
> > > > of the read and finally attempts to loop between 0 and "success" - i.e.
> > > > not at all - and the code returns indicating that no match was found.
> > > >
> > > > Fix this by using a separate variable to track the success of the read,
> > > > to allow the loop to get a change to find a match.
>
> ...
>
> > > > - nval = fwnode_property_read_u16_array(fwnode, "svid", val, nval);
> > > > - if (nval < 0) {
> > > > + ret = fwnode_property_read_u16_array(fwnode, "svid", val, nval);
> > > > + if (ret < 0) {
> > > > kfree(val);
> > > > - return ERR_PTR(nval);
> > > > + return ERR_PTR(ret);
> > > > }
> > >
> > > This changes the behaviour of the original code, i.e. nval can be
> > > still positive but less than we got from previous call. Some fwnode
> > > backends in some cases potentially can _successfully_ read less than
> > > asked.
> > >
> > > Perhaps
> > >
> > > nval = ret;
> > >
> > > or drop the patch.
> > >
> >
> > Per the kerneldoc of fwnode_property_read_u16_array:
> >
> > * Return: number of values if @val was %NULL,
> > * %0 if the property was found (success),
> >
> > @val is not NULL, as we just checked for that, so the function will
> > always return 0 on success.
> >
> > I don't see anything indicating that the number of elements can be
> > different from what fwnode_property_count_u16() returned.
>
> Okay, I have checked the backends of fwnode and indeed, OF case (from
> where I remember such behaviour) deliberately does
>
> if (ret >= 0)
> return 0;
>
> Otherwise the rest return 0 directly / explicitly.
>
> The only exception is _read_string_array().
>
I wasn't aware that the string array behaved difference, and the
kernel-doc gives no hint either. Thanks for pointing it out.
Regards,
Bjorn
prev parent reply other threads:[~2021-05-17 16:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-16 3:47 [PATCH] usb: typec: mux: Fix matching with typec_altmode_desc Bjorn Andersson
2021-05-17 9:02 ` Heikki Krogerus
2021-05-17 9:13 ` Andy Shevchenko
2021-05-17 15:14 ` Bjorn Andersson
2021-05-17 15:37 ` Andy Shevchenko
2021-05-17 15:44 ` Bjorn Andersson [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=20210517154433.GU2484@yoga \
--to=bjorn.andersson@linaro.org \
--cc=andy.shevchenko@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=jun.li@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.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