From patchwork Mon Jan 9 01:34:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiYuan Huang X-Patchwork-Id: 40605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1930871wrt; Sun, 8 Jan 2023 17:56:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvTGwhI+tTD6kpOFb2TWk2xzwBb/iUeZyvxoNkRYwpbAUt9wQnXjlYo0FzSXjZ2veFhP/+s X-Received: by 2002:a17:906:30d3:b0:7c0:a1f9:c778 with SMTP id b19-20020a17090630d300b007c0a1f9c778mr54503165ejb.13.1673229411531; Sun, 08 Jan 2023 17:56:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673229411; cv=none; d=google.com; s=arc-20160816; b=E62+nC2yK0mu2sVkR0rTdzUpU29GQm/p8O8f0Qf3u493Ab0sNuigPAi2AFiuDaHEIR 9e82Iqib2q4gCyXU3J/gAuVCT8ObGq5K/ZVvYiwyAAPCImyqHcCLwPg7oQGg0uRRtWd2 ngR4yuStz7luzwke92UKAZGuDNjCX0oZuPy50yO+nq8mTX0w+G3a2aZWWM6W/ec6bIrV vbTbYlibAA5kpoe6Kk2uIKRIpZoy2AH+2cTl6MohgRPNJ81TCqY3sDGLdB8MIy4bZiIP y+h+lba2TImRBUHje7G806RllFW8e1fSOw+cNm4UjxP7a6N9u/KeFd3d6lQkfKBTeUPF uuLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LmHLshOOm5+gNZLDJlN2EJs3ncC7MuTl1gTqSc52fyE=; b=eiGBRk7l4RWve7M2ApbPUory4N6K0Uz2/2VWe0nueg74w1dsFEokpWsoXzd1w31qoi IDzUoj/nOl2aaonbHz12BuEZoFPbL+T7imgBkVFoTd5Zj1PdD9tbU1ohtBHBE2yOr9Ug SmaWyOlvsMho9r8fNShAJoU90oezPNmD3/d93+myHXnFMiVRPdOn5+mOD61j9UP5uSpP tOAeZc5eegRFdvZIy1Y9vB5C/buv7f+WWwq5QiQVzZxXVE/+8zMK8Uyry5DlWwxsJ8q/ x+72ZgJaV+mhlX3lpI+iVHM6ttK+vJpnXaN66CEl76sgWrkKoPrQWNwEZ47AFk85A0Y0 fg2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a17090658c600b007ad8bc64c89si8657537ejs.701.2023.01.08.17.56.22; Sun, 08 Jan 2023 17:56:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233601AbjAIBnr convert rfc822-to-8bit (ORCPT + 99 others); Sun, 8 Jan 2023 20:43:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234071AbjAIBno (ORCPT ); Sun, 8 Jan 2023 20:43:44 -0500 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BCD1CDC3; Sun, 8 Jan 2023 17:43:41 -0800 (PST) X-MailGates: (flag:3,DYNAMIC,RELAY,NOHOST:PASS)(compute_score:DELIVER,40 ,3) Received: from 192.168.8.21 by mg.richtek.com with MailGates ESMTP Server V3.0(2730:0:AUTH_RELAY) (envelope-from ); Mon, 09 Jan 2023 09:43:39 +0800 (CST) X-MailGates: (compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTP Server V5.0(16482:0:AUTH_RELAY) (envelope-from ); Mon, 09 Jan 2023 09:34:54 +0800 (CST) Received: from ex3.rt.l (192.168.10.46) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Mon, 9 Jan 2023 09:34:53 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex3.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1118.20 via Frontend Transport; Mon, 9 Jan 2023 09:34:53 +0800 From: To: , , CC: , , , , , , ChiYuan Huang , Subject: [PATCH v2] usb: typec: tcpm: Fix altmode re-registration causes sysfs create fail Date: Mon, 9 Jan 2023 09:34:52 +0800 Message-ID: <1673228092-27281-1-git-send-email-cy_huang@richtek.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754508203227584998?= X-GMAIL-MSGID: =?utf-8?q?1754508203227584998?= From: ChiYuan Huang There's the altmode re-registeration issue after data role swap (DR_SWAP). Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP can initiate the VDM command to get partner identity information. For a USBPD 3.0 UFP device, it may already get the identity information from its port partner before DR_SWAP. If DR_SWAP send or receive at the mean time, 'send_discover' flag will be raised again. It causes discover identify action restart while entering ready state. And after all discover actions are done, the 'tcpm_register_altmodes' will be called. If old altmode is not unregistered, this sysfs create fail can be found. In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. For UFP, the original altmodes keep registered. This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' must be called whatever the current data role is. Reviewed-by: Macpaul Lin Fixes: ae8a2ca8a221 ("usb: typec: Group all TCPCI/TCPM code together) Reported-by: TommyYl Chen Cc: stable@vger.kernel.org Signed-off-by: ChiYuan Huang --- Since v2: 1. Correct the mail sent from Richtek. 2. Add 'Reviewed-by' tag. --- drivers/usb/typec/tcpm/tcpm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.7.4 ************* Email Confidentiality Notice ******************** The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you! diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 904c7b4..59b366b 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4594,14 +4594,13 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, ready_state(port), 0); break; case DR_SWAP_CHANGE_DR: - if (port->data_role == TYPEC_HOST) { - tcpm_unregister_altmodes(port); + tcpm_unregister_altmodes(port); + if (port->data_role == TYPEC_HOST) tcpm_set_roles(port, true, port->pwr_role, TYPEC_DEVICE); - } else { + else tcpm_set_roles(port, true, port->pwr_role, TYPEC_HOST); - } tcpm_ams_finish(port); tcpm_set_state(port, ready_state(port), 0); break;