From patchwork Fri Jun 16 07:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 108908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1155065vqr; Fri, 16 Jun 2023 00:48:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/aV+0ZHOLXCjiDdFHQhvLLA+K45OExuVwZyUH1wqcAHgvv92QVABq5HbECroVX4R+gUxG X-Received: by 2002:a05:6358:6117:b0:129:bf30:3ee with SMTP id 23-20020a056358611700b00129bf3003eemr937064rws.7.1686901705760; Fri, 16 Jun 2023 00:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901705; cv=none; d=google.com; s=arc-20160816; b=XthiFcc75Qbh2kNvgy9MGrzmFroSXowedZaemlpvHk1fxQDv+6I9aoRFdoWPw/j64g 79Lo4j6rMxUK7riTmmNyfUcr6kcXHD1HIMHbEuQYIxEDeb6k4hWI1uCH4NYSKfAxHhVc JDOlisNp/+WzJTxAMYwHli6b6otoM7abxeCl6v0JpDSmQUJb5MwqhmgNhRDvUOtZghCN IcIXLk/rlrxOkkkvUSp+53rEoxwvUqkeLYj61fNKvdsP2h+eYNFuZwRzxCFNpgf6qMJp t6xAQv5XFrjSQKYELwIyz25x5J/Mf61EJfHWT6QpCrwGqsMe9ODBUkkZBy5zbmhFYdlo VuKg== 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:dkim-signature; bh=64XPUhJY9k+HP/wrVo4rgb68Xlk7MRxMuk91+9PlTYM=; b=YR5kv50yE2ayOSBocG0iM4u6CWG4EhLGv/Yl/A6S4aJC02H3QKNvaM7Dcu8w/pdbwd nkX2yuXMywDg50pbzvLtPf5Z7YSIAm/wl06uqNF8hQ7EcIFEyJB4r3IYPB4hwTWtb4Nc WVD2JzqvHKKAc+OTUuWIdjfLkYY3G6BT81tay7QtWcqGay3KsdundqtrbPO91Q7pwiGX zAkwuRJ0K4nl5sorz4/6tWt6aKGKFIt94oCSHxCnWjRmG8/xs0y5KmcHDbpG94fWn2R6 A34c6cSfcdqJB2Wvw2d3yoQ/chXPFaXHxY9vy1REp0nux45tXVCKJJZYzRXCLL1uY9xx t6Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=atvlWIWk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a63eb45000000b0054403507e7bsi11992256pgk.77.2023.06.16.00.48.11; Fri, 16 Jun 2023 00:48:25 -0700 (PDT) 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; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=atvlWIWk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244552AbjFPHRm (ORCPT + 99 others); Fri, 16 Jun 2023 03:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244222AbjFPHRk (ORCPT ); Fri, 16 Jun 2023 03:17:40 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E20EF1FF5; Fri, 16 Jun 2023 00:17:38 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35G66Y8C012151; Fri, 16 Jun 2023 07:17:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=64XPUhJY9k+HP/wrVo4rgb68Xlk7MRxMuk91+9PlTYM=; b=atvlWIWkTYptnS4fK/ptXEYHVeft3IYbLhFzJ0CkNYEbjNYYj70IFsMJFoWIVq20OJ1z K3BrmyUKwGAxoGSgjajokJx3WCtRw21WOvgiKsAByI1minMnZavNNbp0MyffGjFszMwO VQPcYvEsj2pzbpq8z3SI3HA6zpEc9G7FfKUr30rO0fVlUP/j6nKOXZ98e3hbpVmYMAET 0AIKYLS1nroKpoW7r1pZIng4M4jelaWL4eIIVLZDL6GUTg1DHe3dVKxpGC6nyi0HawQx YuK5Klf1FXG/kvyW+18Co5XlZ5lcMbKTOaymR9nHaVnyr2TnOQTN/vyKyNfahGsa9Qvo Ww== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3r83p99ss7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Jun 2023 07:17:36 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 35G7Hac2005866 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Jun 2023 07:17:36 GMT Received: from hu-kriskura-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Fri, 16 Jun 2023 00:17:25 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman CC: , , , , , , Krishna Kurapati Subject: [PATCH v2] usb: dwc3: gadget: Propagate core init errors to UDC during pullup Date: Fri, 16 Jun 2023 12:47:15 +0530 Message-ID: <20230616071715.20960-1-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: FtyA6XxC-9VAaw3-8HwTKR7bWoQ17IR9 X-Proofpoint-GUID: FtyA6XxC-9VAaw3-8HwTKR7bWoQ17IR9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-16_04,2023-06-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=994 mlxscore=0 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306160064 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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?1768844642612091533?= X-GMAIL-MSGID: =?utf-8?q?1768844642612091533?= In scenarios where pullup relies on resume (get sync) to initialize the controller and set the run stop bit, then core_init is followed by gadget_resume which will eventually set run stop bit. But in cases where the core_init fails, the return value is not sent back to udc appropriately. So according to UDC the controller has started but in reality we never set the run stop bit. On systems like Android, there are uevents sent to HAL depending on whether the configfs_bind / configfs_disconnect were invoked. In the above mentioned scnenario, if the core init fails, the run stop won't be set and the cable plug-out won't result in generation of any disconnect event and userspace would never get any uevent regarding cable plug out and we never call pullup(0) again. Furthermore none of the next Plug-In/Plug-Out's would be known to configfs. Return back the appropriate result to UDC to let the userspace/ configfs know that the pullup failed so they can take appropriate action. Fixes: 77adb8bdf422 ("usb: dwc3: gadget: Allow runtime suspend if UDC unbinded") Signed-off-by: Krishna Kurapati Acked-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 578804dc29ca..27cb671e18e3 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2747,7 +2747,9 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) ret = pm_runtime_get_sync(dwc->dev); if (!ret || ret < 0) { pm_runtime_put(dwc->dev); - return 0; + if (ret < 0) + pm_runtime_set_suspended(dwc->dev); + return ret; } if (dwc->pullups_connected == is_on) {