Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4262524iob; Sun, 8 May 2022 07:39:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3xbupcYD1jMMTZELaTUYqHMMamBuRsTQgHbhmMtvUjJXKGk15ZZbtNCQyWpOQOonxASBb X-Received: by 2002:a17:90b:4b81:b0:1dc:4dfe:9b01 with SMTP id lr1-20020a17090b4b8100b001dc4dfe9b01mr13814426pjb.110.1652020773539; Sun, 08 May 2022 07:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652020773; cv=none; d=google.com; s=arc-20160816; b=bIaEIf24a83NuKTWCH9wkjzIocjfIIsSySFN1DAVdERvNGVkXQzIPDkXOvaNRaWePi sDmn97BtKfGf1xqSbIb6tpg0yG5iG14c9DtL6xQ9PvoMJL/1oNu7WRwNBNka55f1AF+6 Lf3tBip+mE5OF1uezJblC1/WSqIfOCrmoLVO4gsHNCvgtf0MPYXGqCCFoqJwXSPgLP4C lXsH4xA/78ze39NL/Z0XVz6EcYQck/krtEQL9i/Pfwpg3jR9I03n7wSneLMAHerJt3RD plo1t+R+vBIh1pdGSYpvmoXNqqVIFeeYqlYmEEr8vTLyKcU/+EaDLGa7LlOFIqhAt0rb 5TCA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2aQgO6bfQh2s2SsRWDdscbGvANQ1aisvkD/2OsQpnMs=; b=NWnKHql+38837X/wRees0BOZc1R/l8c2oU3lwbOzZXdwYuuyNhYP8Sf7+uqSQkXv5d plsMwI7xhVck9mX0bdfmmzwMqWNItm+2sKpIq3DVX+/Wn9CxpiZS3/EwXxMEBzKdfQM5 Ff+XaqUP0bObULF7PcGqt5tnsYvcZL6KuNbz8P4cjhxPCf8iGuc9ajiVwyvXvYMlLSbS lqgJtFUTyv2vMkgX0MO+DNAl33mkt6CCDBAZzK2PElxuO5XDyVNSrA0wGOcuj4AjQv8k To1KFeYX4ZvFdCaKfY87F4lknLJ5ykSrlBUpf5XxoFLmCfcIaVX+8OMN+0722JHe8XDp azEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p7VXIXki; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a654d43000000b0039e01d84aa8si12614999pgt.352.2022.05.08.07.39.19; Sun, 08 May 2022 07:39:33 -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=@linuxfoundation.org header.s=korg header.b=p7VXIXki; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353960AbiEDQxf (ORCPT + 99 others); Wed, 4 May 2022 12:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353746AbiEDQwN (ORCPT ); Wed, 4 May 2022 12:52:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D37C247383; Wed, 4 May 2022 09:48:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 96246B82553; Wed, 4 May 2022 16:48:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 309B4C385A4; Wed, 4 May 2022 16:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651682912; bh=XFgNyRslClTV0rrP3goGZV9aGZ2Y8CKS/AcF5V7U3OE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p7VXIXkiWAkvNrtGQLxgQmAn4CR7uBdTKBsILVhu/0AoexAt/VbZYOxdZZ4ssvhA3 k70NSqwpEpScXp6LlM8D1FUORlWmK/FLvI3gm8P9PGyIK613tAAGz3XeugbBnRXHU/ RLBZtA/aFK4jxmMc0ibHexjStxpodh6i+rjMw6CU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heikki Krogerus , Jia-Ju Bai Subject: [PATCH 5.4 18/84] usb: typec: ucsi: Fix role swapping Date: Wed, 4 May 2022 18:43:59 +0200 Message-Id: <20220504152929.070520635@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504152927.744120418@linuxfoundation.org> References: <20220504152927.744120418@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Heikki Krogerus commit eb5d7ff3cf0d55093c619b5ad107cd5c05ce8134 upstream. All attempts to swap the roles timed out because the completion was done without releasing the port lock. Fixing that by releasing the lock before starting to wait for the completion. Link: https://lore.kernel.org/linux-usb/037de7ac-e210-bdf5-ec7a-8c0c88a0be20@gmail.com/ Fixes: ad74b8649bea ("usb: typec: ucsi: Preliminary support for alternate modes") Cc: stable@vger.kernel.org Reported-and-tested-by: Jia-Ju Bai Signed-off-by: Heikki Krogerus Link: https://lore.kernel.org/r/20220405134824.68067-3-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/ucsi.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -748,14 +748,18 @@ ucsi_dr_swap(const struct typec_capabili if (ret < 0) goto out_unlock; + mutex_unlock(&con->lock); + if (!wait_for_completion_timeout(&con->complete, - msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) - ret = -ETIMEDOUT; + msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) + return -ETIMEDOUT; + + return 0; out_unlock: mutex_unlock(&con->lock); - return ret < 0 ? ret : 0; + return ret; } static int @@ -780,11 +784,13 @@ ucsi_pr_swap(const struct typec_capabili if (ret < 0) goto out_unlock; + mutex_unlock(&con->lock); + if (!wait_for_completion_timeout(&con->complete, - msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) { - ret = -ETIMEDOUT; - goto out_unlock; - } + msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) + return -ETIMEDOUT; + + mutex_lock(&con->lock); /* Something has gone wrong while swapping the role */ if (con->status.pwr_op_mode != UCSI_CONSTAT_PWR_OPMODE_PD) {