From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752937AbcHQRxm (ORCPT ); Wed, 17 Aug 2016 13:53:42 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:43045 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752545AbcHQRxk (ORCPT ); Wed, 17 Aug 2016 13:53:40 -0400 Date: Wed, 17 Aug 2016 10:53:11 -0700 From: Guenter Roeck To: Heikki Krogerus Cc: Greg KH , Oliver Neukum , Felipe Balbi , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH v5 1/2] usb: USB Type-C connector class Message-ID: <20160817175311.GA4598@roeck-us.net> References: <1471430081-12860-1-git-send-email-heikki.krogerus@linux.intel.com> <1471430081-12860-2-git-send-email-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1471430081-12860-2-git-send-email-heikki.krogerus@linux.intel.com> 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 X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 17, 2016 at 01:34:40PM +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 > --- [ ... ] > + > +static ssize_t > +current_data_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, "data role swap only supported with DRP ports\n"); > + return -EOPNOTSUPP; > + } > + > + if (!port->cap->dr_set) { > + dev_dbg(dev, "data role swapping not supported\n"); > + return -EOPNOTSUPP; > + } > + > + if (!port->connected) > + return size; I don't think this check should be here. The connection status can change after the connection status was checked. We should leave it up to the driver to perform the necessary checks. This also applies to the other role change store functions. Thanks, Guenter