From patchwork Thu Sep 26 05:49:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 830947 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (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 D8CFF1D5AD0 for ; Thu, 26 Sep 2024 05:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329813; cv=none; b=jGbKkdlsW27aeS9o2CMVSCCQdEGSUPxZhpyEhneTroU2fIBY1sEK6jRiVxq2kt86OgRckrMlYICMySx4f3gxODC0uZBFYupb9Sx17n1TpQAVtwO3VsMYi3sYphqsX9rZiCQq7wj0C1gPviKQv6ZjD+uY+ITcZJbLg4nTaX1niGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329813; c=relaxed/simple; bh=gWqOpuNGrrOnjJXc15ru2E59HKMuTUnNVS2eBMpuErg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XzDVZv5rUxFzH7usLiH5o94rla06EkIXtMkM+m6Op0SWo880zbJtBQnZtyxRTX9tdcnLLb+xoQPF7hr4LGE4j8T/iNvySutBI0ROOYsekXrvfnsBukhBF8s5cJZb5R9hWfh8opG2piaFEbg1W626rTmarALsbTTwvpD/IZDzmSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SK1uKoUz; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SK1uKoUz" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-4583209a17dso4750881cf.1 for ; Wed, 25 Sep 2024 22:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727329811; x=1727934611; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5R3jeoC+JoIkoCMlX58x+koThQrbjgmlcnr2nfF31vI=; b=SK1uKoUz6kcqkwZLy+ncgszmjEPDSTEWgsv5twozkodCawIB8iv1SmMLE1suSIJM8z C1zMHjyUUHeh/yZ409uvNuwTAf27Q97AMoMCpybbRX73SEZ74tb5y4jauZD/Df2vmbjh 7q/q6NyPOiGnSD75ACOlctESVzKve56It04v8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727329811; x=1727934611; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5R3jeoC+JoIkoCMlX58x+koThQrbjgmlcnr2nfF31vI=; b=T3hR9qGSWHxOEomtI6sWKD8ngjzI7wt29EIDHA8madypGk/na5Do68pOS7/ipUMQdZ 2pwiSi0H/U4h7CNF5rtTX0Y0AyGka9aSu0wdjXgOiOg+rTD0MeZEMixY6aSsCMxVo1FU 1V0xDA5kH76jThZsmgn5O76RXtOgvywQc+ZLrDxma0olCjswpWtJUrKbGdQkuJn7Igk0 zL0qtx+yXmIgCpB5ctpGwMZtvd9Z3wtf0LW3dHqHZYuNNFShOFkGbo3Xa8jtk31gomsQ ccWyNVxxDGXxzZvnScrW37J4zYWTbp4cUB6aAcK0/0Xnx+3Xuc44f5GfZx8hA+U5loRO skVA== X-Forwarded-Encrypted: i=1; AJvYcCUx2DZYqGubUogPluJ2MHF8p1PZdY8bxmdwjzwCAsdJQKuAE9ww9XAw5PwIW8Vp0UCBrZeg0EIpxKb1Pw==@vger.kernel.org X-Gm-Message-State: AOJu0YzbH+VQESsrAbNO4F0D0d6k174+0SM7GJ0jCaY/Xe5kfDa9q5H6 y7KRaUl2leAL6AYw2Zupx14KH/K7yvK76XxVXzlxU0oOoWkqKwT6DQ/H4t7Uew== X-Google-Smtp-Source: AGHT+IGgk05kC/TahyF9M/owtAg5RjgPRrJ8XBEO9Pn6N3lVjtrLE8EQvrkLA+fJYpM1tZpJ60/CWg== X-Received: by 2002:ac8:58c2:0:b0:458:2756:fd8 with SMTP id d75a77b69052e-45b5e02b09fmr84774081cf.40.1727329810605; Wed, 25 Sep 2024 22:50:10 -0700 (PDT) Received: from denia.c.googlers.com (76.224.245.35.bc.googleusercontent.com. [35.245.224.76]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5264b629sm22406781cf.64.2024.09.25.22.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 22:50:09 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 26 Sep 2024 05:49:57 +0000 Subject: [PATCH v7 1/3] media: uvcvideo: Refactor the status irq API Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240926-guenter-mini-v7-1-690441953d4a@chromium.org> References: <20240926-guenter-mini-v7-0-690441953d4a@chromium.org> In-Reply-To: <20240926-guenter-mini-v7-0-690441953d4a@chromium.org> To: Mauro Carvalho Chehab Cc: Guenter Roeck , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus , Sergey Senozhatsky X-Mailer: b4 0.13.0 There are two different use-cases of uvc_status(): - adding/removing a user when the camera is open/closed - stopping/starting when the camera is suspended/resumed Make the API reflect these two use-cases and move all the refcounting and locking logic to the uvc_status.c file. No functional change is expected from this patch. Reviewed-by: Sergey Senozhatsky Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_driver.c | 13 ++-------- drivers/media/usb/uvc/uvc_status.c | 53 ++++++++++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 22 +++++----------- drivers/media/usb/uvc/uvcvideo.h | 10 ++++--- 4 files changed, 65 insertions(+), 33 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index f0febdc08c2d..31e8942f1ef8 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2116,7 +2116,6 @@ static int uvc_probe(struct usb_interface *intf, INIT_LIST_HEAD(&dev->streams); kref_init(&dev->ref); atomic_set(&dev->nmappings, 0); - mutex_init(&dev->lock); dev->udev = usb_get_dev(udev); dev->intf = usb_get_intf(intf); @@ -2288,10 +2287,7 @@ static int uvc_suspend(struct usb_interface *intf, pm_message_t message) /* Controls are cached on the fly so they don't need to be saved. */ if (intf->cur_altsetting->desc.bInterfaceSubClass == UVC_SC_VIDEOCONTROL) { - mutex_lock(&dev->lock); - if (dev->users) - uvc_status_stop(dev); - mutex_unlock(&dev->lock); + uvc_status_suspend(dev); return 0; } @@ -2322,12 +2318,7 @@ static int __uvc_resume(struct usb_interface *intf, int reset) return ret; } - mutex_lock(&dev->lock); - if (dev->users) - ret = uvc_status_start(dev, GFP_NOIO); - mutex_unlock(&dev->lock); - - return ret; + return uvc_status_resume(dev); } list_for_each_entry(stream, &dev->streams, list) { diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index a78a88c710e2..e438ae5af2e8 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -257,6 +257,8 @@ int uvc_status_init(struct uvc_device *dev) unsigned int pipe; int interval; + mutex_init(&dev->status_lock); + if (ep == NULL) return 0; @@ -302,18 +304,22 @@ void uvc_status_cleanup(struct uvc_device *dev) kfree(dev->status); } -int uvc_status_start(struct uvc_device *dev, gfp_t flags) +static int uvc_status_start(struct uvc_device *dev, gfp_t flags) { + lockdep_assert_held(&dev->status_lock); + if (dev->int_urb == NULL) return 0; return usb_submit_urb(dev->int_urb, flags); } -void uvc_status_stop(struct uvc_device *dev) +static void uvc_status_stop(struct uvc_device *dev) { struct uvc_ctrl_work *w = &dev->async_ctrl; + lockdep_assert_held(&dev->status_lock); + /* * Prevent the asynchronous control handler from requeing the URB. The * barrier is needed so the flush_status change is visible to other @@ -350,3 +356,46 @@ void uvc_status_stop(struct uvc_device *dev) */ smp_store_release(&dev->flush_status, false); } + +int uvc_status_resume(struct uvc_device *dev) +{ + guard(mutex)(&dev->status_lock); + + if (dev->status_users) + return uvc_status_start(dev, GFP_NOIO); + + return 0; +} + +void uvc_status_suspend(struct uvc_device *dev) +{ + guard(mutex)(&dev->status_lock); + + if (dev->status_users) + uvc_status_stop(dev); +} + +int uvc_status_get(struct uvc_device *dev) +{ + int ret = 0; + + guard(mutex)(&dev->status_lock); + + if (!dev->status_users) + ret = uvc_status_start(dev, GFP_KERNEL); + if (!ret) + dev->status_users++; + + return ret; +} + +void uvc_status_put(struct uvc_device *dev) +{ + guard(mutex)(&dev->status_lock); + + if (dev->status_users == 1) + uvc_status_stop(dev); + WARN_ON(!dev->status_users); + if (dev->status_users) + dev->status_users--; +} diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f4988f03640a..97c5407f6603 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -628,20 +628,13 @@ static int uvc_v4l2_open(struct file *file) return -ENOMEM; } - mutex_lock(&stream->dev->lock); - if (stream->dev->users == 0) { - ret = uvc_status_start(stream->dev, GFP_KERNEL); - if (ret < 0) { - mutex_unlock(&stream->dev->lock); - usb_autopm_put_interface(stream->dev->intf); - kfree(handle); - return ret; - } + ret = uvc_status_get(stream->dev); + if (ret) { + usb_autopm_put_interface(stream->dev->intf); + kfree(handle); + return ret; } - stream->dev->users++; - mutex_unlock(&stream->dev->lock); - v4l2_fh_init(&handle->vfh, &stream->vdev); v4l2_fh_add(&handle->vfh); handle->chain = stream->chain; @@ -670,10 +663,7 @@ static int uvc_v4l2_release(struct file *file) kfree(handle); file->private_data = NULL; - mutex_lock(&stream->dev->lock); - if (--stream->dev->users == 0) - uvc_status_stop(stream->dev); - mutex_unlock(&stream->dev->lock); + uvc_status_put(stream->dev); usb_autopm_put_interface(stream->dev->intf); return 0; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index b7d24a853ce4..07f9921d83f2 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -563,8 +563,6 @@ struct uvc_device { const struct uvc_device_info *info; - struct mutex lock; /* Protects users */ - unsigned int users; atomic_t nmappings; /* Video control interface */ @@ -586,6 +584,8 @@ struct uvc_device { struct usb_host_endpoint *int_ep; struct urb *int_urb; struct uvc_status *status; + struct mutex status_lock; /* Protects status_users */ + unsigned int status_users; bool flush_status; struct input_dev *input; @@ -752,8 +752,10 @@ int uvc_register_video_device(struct uvc_device *dev, int uvc_status_init(struct uvc_device *dev); void uvc_status_unregister(struct uvc_device *dev); void uvc_status_cleanup(struct uvc_device *dev); -int uvc_status_start(struct uvc_device *dev, gfp_t flags); -void uvc_status_stop(struct uvc_device *dev); +int uvc_status_resume(struct uvc_device *dev); +void uvc_status_suspend(struct uvc_device *dev); +int uvc_status_get(struct uvc_device *dev); +void uvc_status_put(struct uvc_device *dev); /* Controls */ extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; From patchwork Thu Sep 26 05:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 830946 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 8D24E1714AA for ; Thu, 26 Sep 2024 05:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329815; cv=none; b=M96aHok0PLvu+yq4qslGC78yuRLeRbt7ppKhAAff1CNcsS5Poq4zEtFOe7v28pPINCUfHOcMLMRsGNPX+7v7fOLr3HKqT5LBcpauuPfRRdw2n5hhzjdRweN/DYjofpaXIeo9AhydyxGbpuy7BISPfiW41yDEKCZIUTesqhb3/x8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329815; c=relaxed/simple; bh=Bfu7bqhrmzOz9Ey2Adj2zHRWUZVXSf36bOoXdS7G1BU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nkK46GnZKdsuj1/jnuH+O9yPm/K02KejZIRAavgAasa1YyjjKltCFpZmvqEMEVSYkbEm3ddnnrjIGV8hHWKVWOHdfSGRtdXjJjMGjxnDhx+47M2y6Yf8NQU1XDqm50i/E7DmUdllZS8N1yFLThOy0jozfUvnYihIn3dLlv+KqOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=OZnvO57H; arc=none smtp.client-ip=209.85.160.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OZnvO57H" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-458320b30e7so3688701cf.0 for ; Wed, 25 Sep 2024 22:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727329812; x=1727934612; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HYIvqRnC2mqEpaPGnRTLTAO+wgXxtOMY+ADw+uJOyw8=; b=OZnvO57HA6FDm+Fwkd89McBAPowcvbSdIEMk86MotSNhQdIZKwax19WLh2XjaYyo13 GYDsQdPe0zTvzZMTqsmW5+XbTak08dmOz+4weyzXnlSx5BY/b2YJoJN5Fb4XnZMdXDRN aWp+0lH1iYfZbJ5FYq+Zv+IQPEw51faDnwK7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727329812; x=1727934612; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HYIvqRnC2mqEpaPGnRTLTAO+wgXxtOMY+ADw+uJOyw8=; b=tLhK8abw7Z6VnKCILW4YAjnGGASS4LLXl+ZVeKswtjIhFKkRGi5mLHqliD//IhHEdI LvMx8HhokSaB0uuQIJPnlnBPi6WAEsXI1i0WSzhI17J93VirEgQnA/OzfT6Rr+E9ziD+ x4/R4XZBAe3bEqR987O9iW0jxk5dvIszLpd9zHdU8BB2DZcx5qMIK75h+GsmsuV0FpRW hPpj9qKgVQGytDWXn/RgoaMl5uIzrkOjDzJgMnrw7vc5NILFH5MLLqAObO/cJOgBMbUh 7Va6BbZS4AiY0LTmB7J1lLUfWAub/3QxN+LGqMEBQtfnYDfFwWmCpCp0e4WVUbCFKyXv Cpxg== X-Forwarded-Encrypted: i=1; AJvYcCXkPnjd/PgF1Aexl2Y10GdgrPqznaPQIqWgXYu8hBzmc52HysI8kFyQexTewoGFySNxeOP9ffF1X2LSFQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzGdqhTa3DBiKPR7EuUTnbwwE4Y1TTg06p/nAsDdCaddFEl88q6 i2WxiN4H3WKk+OVTYinYbp6nhkXCGPJI+kiualK6woQl/xzCfZoh8ud9EUgm7g== X-Google-Smtp-Source: AGHT+IHpOZiuMWVYTw3bufjx9CXLF6X5TIqgtqRz1AT4LYEzDp58FI5NPEJFOE2ClOgshqTOtjB2iQ== X-Received: by 2002:a05:622a:130f:b0:44f:fb77:74ce with SMTP id d75a77b69052e-45b5e030abcmr70037471cf.47.1727329812443; Wed, 25 Sep 2024 22:50:12 -0700 (PDT) Received: from denia.c.googlers.com (76.224.245.35.bc.googleusercontent.com. [35.245.224.76]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5264b629sm22406781cf.64.2024.09.25.22.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 22:50:10 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 26 Sep 2024 05:49:58 +0000 Subject: [PATCH v7 2/3] media: uvcvideo: Avoid race condition during unregister Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240926-guenter-mini-v7-2-690441953d4a@chromium.org> References: <20240926-guenter-mini-v7-0-690441953d4a@chromium.org> In-Reply-To: <20240926-guenter-mini-v7-0-690441953d4a@chromium.org> To: Mauro Carvalho Chehab Cc: Guenter Roeck , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus , Sergey Senozhatsky X-Mailer: b4 0.13.0 The control events are handled asynchronously by the driver. Once the control event are handled, the urb is re-submitted. If we simply kill the urb, there is a chance that a control event is waiting to be processed, which will re-submit the urb after the device is disconnected. Fix this by calling uvc_status_suspend(), which flushes the async controls and kills the URB in a race-free manner. Reviewed-by: Laurent Pinchart Reviewed-by: Sergey Senozhatsky Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index e438ae5af2e8..d8d5b327693f 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -294,7 +294,7 @@ int uvc_status_init(struct uvc_device *dev) void uvc_status_unregister(struct uvc_device *dev) { - usb_kill_urb(dev->int_urb); + uvc_status_suspend(dev); uvc_input_unregister(dev); } From patchwork Thu Sep 26 05:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 831254 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 A3833187348 for ; Thu, 26 Sep 2024 05:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329817; cv=none; b=VVcijVweM5EfSrF5Jmt0ozJ4a+Imxau8bPtDdS16nXgWLb7MaOerRyo+8mIt5sU6KTKIJ4p26Xn8dETtPvHwKQsM2UMh5CicWKo4RGKOZfdiiPhzSqiixs/7r2PCguSsbl1L6VIWXiI3FjdfsetcCx6lty3vucgBoVGlvK/YNXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329817; c=relaxed/simple; bh=bp/AyInNx+sYmGScXTk/dVr8nFraf0tgtMRd3LHHRBg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ifcRvnIPW9lJJvBqDoMV04eNwx28igCELHwUWcaHP4JeECgo5jjJsO+65ZjYZuS+rKt+QLCb4C36HvLNxrxBKRdrocLSTfzPThPsU2GPYcgJfWQtgFaBxV/k9R0k3bxNt0DWmXY9vq9rZafo1NVGUV3sd+9pmeCs/XsEKC9louA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=WSS7ckOh; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WSS7ckOh" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-45832b2784bso4352931cf.3 for ; Wed, 25 Sep 2024 22:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727329814; x=1727934614; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1Jte9oqU3bEqLQEq3uaVn2nHKDdidO4uVkSl6injc2E=; b=WSS7ckOh7Rgcph7n8Z2LsZEk84OufCi6Ire0pDgM1fLfl9cILAbeVnpxUys1yMaL1M UoT6k0dJR8xaCvtgaFywqDbzaPhe1T1wLUpUiSg7HPbAQKi7Qm0Bz48cR86NU3Lu9gWb SeOyuibY33nC3nyEIXBcPn0izyvEM70KXUZy0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727329814; x=1727934614; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Jte9oqU3bEqLQEq3uaVn2nHKDdidO4uVkSl6injc2E=; b=dt44pkUZT3UribvKzUBdrcKoXtVba+LqcrMb5MWgrKrGjnduluOWB6KEtJ+YGkMo56 FYVyqUfcdR97D5ZYdPSD8FwK1F7YCg/aBqyDq1jmB72moGP5i7J2LWyBTEXiO9DQjoUY b2ijscvbr0VJ87Nbg7bNNW/vbpxyXhYH5J9KDldjjWybCQ8EzYI/yLc1LxTUmXywZa5e cS7weKlWCaVr4QUuCOmPrrP4theWjZ3C7S470V+12PWfW/YW9lA7zDOhi9vTkiu5Yfvg UTOxwA8Ud+gD21Ce62zjat8QXvteRhAPD+8Ik0z9VCkqL+U6PhUeCt7Gyyq0z01s3ZWv gqRQ== X-Forwarded-Encrypted: i=1; AJvYcCXazV1Sei5CW5Vs2gDI97OD2YGfxghzZjDRyHCKEM8pwzloNUAjb3bd+XUkFcHAQ+EdwPt7+IpxTp6Xfg==@vger.kernel.org X-Gm-Message-State: AOJu0Ywu+wuG/GrLWqr1KptxYGgmnYsejT/LNC+nBEgkrNpk1pGebyze 5Vyfi6lWaDpjehvl8BSLEk67koIip84reVFex+69KPil2wGly+AiHloNObNr7g== X-Google-Smtp-Source: AGHT+IFxCfHwEy321Bw8EBQt293rqr5m34pmJLEgFglHcCaIk+ih11NQYLPeHDvPTI9jJvdqYBjNuQ== X-Received: by 2002:ac8:5885:0:b0:456:94fe:dcdf with SMTP id d75a77b69052e-45b5def4674mr65467061cf.35.1727329814538; Wed, 25 Sep 2024 22:50:14 -0700 (PDT) Received: from denia.c.googlers.com (76.224.245.35.bc.googleusercontent.com. [35.245.224.76]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5264b629sm22406781cf.64.2024.09.25.22.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 22:50:13 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 26 Sep 2024 05:49:59 +0000 Subject: [PATCH v7 3/3] media: uvcvideo: Exit early if there is not int_urb Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240926-guenter-mini-v7-3-690441953d4a@chromium.org> References: <20240926-guenter-mini-v7-0-690441953d4a@chromium.org> In-Reply-To: <20240926-guenter-mini-v7-0-690441953d4a@chromium.org> To: Mauro Carvalho Chehab Cc: Guenter Roeck , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus , Sergey Senozhatsky X-Mailer: b4 0.13.0 If there is no int_urb there is no need to do a clean stop. Also we avoid calling usb_kill_urb(NULL). It is properly handled by the usb framework, but it is not polite. Now that we are at it, fix the code style in uvc_status_start() for consistency. Reviewed-by: Laurent Pinchart Reviewed-by: Sergey Senozhatsky Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_status.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index d8d5b327693f..c7901ac32c26 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -308,7 +308,7 @@ static int uvc_status_start(struct uvc_device *dev, gfp_t flags) { lockdep_assert_held(&dev->status_lock); - if (dev->int_urb == NULL) + if (!dev->int_urb) return 0; return usb_submit_urb(dev->int_urb, flags); @@ -320,6 +320,9 @@ static void uvc_status_stop(struct uvc_device *dev) lockdep_assert_held(&dev->status_lock); + if (!dev->int_urb) + return; + /* * Prevent the asynchronous control handler from requeing the URB. The * barrier is needed so the flush_status change is visible to other