Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4591368pxj; Wed, 12 May 2021 08:50:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQk3LgUDdux/cgdFCNeWB4+jrwK36JxL1gjqRwIN4Rh793AeDel6K6djnYDpkI7mcwzFNj X-Received: by 2002:a17:907:7b9f:: with SMTP id ne31mr38353803ejc.139.1620834623264; Wed, 12 May 2021 08:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834623; cv=none; d=google.com; s=arc-20160816; b=DAMSUtGaAWBj/x5L+6Ah3/Os+S3vW0hBYPQYx2ENvvZJFseOaBRRMMkMvdlrfyUIH+ tuJEDvNUn7g8/XFJ9O6IPsklm2rK5rZOvPnEsdbypZf4UEVU30x25u2Gf7UfORXjxa2j PLGiAG2HCsGrgG37u41PoaEPQNbmUqIDJWRr7xiVTy9cNnX0HzYEHqMX6D49uspyFh01 GHmkXOsKyzyMUc8aDMdGOh5lwYdIno+JPbKrXtrxHwVI4xP3Ib8dIIiNIU9EnQvL13LT gt5nNkO8wsK2/Q6nd9v/jfD7JqNChyl+UJGHxkLzyZhZRLelQ7N5oCSKgkcMNZAkOHzh OsSA== 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=NTZVALYwRUdH3ICXLqNUO6Vo3grV4n9hxjLgak4+BpE=; b=IVz+j/JqjwGNFDATVGZw12wHMdgLnHpH2O3YwnVbMnGoRQskjRetTb3Zg5KKjnTxOd +GofjdaVL/T515cbhCCIv7JphazCpENJwpvQ6sdVW5k9r3erKFmlOnegPJ0qTSOLQYGc RaJG2l8cBj+5ldojQVph4xM7bnV/te2jpRavkbFXuZ/uBey6b1o0AHnNOtYuwWckjofu cBBUqYZve9xg10BU3G5Zdol56FGG58NDL6bOwSNPCdFHSlOy9YTtWR3R/3Rc0tKFf+MN 9lUFsCsdy1hZfuMN3omDV937+t1FC9YJM30H6pjLGwkgDMg/GOYwLB6HobPEEKvfVAZU Pnmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MBV6OhQN; 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 jg39si240714ejc.63.2021.05.12.08.49.58; Wed, 12 May 2021 08:50:23 -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=MBV6OhQN; 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 S236635AbhELPpf (ORCPT + 99 others); Wed, 12 May 2021 11:45:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234679AbhELPUW (ORCPT ); Wed, 12 May 2021 11:20:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA3B16144F; Wed, 12 May 2021 15:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832104; bh=5QnSpx1xnospmZcVSULOnO1SORRa52ODAEZ8FhhOFK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MBV6OhQN7S3rI5UeeDhjrd2Oj1AJUS3LyIUr82k1cAqeZzDcV+lJxgRyYB94ijR7Z jsE6EOLFCGXC39H+FgLlV9LDqXwgRV9b5INLKp73mDvyEeyCO+ctPW7I1c5p/HBQN1 h9cwlc70J6sVoFCfnez5sSj+sWbtRPsJZaNGRqHQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Iago Abal , Andy Shevchenko Subject: [PATCH 5.10 109/530] usb: gadget: pch_udc: Revert d3cb25a12138 completely Date: Wed, 12 May 2021 16:43:39 +0200 Message-Id: <20210512144823.385784572@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 @@ -596,18 +596,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); } /** @@ -1166,20 +1170,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; }