Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6940928rwr; Wed, 10 May 2023 01:17:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XS3YOyFxG2JzRsjX92jF7eZgyh8JOEktvOvIqtGhnrRngv/4kT2Jq/OhKI19oQ8lc2rEm X-Received: by 2002:a05:6a00:189a:b0:646:7234:cbfc with SMTP id x26-20020a056a00189a00b006467234cbfcmr11121168pfh.27.1683706672393; Wed, 10 May 2023 01:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683706672; cv=none; d=google.com; s=arc-20160816; b=NiN2my9fqmDY5ttgNkZIUDEFFE3vTYBLjoNRpDmtEgX/bPJaMHhbwy/oJ12Q4/24lV NYWZOErJ5BIclIpHfzRTh/1t3BBBTnlH6fg1mZv2B9271/4efHlotCDW7brZDJQLIc/3 2yrQXlqYUxPxkEfaxIYhV0ob2gi56uxGh/7Kahn8GGziu5GUp5zFZlzF7+l7cLd0OXOx IzZzbq9qPaOCtxwiydXt+fnhebFLXDQwewJiR+j3s7Gu1iwq8+fRBhIOX1G24Mqfa1ab BfB0/LOZ4B7MhnpTrGGx+Q5q+eUklO4D6U1ebDc+5Sr0ynJuw/M1TUL+gtHbwoKx6SXT v3/A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TWfriI1GPViFPiF9QfSprwUBp0trQtulsgwwLsgPKAY=; b=fV4Ia4iUYDo46stRm4uDsZ+IylJIPe29idHDT17ERyMSjltn5a3xpA48LjBIlU3mMS qqdP8qMtCnznjPVYhudRzk5lK52gIuQtdeeQxoU76Knk/l3uCB13ZDcxcvaRUsbysJxv RlEqlLqdTVFZctzp9F5KBJz+5GOI/hAEh/xdvS5IK1fHB2JrYdMUVBW/4djP5tMGzO31 bMyAfHAuW7HDHCRgjzkPUxK016zjvOlF+h3qZ/dz4nMQOXr+45FpxFKnzTqh/urLk8rH q72ootaqBmtIPQbZ5Ft146tPFLc+fg8McVSKMpGhPzzYIEhV58jaATAeGy2BmT76APeA PpgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=n7hg07RM; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020aa7960b000000b0062804ba6fb4si4564078pfg.58.2023.05.10.01.17.38; Wed, 10 May 2023 01:17:52 -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=n7hg07RM; 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 S236449AbjEJHx7 (ORCPT + 99 others); Wed, 10 May 2023 03:53:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236436AbjEJHxx (ORCPT ); Wed, 10 May 2023 03:53:53 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 273CE44AB; Wed, 10 May 2023 00:53:42 -0700 (PDT) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34A7RIAU017497; Wed, 10 May 2023 07:53:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=TWfriI1GPViFPiF9QfSprwUBp0trQtulsgwwLsgPKAY=; b=n7hg07RMT84PZJYqqr75XTzL6R+Z6hBLafurv+LOMfZEEgf6aqEVSNbbVWhAQRdA3z2z HeY9Cg6NEYQIXR8zU0o9ht/rK5Pr3p2ijTSiishDkyvJToeA7FrWNhUQsysuN/6Vk/3i ejjBMZVX2yyy8l8iHNOEdHuxgSVnDxWi7OXooDiFkkWmTLWk2irBakhTSKfD2IWOjCww r053Alomxh8cpW+HRASXWLHXQQJ3OxrGMJMlIM7uwhPoFckwfH6FY/gEk8GU+ixT3eT3 uLWlm+hOccRJE7swJ8SUC67hs9kLWwiRwjMjWI91+kksq7Gd3M7MJ2hs6ubpqj2GPbbz 7g== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qfrut9mwc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 07:53:19 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34A7rHQd015468 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 May 2023 07:53:17 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; Wed, 10 May 2023 00:53:14 -0700 From: Krishna Kurapati To: Thinh Nguyen , Greg Kroah-Hartman , Alan Stern , "Jiantao Zhang" , Badhri Jagan Sridharan CC: , , , , , Krishna Kurapati Subject: [PATCH v3 2/2] usb: gadget: udc: Handle gadget_connect failure during bind operation Date: Wed, 10 May 2023 13:22:52 +0530 Message-ID: <20230510075252.31023-3-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230510075252.31023-1-quic_kriskura@quicinc.com> References: <20230510075252.31023-1-quic_kriskura@quicinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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-GUID: pwcW3T6yZNhZ2L6Peo3B0s5wVvZ-m0Em X-Proofpoint-ORIG-GUID: pwcW3T6yZNhZ2L6Peo3B0s5wVvZ-m0Em X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-10_04,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 suspectscore=0 phishscore=0 bulkscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305100061 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 In the event, gadget_connect call (which invokes pullup) fails, propagate the error to udc bind operation which inturn sends the error to configfs. The userspace can then retry enumeartion if it chooses to. Signed-off-by: Krishna Kurapati Acked-by: Alan Stern --- changes in v3: Rebase on top of usb-next drivers/usb/gadget/udc/core.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 4641153e9706..69041cca5d24 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1122,12 +1122,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state); /* ------------------------------------------------------------------------- */ /* Acquire connect_lock before calling this function. */ -static void usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock) +static int usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock) { + int ret; + if (udc->vbus && udc->started) - usb_gadget_connect_locked(udc->gadget); + ret = usb_gadget_connect_locked(udc->gadget); else - usb_gadget_disconnect_locked(udc->gadget); + ret = usb_gadget_disconnect_locked(udc->gadget); + + return ret; } /** @@ -1583,12 +1587,21 @@ static int gadget_bind_driver(struct device *dev) goto err_start; } usb_gadget_enable_async_callbacks(udc); - usb_udc_connect_control_locked(udc); + ret = usb_udc_connect_control_locked(udc); + if (ret) + goto err_connect_control; + mutex_unlock(&udc->connect_lock); kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); return 0; + err_connect_control: + usb_gadget_disable_async_callbacks(udc); + if (gadget->irq) + synchronize_irq(gadget->irq); + usb_gadget_udc_stop_locked(udc); + err_start: driver->unbind(udc->gadget); -- 2.40.0