From nobody Fri Nov 29 00:54:50 2024 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 E2C5E1531E3 for ; Thu, 26 Sep 2024 05:50:11 +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=1727329814; cv=none; b=n2pdveJ/w7usIafYQMX6fN5sPeNCqlpVbDSnc3+0g/rr2SUutzVBtEcUlg/LgtxIVNSiMUrDVXJmxq7Fxd0JIqoUPjiRd0c6aJeFdOmVgrKybqY2HpBoGuyZmi+XtW1ZSUQB8s5+lvfPBpiSemBvarmEnypPkLt3XcbnYD4DYqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329814; c=relaxed/simple; bh=gWqOpuNGrrOnjJXc15ru2E59HKMuTUnNVS2eBMpuErg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=apyxI3trZuFdVyxmq1mYs74QGVmKXer9/fFHpSP94fJ/YCYgoUdSdVD5aQPWDmET8DMGojaOVfq6Xq7tBMgwXVldIWAAtFR2l4hX3tdpCqzHM5LkEtJ/uG5jVw2UzJjUjICJsli1Cq9sOxQ1UNXAHAkuabIWgursrw7zgxVUqW4= 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.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="SK1uKoUz" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-4585e25f42bso4551641cf.2 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=nsVzPrzw+zOWuu1+6oyg1ExBmdp5euwdT9IGQwFUcSmo874r5gaQF9IcelBvNAiuT5 dvy5cIKx4+QseACHrejfCa/fXxwmQXVBS8DyYbU/SXYaRWGKwdODxllHhTBBcdhEPY2N PWp3y+OH0hYbiZkshbfp872IBLTuUnxK+AlwbBR8DQab231zbGjAtZ8jR+nT+hrWzKq/ Ugsg5uLL4/3Q03CNaIwTG29w2JtX4wZ2Gku40EZnmHuOywlER2sjKK8+jK0GTO9almRo zG4wnyA1HzLnnbx3fFWAmoqBepZzb6k3l7TtbxcTs/BSGHXG5P2gmiupjSTe7JQv29mp cGMw== X-Forwarded-Encrypted: i=1; AJvYcCUQCqJ8Re9xgcyGicjCqBo1z/mlKoVqM+kYMu8QzMiWspPoWWpKGxEaL0N6msKZAgOP6SOpQCMnXSmhAvA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywc2yUbO/IbkGGLtqB6YEvKdr25m1ft5cfK1zWD/ImGl07Vl6Ba 5LzwniCf6i3vvi+b/Pqbnay0MELMaKKvQfEfH42veavVjdd5cZ6DF6DkrIpY3A== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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); =20 dev->udev =3D usb_get_dev(udev); dev->intf =3D usb_get_intf(intf); @@ -2288,10 +2287,7 @@ static int uvc_suspend(struct usb_interface *intf, p= m_message_t message) /* Controls are cached on the fly so they don't need to be saved. */ if (intf->cur_altsetting->desc.bInterfaceSubClass =3D=3D UVC_SC_VIDEOCONTROL) { - mutex_lock(&dev->lock); - if (dev->users) - uvc_status_stop(dev); - mutex_unlock(&dev->lock); + uvc_status_suspend(dev); return 0; } =20 @@ -2322,12 +2318,7 @@ static int __uvc_resume(struct usb_interface *intf, = int reset) return ret; } =20 - mutex_lock(&dev->lock); - if (dev->users) - ret =3D uvc_status_start(dev, GFP_NOIO); - mutex_unlock(&dev->lock); - - return ret; + return uvc_status_resume(dev); } =20 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; =20 + mutex_init(&dev->status_lock); + if (ep =3D=3D NULL) return 0; =20 @@ -302,18 +304,22 @@ void uvc_status_cleanup(struct uvc_device *dev) kfree(dev->status); } =20 -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 =3D=3D NULL) return 0; =20 return usb_submit_urb(dev->int_urb, flags); } =20 -void uvc_status_stop(struct uvc_device *dev) +static void uvc_status_stop(struct uvc_device *dev) { struct uvc_ctrl_work *w =3D &dev->async_ctrl; =20 + 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 =3D 0; + + guard(mutex)(&dev->status_lock); + + if (!dev->status_users) + ret =3D 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 =3D=3D 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_v= 4l2.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; } =20 - mutex_lock(&stream->dev->lock); - if (stream->dev->users =3D=3D 0) { - ret =3D 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 =3D uvc_status_get(stream->dev); + if (ret) { + usb_autopm_put_interface(stream->dev->intf); + kfree(handle); + return ret; } =20 - stream->dev->users++; - mutex_unlock(&stream->dev->lock); - v4l2_fh_init(&handle->vfh, &stream->vdev); v4l2_fh_add(&handle->vfh); handle->chain =3D stream->chain; @@ -670,10 +663,7 @@ static int uvc_v4l2_release(struct file *file) kfree(handle); file->private_data =3D NULL; =20 - mutex_lock(&stream->dev->lock); - if (--stream->dev->users =3D=3D 0) - uvc_status_stop(stream->dev); - mutex_unlock(&stream->dev->lock); + uvc_status_put(stream->dev); =20 usb_autopm_put_interface(stream->dev->intf); return 0; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.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 { =20 const struct uvc_device_info *info; =20 - struct mutex lock; /* Protects users */ - unsigned int users; atomic_t nmappings; =20 /* 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; =20 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); =20 /* Controls */ extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; --=20 2.46.1.824.gd892dcdcdd-goog From nobody Fri Nov 29 00:54:50 2024 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 99DD517ADFF for ; Thu, 26 Sep 2024 05:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329816; cv=none; b=qxrbW4cx3wVXYa4h/WMD15k6DKmXW0VX0/a4mgjU2j//lKE2JAWxRyrolm98ot5TF4V4vSMJvhQU6iD2iXA0c37JBn/D3i/ACsFK43uH9cKwF+xmMoGauImQRiNuueI6GcpIK7mjLQQM0e+RBtZS5AwdLHeM4wDkKRRmbSPPGvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727329816; c=relaxed/simple; bh=Bfu7bqhrmzOz9Ey2Adj2zHRWUZVXSf36bOoXdS7G1BU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=n0L4airvG72KZEdcdrFMbcTgUP6qNFL623LdKAK5vAF500+KhXPK1jP/g/ezRyGrwNG+in7hPmXEY5HoWBwFMh+9OgV8LXHTTo54hxp2qzevekKULPy+3jzVN7iEvDFKxn38xy8OZt4hBPgTF8mt1CcqCp3tEN53V6LTr/m8KOU= 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.177 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-f177.google.com with SMTP id d75a77b69052e-4581f44b9b4so3490651cf.1 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=ZTJmEZDUlo7KTZvz0nY7Z8T3mr+nQ/ESgsZ1UnMDKABFvbrpiPN4BVWKhG3b6TiDd+ d08PKtQScFGokFzKWcAW7fSpGOJhuFdFoQlgLg/Ipg7lmxjPl2MsN9gKjR68fVvjZVVP 7Mghy+Y3Y2QJZqnQTkQ9wvrEHsl0MYS5uHVVbOMRXNT3AwoykYyVn2P8I/OEgGlTfmjU eVkJun56Xe3ttCd2BrRl9qrxBSCj7kiHus55Ql1ALjE2s9MqjEgi6RFsOOyaylPnEEVD UtFENF/tDSTJ9YsS3ax5X7CQ/Xje9yuSpoPbSksTYu8E3z1I2f4PYZ1sejT904YMBF9I ywkA== X-Forwarded-Encrypted: i=1; AJvYcCVcQ09DaiZvwUO+rzDvqgLzkPJpaTOkPl2M3weNwOh/obBBfws5GbBRRf05mNIcuAx2nyAUBXboO7ZLvRo=@vger.kernel.org X-Gm-Message-State: AOJu0Ywzw/G+FLSiTcbR7gzN2jq0dS/lig1mb0tlt69nJdJ6ubzxdWxs 1XUJOd0Q7GzkZgwStQ2JoQZYAEBQWjLUbH6Ab5TP8X5cIhf3lGZ0tIalVQmv/A== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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) =20 void uvc_status_unregister(struct uvc_device *dev) { - usb_kill_urb(dev->int_urb); + uvc_status_suspend(dev); uvc_input_unregister(dev); } =20 --=20 2.46.1.824.gd892dcdcdd-goog From nobody Fri Nov 29 00:54:50 2024 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 C14DA18756D 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-4582fb3822eso3802071cf.1 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=vIGDE8sfC23slFTIox80XH8uQuOZzZj+68/Nk6XbZHDRpENlfW5uV5OMbkV5XXbcu8 FzonTQC8hWSWs62wD1yJXkZw2OqNTojmYq7UiZt33G0KYYV5HgEi/HtRygDJZu25pWML nF80HoAGkLz2dy/r7o6BZ0OlLmlUH/WA21Ovuk1Dhq0LdU/fTqIW8jpDmF74I8W63yWd F00SIC/OFr25i8qR9OVQGJjiMUiFNEyszYPW2dSGQuauhYVMro9jelbPuLPXjOmW4tJ0 0NgEs8tMdXUBJ+YCSQfgYInHcfQOg4Ty+iY0CdoLfwcC18Smn8MKiiPB0hsi8wSLHSEO t+Vg== X-Forwarded-Encrypted: i=1; AJvYcCVa3wXZ+QOTER7uHzN6ybEdoHE4WL05yViPXiieDK/zNpdL39Z2CeOYUHPbORDjCiY7Pz1VyKPQO/qnyhc=@vger.kernel.org X-Gm-Message-State: AOJu0Yyb024kA9IPaWVGGZKBRm0mjMZN1AbLkYLlIDOHx1+tviePJ4ld 2590y8vHzBlY7J31LR5uxsD1UF/EiQf4wtFRVWUPO3l3MVf/Hf6jz6Va+9PysQ== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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); =20 - if (dev->int_urb =3D=3D NULL) + if (!dev->int_urb) return 0; =20 return usb_submit_urb(dev->int_urb, flags); @@ -320,6 +320,9 @@ static void uvc_status_stop(struct uvc_device *dev) =20 lockdep_assert_held(&dev->status_lock); =20 + 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 --=20 2.46.1.824.gd892dcdcdd-goog