From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Greg KH <gregkh@linuxfoundation.org>,
Oliver Neukum <oneukum@suse.com>,
Felipe Balbi <felipe.balbi@linux.intel.com>,
Bin Gao <bin.gao@linux.intel.com>,
Vincent Palatin <vpalatin@chromium.org>,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCHv8 1/2] usb: USB Type-C connector class
Date: Fri, 9 Sep 2016 10:36:00 +0300 [thread overview]
Message-ID: <20160909073600.GB24214@kuha.fi.intel.com> (raw)
In-Reply-To: <20160908200429.GA971@roeck-us.net>
On Thu, Sep 08, 2016 at 01:04:29PM -0700, Guenter Roeck wrote:
> On Thu, Sep 01, 2016 at 02:49:47PM +0300, Heikki Krogerus wrote:
> > The purpose of USB Type-C connector class is to provide
> > unified interface for the user space to get the status and
> > basic information about USB Type-C connectors on a system,
> > control over data role swapping, and when the port supports
> > USB Power Delivery, also control over power role swapping
> > and Alternate Modes.
> >
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > ---
> ...
>
> > +
> > +static int sysfs_strmatch(const char * const *array, size_t n, const char *str)
> > +{
> > + const char *item;
> > + int index;
> > +
> > + for (index = 0; index < n; index++) {
> > + item = array[index];
> > + if (!item)
> > + break;
> > + if (!sysfs_streq(item, str))
>
> This doesn't work ... sysfs_streq() returns true if there is a match,
> so the "!" is wrong.
Oh no! I've been testing (stupidly) with a patch on top where I move
this function to lib/string.c (I guess I had this correctly in that).
Sorry about this.
> > + return index;
> > + }
> > +
> > + return -EINVAL;
> > +}
> > +
> [ ... ]
> > +
> > +static ssize_t
> > +preferred_role_store(struct device *dev, struct device_attribute *attr,
> > + const char *buf, size_t size)
> > +{
> > + struct typec_port *port = to_typec_port(dev);
> > + enum typec_role role;
> > + int ret;
> > +
> > + if (port->cap->type != TYPEC_PORT_DRP) {
> > + dev_dbg(dev, "Preferred role only supported with DRP ports\n");
> > + return -EOPNOTSUPP;
> > + }
> > +
> > + if (!port->cap->try_role) {
> > + dev_dbg(dev, "Setting preferred role not supported\n");
> > + return -EOPNOTSUPP;
> > + }
> > +
> > + ret = sysfs_strmatch(typec_roles, ARRAY_SIZE(typec_roles), buf);
> > + if (ret < 0) {
> > + port->prefer_role = -1;
> > + return size;
>
> Are you sure about that ? It is kind of unusual to accept "bad" strings.
> Why not return -EINVAL ?
I'm considering a "bad" string as clearing the preference. I did
explain this in the ABI document. But I suppose it's better to define
a specific string also for clearing. I'll change this.
> > + }
> > +
> > + role = ret;
> > +
> > + ret = port->cap->try_role(port->cap, role);
> > + if (ret)
> > + return ret;
> > +
> > + port->prefer_role = role;
> > + return size;
> > +}
> > +
> [ ... ]
> > +
> > +static ssize_t supported_accessory_modes_show(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + struct typec_port *port = to_typec_port(dev);
> > + ssize_t ret = 0;
> > + int i;
> > +
> > + if (!port->cap->accessory[0])
>
> You probably want
> if (!port->cap->accessory)
> here. Otherwise the check is quite pointless (and crashes if the pointer
> is NULL).
OK.
Thanks,
--
heikki
next prev parent reply other threads:[~2016-09-09 7:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-08 20:04 [PATCHv8 1/2] usb: USB Type-C connector class Guenter Roeck
2016-09-09 7:36 ` Heikki Krogerus [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-09-01 11:49 [PATCHv8 0/2] USB Type-C Connector class Heikki Krogerus
2016-09-01 11:49 ` [PATCHv8 1/2] usb: USB Type-C connector class Heikki Krogerus
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=20160909073600.GB24214@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=bin.gao@linux.intel.com \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=oneukum@suse.com \
--cc=vpalatin@chromium.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).