Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp435652pxj; Thu, 20 May 2021 12:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoX6hg2dXwg062hAyN36xsuJvN6oPNv75UlSZnsWkDQN/oqt9JSKpc/0YC8wHAPyCf8Z8R X-Received: by 2002:a05:6402:2064:: with SMTP id bd4mr6576799edb.96.1621540271162; Thu, 20 May 2021 12:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621540271; cv=none; d=google.com; s=arc-20160816; b=okzBp9UoSn9no0YWvPEXmpaNVlbfY6RODEnQYWlWsW/l5z8rDIGZjB9/ji3E4+H5Kc WATL5T0HpgyB3ZRa8hZy29pOMYoUNpMLqNsUQNgau2k1mySnCQjARW57fIvl++751auE uFR+y+EHFoh2TWJsjIjp//vwusFfCCswpsDRIkOB8i10qy1j1uv471WnhTyylkTYE9+x yh49mCjiLZG0k2P+QmdWv7FhBFBsFp3zAugeR/Ef0jpuxXnd04rkBDuZuT/o+tx75tlj 6JVpJCDqiiSX0zt9AM8wFUIYrT46/FMtRwYstaTt/m0JsVssaCsEZsHm5wcJ3PMtLo7W 00Og== 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=Bcdb1Ltk1BGNDPP1Bg0pKke3F2eVBl0sDO4lpu9msRs=; b=fuxy1AWhDoFNPLPQ/dx2WxLdf1NIsxqcub5WVHBcw4Sinjx59Lko9Heb19Hpm9Iy1Q gyGdGNeP8UnPWBh8veZiO9Go4X7BLKI5rrhSVclp0D+3CpootALYJIoj0xAKMktQX2o0 fWYx6P0qO+ouHD0kuColCy1xFOsOvpnD0BlMnqe6ufxFWPaOQi3a+KJefAMjm6Rw6/WE wnCRRhcqy94uM4KCHs4e7wmqv24jsETXDb6NZoTIiKHa+YbyERHtCMzXtsi1YxJDGvAG HZ6+JMNu6CDl2QpgosIHY1QQobUlhnalvMxF9qpAjbAU3ckqXYzF9XogSDmWlPXmCECH oNIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HbZXGHTp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si1878149edj.72.2021.05.20.12.50.47; Thu, 20 May 2021 12:51:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HbZXGHTp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236657AbhETKpH (ORCPT + 99 others); Thu, 20 May 2021 06:45:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:60372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237036AbhETK33 (ORCPT ); Thu, 20 May 2021 06:29:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7902661C31; Thu, 20 May 2021 09:51:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504274; bh=lSdtHzYaRgOBT0gWw44EQQ3IskH5dXfvS34EW1mGgGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HbZXGHTpwJ5UEVoyWo9ESa7XIlI+F2NEJAvoTpH/CE4mvKpa2KeEwX9vuy0w0R/jU 0JCntb6oufaNcYQXUN5WoTy0g9C9kZKIVZz2x9KrdlbRajNPyIcisKY7UZJ/HWRoTH o08eYMGLnNTqUooBkwXCOf16EZ5rwqMYKkc+7S40= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Iago Abal , Andy Shevchenko Subject: [PATCH 4.14 137/323] usb: gadget: pch_udc: Revert d3cb25a12138 completely Date: Thu, 20 May 2021 11:20:29 +0200 Message-Id: <20210520092124.807678800@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Shevchenko commit 50a318cc9b54a36f00beadf77e578a50f3620477 upstream. The commit d3cb25a12138 ("usb: gadget: udc: fix spin_lock in pch_udc") obviously was not thought through and had made the situation even worse than it was before. Two changes after almost reverted it. but a few leftovers have been left as it. With this revert d3cb25a12138 completely. While at it, narrow down the scope of unlocked section to prevent potential race when prot_stall is assigned. Fixes: d3cb25a12138 ("usb: gadget: udc: fix spin_lock in pch_udc") Fixes: 9903b6bedd38 ("usb: gadget: pch-udc: fix lock") Fixes: 1d23d16a88e6 ("usb: gadget: pch_udc: reorder spin_[un]lock to avoid deadlock") Cc: Iago Abal Signed-off-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210323153626.54908-5-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/pch_udc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) --- a/drivers/usb/gadget/udc/pch_udc.c +++ b/drivers/usb/gadget/udc/pch_udc.c @@ -604,18 +604,22 @@ static void pch_udc_reconnect(struct pch static inline void pch_udc_vbus_session(struct pch_udc_dev *dev, int is_active) { + unsigned long iflags; + + spin_lock_irqsave(&dev->lock, iflags); if (is_active) { pch_udc_reconnect(dev); dev->vbus_session = 1; } else { if (dev->driver && dev->driver->disconnect) { - spin_lock(&dev->lock); + spin_unlock_irqrestore(&dev->lock, iflags); dev->driver->disconnect(&dev->gadget); - spin_unlock(&dev->lock); + spin_lock_irqsave(&dev->lock, iflags); } pch_udc_set_disconnect(dev); dev->vbus_session = 0; } + spin_unlock_irqrestore(&dev->lock, iflags); } /** @@ -1172,20 +1176,25 @@ static int pch_udc_pcd_selfpowered(struc static int pch_udc_pcd_pullup(struct usb_gadget *gadget, int is_on) { struct pch_udc_dev *dev; + unsigned long iflags; if (!gadget) return -EINVAL; + dev = container_of(gadget, struct pch_udc_dev, gadget); + + spin_lock_irqsave(&dev->lock, iflags); if (is_on) { pch_udc_reconnect(dev); } else { if (dev->driver && dev->driver->disconnect) { - spin_lock(&dev->lock); + spin_unlock_irqrestore(&dev->lock, iflags); dev->driver->disconnect(&dev->gadget); - spin_unlock(&dev->lock); + spin_lock_irqsave(&dev->lock, iflags); } pch_udc_set_disconnect(dev); } + spin_unlock_irqrestore(&dev->lock, iflags); return 0; }