Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp632615ybv; Wed, 19 Feb 2020 06:15:32 -0800 (PST) X-Google-Smtp-Source: APXvYqz87Zk6ZpXQUOEwmlaDZD2br0u81lRkI8q62WHOZDNI9fKYaD5aAOdh1Ns8yq73wEJ9XYEE X-Received: by 2002:aca:dc45:: with SMTP id t66mr4875110oig.39.1582121731825; Wed, 19 Feb 2020 06:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582121731; cv=none; d=google.com; s=arc-20160816; b=w82iNzaKzncDEKveBLS6HLkkocDzIgsHNXVASHm0g+b34MKc52QnBlVz90rGBzjToH XVlkUoEumRbY9VE1RDBkeh0BQMALlBec5WkEHdUtqR0tGiY3jeBRDFHwqPhzrz+pvfAt +6kE9ltH2BYPpt2Uw1ZPDW+zO0huPhNxFr8G8z6+CfXpJ8EO2HuAisb9XZxsM6N8XypN gJKHjcxII83gyS8DHG1yxlt7lp8pDQopeTWufv7XybM5AV1gDoEZE2sbw2mN3zy+1vzQ AMNlTMuna7nHDfgdnXz7lntHAdvx4GYEvDLKhhNfzMBug1O/G9DJqfbUCBPbhkpKI2pA 6aHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=IzDk8sZwjypWzIC7QLl+Y7h8bV3d6FU0GTsQ/CcNZeY=; b=AyeidPw3aV7twJ0SirQLB3+JnImbV1/0r4GKGW6q1xfezO1QxotkuZP5G2uVJPXN2C XlYnI53MT9CQYzj1z4q1FIyU2N1uAWC+MLXvn3gs1yUUFw5AMQUXJOV7HIzb+BajD9I4 qR8sdjtNBSkiAiIsPK/1TiXmhOLnH10OioSXgkRFt5AkXRlFGaaFEchUMZo78tMoqe6X F/H4CLokhaXi5dwtEaAWq9M+gBFe/YacSiJ92umefdbZF8vaveKyGalg8rYdg9lEc2S1 ZAb46oTk9R0fmWtv/BSGMZdVBvmHC6Sk/gPT8l3Jt4RfBo9ojaywKSG2gUXfH5MXXUqJ KLJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si1056328otq.146.2020.02.19.06.15.19; Wed, 19 Feb 2020 06:15:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727959AbgBSOOh (ORCPT + 99 others); Wed, 19 Feb 2020 09:14:37 -0500 Received: from mga11.intel.com ([192.55.52.93]:4379 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727705AbgBSOOg (ORCPT ); Wed, 19 Feb 2020 09:14:36 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2020 06:14:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,459,1574150400"; d="scan'208";a="348947661" Received: from kuha.fi.intel.com ([10.237.72.53]) by fmsmga001.fm.intel.com with SMTP; 19 Feb 2020 06:14:32 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Wed, 19 Feb 2020 16:14:32 +0200 Date: Wed, 19 Feb 2020 16:14:32 +0200 From: Heikki Krogerus To: Peter Chen Cc: Felipe Balbi , Chunfeng Yun , Bin Liu , Benson Leung , Prashant Malani , Mika Westerberg , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" Subject: Re: [PATCH 5/9] usb: roles: Provide the switch drivers handle to the switch in the API Message-ID: <20200219141432.GJ28776@kuha.fi.intel.com> References: <20200213132428.53374-1-heikki.krogerus@linux.intel.com> <20200213132428.53374-6-heikki.krogerus@linux.intel.com> <20200213133239.GN1498@kuha.fi.intel.com> <20200218072341.GA30350@b29397-desktop> <20200218122545.GF28776@kuha.fi.intel.com> <20200219015840.GC8602@b29397-desktop> <20200219133815.GH28776@kuha.fi.intel.com> <20200219140955.GA15569@b29397-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219140955.GA15569@b29397-desktop> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 02:09:54PM +0000, Peter Chen wrote: > On 20-02-19 15:38:15, Heikki Krogerus wrote: > > On Wed, Feb 19, 2020 at 01:58:38AM +0000, Peter Chen wrote: > > > On 20-02-18 14:25:45, Heikki Krogerus wrote: > > > > Hi, > > > > > > > > On Tue, Feb 18, 2020 at 07:23:41AM +0000, Peter Chen wrote: > > > > > > > @@ -1118,6 +1119,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) > > > > > > > } > > > > > > > > > > > > > > if (ci_role_switch.fwnode) { > > > > > > > + ci_role_switch.driver_data = ci; > > > > > > > ci->role_switch = usb_role_switch_register(dev, > > > > > > > &ci_role_switch); > > > > > > > > > > Why the struct usb_role_switch_desc needs drvdata, the struct > > > > > usb_role_switch has already one? > > > > > > > > I'm assuming that you are asking why not just register the switch, > > > > and then call usb_role_switch_set_drvdata(), right? > > > > > > Yes. > > > > > > > > > > > That may create a race condition where the switch is accessed before > > > > the driver data is available. That can happen for example if the > > > > switch is exposed to the user space. > > > > > > > > To play it safe, supplying the driver data as part of the descriptor. > > > > That way we can be sure that the driver data is always available > > > > the moment the switch is registered. > > > > > > > > > > Then, you may use the uniform way for the driver. Some may have > > > race condition like you said. > > > > Uniform way for the driver? > > > > Sorry, unify way. Take chipidea and cdns3 as an example, at chipidea you > use struct usb_role_switch_desc > > + ci_role_switch.driver_data = ci; > ci->role_switch = usb_role_switch_register(dev, > &ci_role_switch); > > But at cdns3 side, you set usb_role_switch drvdata directly. > + usb_role_switch_set_drvdata(cdns->role_sw, cdns); > > But according to your comments, all the driver needs to use chipidea's > way to avoid race condition. OK, I'll fix that. thanks, -- heikki