Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp310396pxj; Thu, 20 May 2021 09:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhAwKCPEeRMEUGLc3yS3fTICgd/DAQ5wsIg9Sq2a+0oN2sHWz5mc0XgBleZO+ehHV8wcc/ X-Received: by 2002:a17:906:c299:: with SMTP id r25mr5730474ejz.501.1621529402070; Thu, 20 May 2021 09:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621529402; cv=none; d=google.com; s=arc-20160816; b=SvgunX8Kv255wr5BgQW3vIQcYC7VQjtxLbiAWA3s88UqQF9yL7sZaSWmc/HFoiR3DY eyxHDgjRFm8q64924oN5KZL0GmdSbNsdDl47CH2Nx/4lIR0faELSKxI0WGloNabaMYYQ zzha2tvZyze2/X7ugCrTa9IXkxe1et4Dj0v58rhkp57pbWpoAYg/qks4CxidtzRr3PAl nULw1/yWOTr44O2nvgB6b3jIIhsnc33Q3tdW1LkHMkS4BVsw1fAVCcBWXSyUkE5d4iho 74h3vh8w1WcvTJC/++vRxzaoF+sFvT7fV9v6s+Gue/ohLOMBBmzQvDXwjWCTIyYYSMCN lMQQ== 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=fqB8UtDBQma7mIY2ergjbFwrtYv+iIiRZ5fAwnLtVUk=; b=tgATVdhVFYHJRlPALdp7FYMFflZkTGIoyKL2tU3sntP4oeRCjVqEou5U5uojt5xG+F llPECoUXzS6KUV/zr3yT0C2NG3DHZWJBJmd40TZ5/kcr64PAfkJqlojUe1AFXk0Y6L1l YMX2tFkoY0NfCaMlwNvhoNr3G7txz2UNG0RAzp9nACclrijKmNQDoOYT9hQSmb78OtTr HbSC8xAd7Fc0WRh3u3tK/mxKuXNCrLxJEJ3E2gME/Tn1jAEURSFSJzEDiAdlz8kceiTg lNPNg1uW0CR7EMAy1UfrlCi0/gU5YeJ5Gv3akE0NHLM66rtLyfhLJiIR72ujjW/e9Ao8 Xr6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XCdXEjRm; 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 r14si2636172edm.356.2021.05.20.09.49.38; Thu, 20 May 2021 09:50:02 -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=XCdXEjRm; 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 S234507AbhETJwM (ORCPT + 99 others); Thu, 20 May 2021 05:52:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:48672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234350AbhETJtT (ORCPT ); Thu, 20 May 2021 05:49:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EA21C61481; Thu, 20 May 2021 09:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503303; bh=qrCIjCqBCL6KkOZGcS0ZphTMXqW3/gzowVoBWCTVNEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XCdXEjRmqJJbuAdrJayuogfCEZewlPl4VFMqY4Gxn2kuk2O4TmBcUWkgrviAmfkM8 brCwp8dSfmz86LS/fvN6Y4TCHEocJ2fGPBjRS5SSRhLcFw80wEFHk4BYftq/Mv5jMJ E+T+e6LMAf1g16uFi97sXG/e5H2tb9tAbS+s0wXI= 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.19 161/425] usb: gadget: pch_udc: Revert d3cb25a12138 completely Date: Thu, 20 May 2021 11:18:50 +0200 Message-Id: <20210520092136.747889678@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 @@ -600,18 +600,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); } /** @@ -1168,20 +1172,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; }