Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp618935pxj; Thu, 20 May 2021 18:05:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGln62FjUsb23NuNpbFpfAL0WfTQOnGEW9paRdrEfiGpImg1Myj4s181Nz+i6zjFc3VfkW X-Received: by 2002:a17:907:3f1d:: with SMTP id hq29mr2767232ejc.163.1621559124637; Thu, 20 May 2021 18:05:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621559124; cv=none; d=google.com; s=arc-20160816; b=ms0k7RGZYZAqM6fxcX8draNTqBIsHnIfAqvPj3E+aRyoM3QlFDW8DQ9evEue0kd7+H lULQArT9+K/nVfmoIZylhFL/D+qg4sefojNofCgsLJ0CR71VFKHIg51qWg3MbC6atcXf voWSPyjngQID0NJp2U55z/1vQ4gpguc/xLcNqcdfJP2D4eKVWfgdWWgojfDvFU3x3qIe /35XrTPZ7Nho0pyrIbRW3MWqUAPfkIsPO/TA3yPfu2k+x/VaccyTHoBAwiDwevz7pVxJ ksEOWFaf+qMKO8x1dkVvTqqsRISO+wt/BH33FoAS2etX+qQVAZCNoO9WN1nRwqyTuluz 7cHg== 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=aIqBmaAJXBdv2+rLXjMZiOVSyCG2MLX3SP0UOfiG5Do=; b=atOqcsWorgdRDax8lPQbWOoxebdf0CJJFqncY1CQkylI8zn0cKoamhsTXWOPOMQ9oU dK6G5FMaLToPyo5h6hisWi6/inyAuDWWGIgiZF6mMXPOnBOtL/RA0DYWHAUe6auP5jTw 2K37GemtfaA7Jh5fx+MAfkAGLlbvvh16zcaZH2Spw9ldzsRv66wxisI1DNSmzs2Wmvao 4H5PK8TIiwOhmxne98vvinhaWkNLZM77E93x5oZltFQOPlTtctl7cYOP7Vc7UXSdZJlX fjX5oRENBWbaUUOGH+lXFqpBNjvB6pvCRDluKRonGlRFMnHHGSoRWL3bETwDjmlOWQBd TVHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="uLvBL5g/"; 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 e14si3921930edc.52.2021.05.20.18.05.01; Thu, 20 May 2021 18:05:24 -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="uLvBL5g/"; 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 S240706AbhETLg7 (ORCPT + 99 others); Thu, 20 May 2021 07:36:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:37860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239773AbhETLRA (ORCPT ); Thu, 20 May 2021 07:17:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 192B26143D; Thu, 20 May 2021 10:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505366; bh=NOI1G9IKw5Z1wdia4o9essQLe4L23jHhFxQyjw7997s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uLvBL5g/RGxJbNXMzUmi3meDXPoEvWw2s+zI/v18KY2ne935TxrqX5m1PleFZBMw9 vmlNJ/BFU+GJD2FEy2mYLysE8A85X3mR7g6nzjqdRjLfvhAg99oMGq1hRuv3FLVFSt tR08Z3FS6r2uunguL8EJsPjPfVw0Ma/8jZZUeqVQ= 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.4 075/190] usb: gadget: pch_udc: Revert d3cb25a12138 completely Date: Thu, 20 May 2021 11:22:19 +0200 Message-Id: <20210520092104.675379738@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 @@ -615,18 +615,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); } /** @@ -1183,20 +1187,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; }