Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp29532yba; Thu, 11 Apr 2019 21:02:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxc3c+Prs3MF8TK+jU+xXWgHZqG4rPz8ih/dWnuDISa5GNcwwU0UdoqlAGVOpu970uN70SC X-Received: by 2002:a17:902:d68d:: with SMTP id v13mr54998162ply.55.1555041725794; Thu, 11 Apr 2019 21:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555041725; cv=none; d=google.com; s=arc-20160816; b=dHfYiGtHR8nG7njSoYNLdZnMypoZogotFXDzHpl3DD25WkeZuNr0CXvVWZPDGEiBQW HINdc5+34hIahV7ZDp5iCWm7acn/0TbJlm9q3AVNwk3i1GvfD8zAigAf8wSVOHZVBKGK DzFIkxQ4xgDnpH5XHnChVWqGX7nmcALl6Q6xu7pw8FbDxP+Rwu9AohOgxcS50Iu1OWdd QvynQ518B1URN+PrYF0h+AB1TmCkU5sEav9gxmZ4sXeacZ03qYjyF7kWSZ6PdnxLBRr8 KbLxbEltjOgahuerY157kFAqYW/Rx+ojln6lCuPHoBMRT9PlrmraOwJ8kLIU6nLJYc+G jOtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=FDjbew8/XnEWPCx2JhORMgpWfv6ak7qB7VTQ5Y2QSSQ=; b=d8or6aJlaU5o24UOn4d7V+Q95nikIsgoIQTzjWRFqOUa3xvHGItCjACsgArENMoCbj CpTzxWAcM3BIVAttOxfquBxY9LcGw80umkBDc2WmezCeHvl5eX8Ps3pHZLT5btbTnm7y ZzjyBO6RpXJKtQD810KQo/Bs/wJXx+CFx/pzuq9kwAzfycfLXakLS0nYxRn5Vhhv0Kes JN+FH3dq0X8rOb67gfcu4gDUaJm2spaG1rUtuhllxSa7tyUPNxBarYE0DT5neNWdnRJt TYRjIi0VYYT+fqFXLuWRxntzRtiGN/odssGCZNSedP/RnEujBd5yc/wI/RJXuVzc79Uo XROw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yJUMwLs/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si30422737pgn.143.2019.04.11.21.01.24; Thu, 11 Apr 2019 21:02:05 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b="yJUMwLs/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726742AbfDLD7c (ORCPT + 99 others); Thu, 11 Apr 2019 23:59:32 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35550 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfDLD7c (ORCPT ); Thu, 11 Apr 2019 23:59:32 -0400 Received: by mail-wm1-f66.google.com with SMTP id y197so9210341wmd.0 for ; Thu, 11 Apr 2019 20:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FDjbew8/XnEWPCx2JhORMgpWfv6ak7qB7VTQ5Y2QSSQ=; b=yJUMwLs/VuheROMdvbgcxf4aIlTmHjgP0u0OBcJVi/d+ATgieKvDC5dQ9akuiy+0as 1SWiHpYd3ln7U9/XZXOiWPacUxeA4m7ZwIagBdles+ZrvSDlTmzTaUl6dM3ji725o9D/ xw9PYnbcHoRwWBqHHluLC/I/k+y6vUD2mycjfMOGhH+4e3bOc9yS5uSGQAFodOgnwxAK sNY4u+dATu/fRLitXCIs915unk3mx+at3s+kf8cb4RqsC/ZaE6bv9nbYTxIiPkVx1vDV uzGqJUDVQHxvmLcvsBksSoZ+/X3fb7yHxdoLKCGeividloux9ewo97rgVOUYs1uKvAE2 Uuvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FDjbew8/XnEWPCx2JhORMgpWfv6ak7qB7VTQ5Y2QSSQ=; b=I3M2WGwjUi6cSqRSJDUAWYFRHXc8x559WryuDbSyC5nUHDjTIM78LnSHSgbNbTgU38 MwiLAKN7GHa6dNm9Zb4+i4h9mUZYBCGHgW1PdZjMAQrk0IOGgMh2NZ1XLdiOEPW7iIkW 2Jyv60bE6o5bpv5slwSpmyoOgnnwUZNvKqfT3HXZFPz5qocqZKUbOqB8WtcFmss307tv mvHq2j1/b21TxkFQ9HFaRAQsu1Q+afmxnaD14S54mi2tKXylDtbrsHKUQKlc+XvcL9om wdJDEiiNaPVKxpUyy4wqBOtusEffrmFLbW03kI1gpla1v8N2dPzbZhAJm9VPE0goagfQ VbjA== X-Gm-Message-State: APjAAAVZCMkhc1mS7tLHmFwOuvNgPr+qWj6aqgtXc07zgHEWZ7OXftFm 9VuRTJhU4eavxbx95lbF0QMbps5qm2ED6e5G91d8zA== X-Received: by 2002:a1c:a103:: with SMTP id k3mr9179534wme.8.1555041570364; Thu, 11 Apr 2019 20:59:30 -0700 (PDT) MIME-Version: 1.0 References: <20190329041409.70138-1-chenyu56@huawei.com> <20190329041409.70138-10-chenyu56@huawei.com> In-Reply-To: From: John Stultz Date: Thu, 11 Apr 2019 20:59:17 -0700 Message-ID: Subject: Re: [PATCH v5 09/13] usb: roles: Add usb role switch notifier. To: Yu Chen Cc: Linux USB List , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , lkml , Zhuangluan Su , Kongfei , "Liuyu (R)" , wanghu17@hisilicon.com, butao , chenyao11@huawei.com, fangshengzhou@hisilicon.com, Li Pengcheng , songxiaowei@hisilicon.com, YiPing Xu , xuyoujun4@huawei.com, Yudongbin , Zang Leigang , Greg Kroah-Hartman , Heikki Krogerus , Hans de Goede , Andy Shevchenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 11, 2019 at 6:12 PM John Stultz wrote: > > On Thu, Mar 28, 2019 at 9:14 PM Yu Chen wrote: > > > > This patch adds notifier for drivers want to be informed of the usb role > > switch. > > > > Cc: Greg Kroah-Hartman > > Cc: Heikki Krogerus > > Cc: Hans de Goede > > Cc: Andy Shevchenko > > Cc: John Stultz > > Suggested-by: Heikki Krogerus > > Signed-off-by: Yu Chen > > Hey Yu Chen! > Thanks again for sending this patch out! As mentioned in my > comments with the other patches, I've got one proposal I wanted to > share to try to avoid state initialization races that I've seen with > this patchset. > > > diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c > > index f45d8df5cfb8..e2caaa665d6e 100644 > > --- a/drivers/usb/roles/class.c > > +++ b/drivers/usb/roles/class.c > > @@ -58,6 +61,20 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) > > } > > EXPORT_SYMBOL_GPL(usb_role_switch_set_role); > > > > +int usb_role_switch_register_notifier(struct usb_role_switch *sw, > > + struct notifier_block *nb) > > +{ > > + return blocking_notifier_chain_register(&sw->nh, nb); > > +} > > +EXPORT_SYMBOL_GPL(usb_role_switch_register_notifier); > > As noted earlier, one issue I've seen is that the hisi_hikey_usb > driver's notifier may not get called early enough to receive > notification of the initial usb state. > > It seems like on registration here, we should take the lock, read the > role state and immediately call the notifier to properly initialize > it? I suspect that should close the window for any state races around > driver probe timings and > > Does that make sense? I have roughly prototyped this but need to do > additional testing. So these seem to be working ok. First, the notifier call on register change: https://git.linaro.org/people/john.stultz/android-dev.git/commit/?h=dev/hikey960-mainline-WIP&id=1d312db9763c2449c3cf5b3383b1f33390f8ce7b Second, the current_dr_role change for dwc3: https://git.linaro.org/people/john.stultz/android-dev.git/commit/?h=dev/hikey960-mainline-WIP&id=b80b536de76eb80f7df0846aa54ac22e2b4ffe4e Feel free to fold/rework those changes into your patch set. thanks -john