Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1479479

Re: [PATCHv8 1/2] usb: USB Type-C connector class

Path csiph.com!news.mixmin.net!aioe.org!gothmog.csi.it!bofh.it!news.nic.it!robomod
From Guenter Roeck <linux@roeck-us.net>
Newsgroups linux.kernel
Subject Re: [PATCHv8 1/2] usb: USB Type-C connector class
Date Thu, 08 Sep 2016 22:10:02 +0200
Message-ID <sfdO2-1TD-23@gated-at.bofh.it> (permalink)
Dkim-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Type:MIME-Version:Message-ID:Subject:Cc: To:From:Date; bh=Betk4n31TGFxyA2F3We2OYoiAL/CAANyji77ZVZ/xVk=; b=daVQEY1OdClj c1ge7zqL9/0FyXyPiaKwk/xebGu5q6TaoFX/wLsYHpR8Ecsya7ySotsKFPObhAyaFdpeC1MaFKlAU xhpkDsJ7dx28yVvG6eWqai8F8kfbxQP859xxu4M8/JFG+wcIQQKYDFdi7EhH9XIujDlhNxSymloKo /BOZqZkqWvqGWgMJcsN5z3NIwkuo9aRNjXu2isxo4Gsj0cH1EuMdeEl6JLzCHZKwXV0WNR4lM27GT Oe4I7XOCxI51WSkIv5kAxElluOLsuvWmjnElJ9i6m56JB9SdGIh1k7BW2Kx9i0DD5Mnb/AiihfUDO P9WPvtDVWqlDdVhIDqO77A==;
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.23 (2014-03-12)
X-Authenticated_Sender guenter@roeck-us.net
X-Outgoing-Spam-Status No, score=-1.0
X-Antiabuse This header was added to track abuse, please include it with any abuse report
X-Antiabuse Primary Hostname - bh-25.webhostbox.net
X-Antiabuse Original Domain - vger.kernel.org
X-Antiabuse Originator/Caller UID/GID - [47 12] / [47 12]
X-Antiabuse Sender Address Domain - roeck-us.net
X-Get-Message-Sender-Via bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net
X-Authenticated-Sender bh-25.webhostbox.net: guenter@roeck-us.net
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 101
Organization linux.* mail to news gateway
X-Original-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
X-Original-Date Thu, 8 Sep 2016 13:04:29 -0700
X-Original-Message-ID <20160908200429.GA971@roeck-us.net>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1479479

Show key headers only | View raw


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.

> +			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 ?

> +	}
> +
> +	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).

> +		return 0;
> +
> +	for (i = 0; port->cap->accessory[i]; i++)
> +		ret += sprintf(buf + ret, "%s\n",
> +			       typec_accessory_modes[port->cap->accessory[i]]);
> +	return ret;
> +}
> +static DEVICE_ATTR_RO(supported_accessory_modes);
> +

Guenter

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCHv8 1/2] usb: USB Type-C connector class Guenter Roeck <linux@roeck-us.net> - 2016-09-08 22:10 +0200
  Re: [PATCHv8 1/2] usb: USB Type-C connector class Heikki Krogerus <heikki.krogerus@linux.intel.com> - 2016-09-09 09:50 +0200

csiph-web