From patchwork Fri Dec 15 21:07:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avichal Rakesh X-Patchwork-Id: 179553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9578079dys; Fri, 15 Dec 2023 13:08:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6KZd7R6Uay4U6rMIXf5R5cToyHaMYb4yTuUKeEnmv0H6bprhmjRbpvi3kXZ+Z6a5BhbSh X-Received: by 2002:a50:d613:0:b0:552:fa55:210 with SMTP id x19-20020a50d613000000b00552fa550210mr20430edi.62.1702674509419; Fri, 15 Dec 2023 13:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702674509; cv=none; d=google.com; s=arc-20160816; b=ETjzZz6QOwQEIcW+QgpSyvs1yUOAPVNL2SSkFO5K1xblZi6yk3TjjGmsJpcsnpn9wo ldAbT6q9UgcVcVi5MFSPCyP8cyPIIdBAaG0/H4vlgPXX7Dlzt+zBu1Zc1Lohlzx7yUYi dIJEBC0umHAQQI9OEY1jQxfs7L5h319isNYqEWufJVo+NVo9FM/XyjId8QW0qd61glrG lo+3MCkK4hS1dBOO5brVsPnAvyk6SA1f9gKwyl04cs5xGHay8J46JHWcqp6KfzQTJaBo QZWdbuXp1pdTe7VqlH4NDNXRA5k0XWzjbTDAzT7xYvOqgjOB+h6qMzX40pBWLpEovnnF dD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=GRqAFzXiOHT+uI9y2fcqSO7bCGQ2RPswJt9PYrloaog=; fh=xSG2rkAAUWPhqPdqpMIzTf0guEu4Yf24G8xOCRNvyd0=; b=B2jw17gsUmteo+u8nvIme90J84idLUDTYOPOoa2uZbl8iZTa6j9Ihpo5Za42OkgJSd 5ywS7tctPC1a1uE58Hi/1VLr5+TqIu9MPlLWRdFz6WfbZHWeubXyLCluAddTi8Z6k4Z6 wPiFAwfEYATarWeuw/82RWI/HxD/H0rKY1RHGycW5e7vkIB5dYsISmfu8zDePpIZEOuY 8hctAl4DXVWmE0M49F7YRc2FIov3vP5WBhNZLi/CaNSoNAlWmEvoWkUJNMmG9FRlWlhP 53uhqsorswfLXBr6N1+gS7NdXlaHB4itmiwJnnGhwR5sHDJOj5N0QW2AI57D6RtFBIAJ /duw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sGR3dj0Y; spf=pass (google.com: domain of linux-kernel+bounces-1654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1654-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b10-20020a056402350a00b0054f63eefe11si7472039edd.559.2023.12.15.13.08.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 13:08:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sGR3dj0Y; spf=pass (google.com: domain of linux-kernel+bounces-1654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1654-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0D1971F24875 for ; Fri, 15 Dec 2023 21:08:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2EC548CD5; Fri, 15 Dec 2023 21:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sGR3dj0Y" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1FB54778B for ; Fri, 15 Dec 2023 21:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--arakesh.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbcda1ff95bso950788276.3 for ; Fri, 15 Dec 2023 13:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702674480; x=1703279280; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GRqAFzXiOHT+uI9y2fcqSO7bCGQ2RPswJt9PYrloaog=; b=sGR3dj0Ybnxv6XK1fid3RuxGpe8SQK+ZwVr6c7hkrrJammT+YVev8BuvGK9zB9RUI1 i5fDBTVPBCx7S9aFKpYsA0g+EsnH1BP7bRc6CU5dXPXEnpj+PusWECeRQO0DJ3EiXzgl 8cBGVDFds/6jQunY0+sMgXUkyXtOfsH1oIm7s02Be5iqfCkzBAhVj/FBr98kJKhuOoLC 1QNcKWsF5y/Oa+5Xofvuz9ByVULzGAo+0jvWHu1Nh0OWwXolcj/gpX1sGNX2Wvh7QPRh 47ZrfrIymLbA+YLTZqZU5Cr2OnGMih3JlEzqWqeOW5U0dsbe9LpnWzAvJPcbBNywlG8A 7Dvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702674480; x=1703279280; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GRqAFzXiOHT+uI9y2fcqSO7bCGQ2RPswJt9PYrloaog=; b=apq5QS9jm6NA70e1kURAB5QIg7W+jJI07mT/i3oYViTJT3LfC9Z1Dk6uuvjA06nTXQ 3ZAnqG7cWu+K8F7hjmNb0YXgyh17pGp+Xfg8BVJbS/6z8oJv64bGt3Vcr7crsIYqWo+R ehIllgyWXZVZjXALqL/ahypVPA5xTYqjr/MUHKijLN3XsnilxPXDJQMax0f696T3yuRd foHpg4re4S4dH57rUEoLKVj7JO3AamiXuGFYvIO3ykThx848O0pdi7p25VMlW4tL5CT1 FlxIvKPjw2kaKLVEj8SPYb3nLfNboBVE7EvrYiNCBXVe6n5jVVmU8apKmEsUTZFDUbmw sOrQ== X-Gm-Message-State: AOJu0Yx2iCfTCSZg7g7kd9OGdOIvmhzRYiXEJFfVZNUtJUK5J92+nrDp ND/b7m+trcLIz2intGuMQvAf9i1SV2ZJ X-Received: from hi-h2o-specialist.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3cef]) (user=arakesh job=sendgmr) by 2002:a5b:786:0:b0:db9:772b:1020 with SMTP id b6-20020a5b0786000000b00db9772b1020mr134630ybq.5.1702674479792; Fri, 15 Dec 2023 13:07:59 -0800 (PST) Date: Fri, 15 Dec 2023 13:07:45 -0800 In-Reply-To: <20231215210746.821494-1-arakesh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231215210746.821494-1-arakesh@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231215210746.821494-2-arakesh@google.com> Subject: [PATCH 2/2] usb: gadget: uvc: Remove nested locking From: Avichal Rakesh To: dan.scally@ideasonboard.com, gregkh@linuxfoundation.org, laurent.pinchart@ideasonboard.com Cc: etalvala@google.com, jchowdhary@google.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Avichal Rakesh X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785383626649893460 X-GMAIL-MSGID: 1785383626649893460 When handling error status from uvcg_video_usb_req_queue, uvc_video_complete currently calls uvcg_queue_cancel with video->req_lock held. uvcg_queue_cancel internally locks queue->irqlock, which nests queue->irqlock inside video->req_lock. This isn't a functional bug at the moment, but does open up possibilities for ABBA deadlocks in the future. This patch fixes the accidental nesting by dropping video->req_lock before calling uvcg_queue_cancel. Signed-off-by: Avichal Rakesh --- drivers/usb/gadget/function/uvc_video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index e5db1be14ca3..d15b9b4c4fcc 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -469,13 +469,15 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) * Put request back in req_free for it to be cleaned * up later. */ - uvcg_queue_cancel(queue, 0); list_add_tail(&to_queue->list, &video->req_free); } } else { uvc_video_free_request(ureq, ep); + ret = 0; } spin_unlock_irqrestore(&video->req_lock, flags); + if (ret < 0) + uvcg_queue_cancel(queue, 0); } static int