From patchwork Mon Mar 25 16:31:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 783894 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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 2CDB913440D for ; Mon, 25 Mar 2024 16:31:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711384299; cv=none; b=pQfqIoc9bTrLemepZhrYUj9FCszYAOdA8DUrgkc/f7jVfD3DfkN97UtjyzVJiX33EB/W2tSM0PT+Mavj4vLtILiprg7VJtQaf2wMsp4M/rkp/4VG6+YOg4UzBMB0m9lsd9fLjeTvhHiOuv+mTAgwhwOThYQN+ZMMG47+h507OTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711384299; c=relaxed/simple; bh=IbGWx43paY/eY3BoKH9LIehCJLKILNpJ3miMe4Ay6xU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VcB4+ycLqzuifyGMdQYuSP6D5u65LNhHw3YoAJ3xQ8OqzUuGm5O9VaZPkcLpZeZa1CeN5FPo9bST7kCujWmq8MTL0z3Tv7xDvj+1pw9Z1IPYfifBFvfiDhg6jGPSv7eO5srFY8iLMMpJa4n0+XQhbNZI/7fEUyAiT+E9J/wQXX4= 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=XALqHOUR; arc=none smtp.client-ip=209.85.219.51 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="XALqHOUR" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-69629b4ae2bso41226646d6.3 for ; Mon, 25 Mar 2024 09:31:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711384296; x=1711989096; 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=yu6CRq784zZk8JmoJH+VcllViInTfNkEV44O9xYOrqY=; b=XALqHOURwLxzSrUCmAtzogdBXLS0B10YeY7xXUN84e1uA57vs8G54f9t1Y15lCoT8t WpkWbGRHUb9R29DwN6A/Az5w6p9CJq1wX5t42u6je8wLdJb36RWtA8D8cYPRhDv4E2ll 1pdDG2ZiTdgYbtAaePhd2mdxyCXDYj6DIruk0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711384296; x=1711989096; 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=yu6CRq784zZk8JmoJH+VcllViInTfNkEV44O9xYOrqY=; b=c3BVYaHdxzaByqyk1V2uEmkAKVkXf/bjg0olGwwBCesurp9Tnnd3G64r0kuzBYm0bS e+TaX48eq5HkudE6mD0hs3ldzkg93noRleypWYLHCqUQenTOoDm8+8hOIwdAC7ajZAml vruSonOzjKfXQvSbqVSGsUAgW9u8JAdmdVLpYjA/61sC/gQHahHWCtKMe2sQuA8SiBeX qJESGLDxnBIbIBkLe4oKycaP51wGten9qQpYfbJFtfISBBVepq9oC1jclrLZE1jfQGss JV4i4l5HMjJoHWmFnVHUqaksCW6lQFWb0/z6I0QvvE0+gX9sKAbPCbUfmsEd0i3ai/Bk FZ1g== X-Forwarded-Encrypted: i=1; AJvYcCXDxV72I+rqZAvU4Dfa4cRPOWNegAx9m+KN7/HqFSbVM/zP2ypniT7hEI4h6AwD5OvqsRx9cghTrIGtmVQ5fCV7x2eGltFE2a0WhrI= X-Gm-Message-State: AOJu0YwFsLZcv7EQouNuqVkJOOnJd7xeJKNceYyVBgomzbFcD7gEok/R Gp5cCrPTAB9c7bQjp3CNntz+AswaqYGrRFH6QLRIy/Hz1FfnlgSQOSvVvdsTZg== X-Google-Smtp-Source: AGHT+IEtUg0mwiYcW1LyaV+FksxmaMuJ5FBKdGORci81ZmbE9EryF5lCqjbumq/U6M1tZw0jXCPXEQ== X-Received: by 2002:a05:6214:acc:b0:696:3705:fe5a with SMTP id g12-20020a0562140acc00b006963705fe5amr9938267qvi.7.1711384296101; Mon, 25 Mar 2024 09:31:36 -0700 (PDT) Received: from denia.c.googlers.com (188.173.86.34.bc.googleusercontent.com. [34.86.173.188]) by smtp.gmail.com with ESMTPSA id jr9-20020a0562142a8900b006905c8b37bbsm376330qvb.133.2024.03.25.09.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:31:35 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 25 Mar 2024 16:31:33 +0000 Subject: [PATCH v3 1/3] media: uvcvideo: stop stream during unregister Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240325-guenter-mini-v3-1-c4bc61d84e03@chromium.org> References: <20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org> In-Reply-To: <20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org> To: Mauro Carvalho Chehab Cc: Guenter Roeck , Max Staudt , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus X-Mailer: b4 0.12.4 uvc_unregister_video() can be called asynchronously from uvc_disconnect(). If the device is still streaming when that happens, a plethora of race conditions can happen. Make sure that the device has stopped streaming before exiting this function. If the user still holds handles to the driver's file descriptors, any ioctl will return -ENODEV from the v4l2 core. This change make uvc more consistent with the rest of the v4l2 drivers using the vb2_fop_* and vb2_ioctl_* helpers. Suggested-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index bbd90123a4e76..17fc945c8deb6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1911,8 +1911,19 @@ static void uvc_unregister_video(struct uvc_device *dev) if (!video_is_registered(&stream->vdev)) continue; + /* + * Serialize other access to the stream. + */ + mutex_lock(&stream->mutex); + uvc_queue_streamoff(&stream->queue, stream->type); video_unregister_device(&stream->vdev); video_unregister_device(&stream->meta.vdev); + mutex_unlock(&stream->mutex); + + /* + * Now the vdev is not streaming and all the ioctls will + * return -ENODEV + */ uvc_debugfs_cleanup_stream(stream); } From patchwork Mon Mar 25 16:31:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 782432 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 403D81442EE for ; Mon, 25 Mar 2024 16:31:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711384299; cv=none; b=FWWUsF2fiCr2nfSkgBRQ60lkqkMevvbQK0AY/xSQjKoAr5b6JIF5bCci7IV3UDCKFOy2cj/GIG/hWtaL0wiVPSDV8tM8qu6LTQQU8MIt9ORiu1nXYLL02vZOWiDKx2A6qvGIJmdcnJSvHQJzSeP+C1xawfyM5p9LU6qL1IY9UdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711384299; c=relaxed/simple; bh=JlvQ9Yfn11uIbhjEgaTFQsmPGd/1yuqa1pSRCbtCi84=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nfuZgNE8PSP7VHDS+rsuWzQyNgYUj5+FP4b0WSVTtNHoeufLM3Mv/UI1n0Lq5xAiMzBXDRyYAR8AEfymWz71iHH6aDXSaB798fNPw/8xam9U0YH7/rn0Q/yj5fHSCdSjOulLUCwqxgQ8bTT6nuP9PTFuY/h/dvCHc/n6IjYahSY= 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=DvvLcanG; arc=none smtp.client-ip=209.85.210.45 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="DvvLcanG" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6e6a1d24770so2715041a34.0 for ; Mon, 25 Mar 2024 09:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711384297; x=1711989097; 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=7Nvi44hWY4ZiLch2QLFxmRlfeQ6MV7x23bO6+n52bYE=; b=DvvLcanGWrqOM87X8pEfRNoLZSMOy9ii0EBYfXZWKEwbRaj5Leivm63pWXJzIZj7Z/ rVSKAFEb/2cKNeaKJH2vCt8a/PXjrFhpN5WMUkQttzM5vLFt5hfog0/0rsChxU0Yp05T m3dJlpWPEq+QBGqrgd0pDPeIo3YuX3fX+rF48= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711384297; x=1711989097; 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=7Nvi44hWY4ZiLch2QLFxmRlfeQ6MV7x23bO6+n52bYE=; b=e9akoKM+8GRjVPL0HSkVK0BivQBEvS9kZkGyoAoTID2wZvuu+rUKhTcVH2Ofz/WmUf cCHw+3UNNWYpwsJQ/5US/TKadAWsHWhJsCbJQLreORTLJ87epuFMudy4Q+WeKcox7oa0 M9cukngJ0RSUrgHpeHBbN0Q+ptLGkCXZniuU9eFW1tB22IkPODV16Vz+XZ3XvN8rhf/q 7KUpmzpMPiaHSFg8ofFpTROeyG0ovu3/Qp6ZlDCGOVrlZmtTBryXqhkwr7UZznf49hYS vllGNbCgB/tx/4F0LQVcvJ87lGwd8l5uPKhUhjryR6hNP5h+OEsEAKBMZZwB/4eWC8QT PR2Q== X-Forwarded-Encrypted: i=1; AJvYcCVkQJwXUBVNnU1SJ7LHpaVlVTqotrAgzA0lio/l/igUMMg4DxH/LscDsPi0hcLXwmiHHY8TyD/sJBhyOqF4xnCbbpwHnaAl3vrpkBI= X-Gm-Message-State: AOJu0YyiRPcrgFgfvNTqANnBVSnn3YQxU3dn6phwwQ5wP+zenPiPOWhp jNL6v4hSSkc9ioErqmpeiy4jtO1PxB6pWECpHgXVtHjMaZBAWLKmvz16ZNJ80w== X-Google-Smtp-Source: AGHT+IGL6ElCSHpsFv9WEDn+/Rwz1Qq56BdY9L8OznTxh2JDZ+MC9Fj8h5NC3ublq3EXy1tW8YR6uA== X-Received: by 2002:a9d:69d9:0:b0:6e4:e561:6ba7 with SMTP id v25-20020a9d69d9000000b006e4e5616ba7mr9350669oto.25.1711384297319; Mon, 25 Mar 2024 09:31:37 -0700 (PDT) Received: from denia.c.googlers.com (188.173.86.34.bc.googleusercontent.com. [34.86.173.188]) by smtp.gmail.com with ESMTPSA id jr9-20020a0562142a8900b006905c8b37bbsm376330qvb.133.2024.03.25.09.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:31:36 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 25 Mar 2024 16:31:34 +0000 Subject: [PATCH v3 2/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: <20240325-guenter-mini-v3-2-c4bc61d84e03@chromium.org> References: <20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org> In-Reply-To: <20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org> To: Mauro Carvalho Chehab Cc: Guenter Roeck , Max Staudt , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus X-Mailer: b4 0.12.4 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. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 13 ++------- drivers/media/usb/uvc/uvc_status.c | 57 ++++++++++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 22 ++++----------- drivers/media/usb/uvc/uvcvideo.h | 10 ++++--- 4 files changed, 68 insertions(+), 34 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 17fc945c8deb6..b579644ac0745 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); @@ -2282,10 +2281,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; } @@ -2316,12 +2312,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 a78a88c710e24..ff66482346dde 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -262,6 +262,8 @@ int uvc_status_init(struct uvc_device *dev) uvc_input_init(dev); + mutex_init(&dev->status_lock); + dev->status = kzalloc(sizeof(*dev->status), GFP_KERNEL); if (!dev->status) return -ENOMEM; @@ -292,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); } @@ -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,48 @@ void uvc_status_stop(struct uvc_device *dev) */ smp_store_release(&dev->flush_status, false); } + +int uvc_status_resume(struct uvc_device *dev) +{ + int ret = 0; + + mutex_lock(&dev->status_lock); + if (dev->status_users) + ret = _uvc_status_start(dev, GFP_NOIO); + mutex_unlock(&dev->status_lock); + + return ret; +} + +void uvc_status_suspend(struct uvc_device *dev) +{ + mutex_lock(&dev->status_lock); + if (dev->status_users) + _uvc_status_stop(dev); + mutex_unlock(&dev->status_lock); +} + +int uvc_status_get(struct uvc_device *dev) +{ + int ret = 0; + + mutex_lock(&dev->status_lock); + if (!dev->status_users) + ret = _uvc_status_start(dev, GFP_KERNEL); + if (!ret) + dev->status_users++; + mutex_unlock(&dev->status_lock); + + return ret; +} + +void uvc_status_put(struct uvc_device *dev) +{ + mutex_lock(&dev->status_lock); + if (dev->status_users == 1) + _uvc_status_stop(dev); + WARN_ON(!dev->status_users); + if (dev->status_users) + dev->status_users--; + mutex_unlock(&dev->status_lock); +} diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f4988f03640ae..97c5407f66032 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 6fb0a78b1b009..00b600eb058cc 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -555,8 +555,6 @@ struct uvc_device { const struct uvc_device_info *info; - struct mutex lock; /* Protects users */ - unsigned int users; atomic_t nmappings; /* Video control interface */ @@ -578,6 +576,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; @@ -744,8 +744,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 uvc_control_mapping uvc_ctrl_power_line_mapping_limited; From patchwork Mon Mar 25 16:31:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 783893 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 7498714430E for ; Mon, 25 Mar 2024 16:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711384301; cv=none; b=gAyCtpdh+luU/5hKxNqsfRdLEMGkn7OY5OHlWvTdFVbM1uVWGh0em3hIZosGGfw8rtVbiKWfgZjTsXgsSnN2f9AC99hzLXwF2RNJC97nbfSXUXOXTqdlE1MQNxerZ4HUbB6ZZ2GC8Rs+flCRGXYFYH/cJlZZeSE7ksQiz3pS950= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711384301; c=relaxed/simple; bh=aOOKQc0+BjjZOy3Vjv74lXq/IqKybd1rwgZmgeR9ipA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MuFSgkbNIlrm27dofo54zWoTQ5LuJMSiMDQQ23LZtdGrn8nUzgUti1lt5dbDZyEsyb0VBLvGimJ/qMDkX0y8z70zsLXeF3rx+a6ynlv7g5qMr+OLvBvDwybCg8HUIRM3E6mm5OF3wz/u1ZlFNb1BV6eCM9l2sOZRb0iBqJG1MD0= 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=OXYX0vK7; arc=none smtp.client-ip=209.85.219.49 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="OXYX0vK7" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-69699fecccdso103016d6.1 for ; Mon, 25 Mar 2024 09:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711384298; x=1711989098; 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=BVxxZahJvjEwwum0ohe5k7ku49jCEwk4G4aHidn4xg0=; b=OXYX0vK7tfQH7jnw4traRHrdXVn5h7uu7+Bgvg76LCeecfwZ+kS3HLO4eCl3oj3JWg VDrwaV/1LJkcJNau0Rqwmpq/wEZ2fp906JYMrjLKCtGCBKu1LNXyKAMRNZJ4l3SVSqoD PaKb/AQZEZLfgjvFay1pKc0eFBEru+y+ZJnu8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711384298; x=1711989098; 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=BVxxZahJvjEwwum0ohe5k7ku49jCEwk4G4aHidn4xg0=; b=oYm6ZuQ9PVzlcD4PCFoME0/wmZnq8zPKxe9zbaqkTnTjMvKkLZ4j8XrnI4qWm15rud wZcUuttqT0qudOfiWtZ2wZK4a3i8ZKhBqZSVEio6TBWSQS+9JZSnV0fYKWMrNAdSn4zN lqomZNqedJq04jJhXC77cesPA8BHMMO+Wfkpb/vLHINFxj8lBx8EL930kBIXqh+WWyvS NWoEg0Qj9URdIRBRn4cvMSHtYeNjyckpEjwRA7YNgeYJuNFhem6WQzcTnXEnDRRr2KgU k/HdfQj7Xuw6iJzkj8TEAeBKSHnDPMUSnH7t7pWy5pkC3+tXQQuYUkEvD24EEwU71ot0 CVew== X-Forwarded-Encrypted: i=1; AJvYcCUzQiThD7RN7+KfHsFVnNrFwvsPSQZKgULRxtS6MGARKAuW1S3+nF6raXVdPsPLh7LFl+k34HbllxwKvo/hlDNFphULFAbDfByI9Hs= X-Gm-Message-State: AOJu0Yz86UQUm2kD2b6c/tl5vbd91ynAHWKTzgi8CL411n15KLYR64ED qISO7xew2gIm6f0kcs4XwJIV6tW6az8GkwIz/DqDEzcA22NO1V0LoiY9P0aeoA== X-Google-Smtp-Source: AGHT+IFaAdbf/X8AXK38Yh+rghPapO/rYthILa86FqkUwUs85GXtW0rd0aFddwLw/d0hBD3qkfuVSw== X-Received: by 2002:ad4:4303:0:b0:696:8865:3437 with SMTP id c3-20020ad44303000000b0069688653437mr3182212qvs.65.1711384298419; Mon, 25 Mar 2024 09:31:38 -0700 (PDT) Received: from denia.c.googlers.com (188.173.86.34.bc.googleusercontent.com. [34.86.173.188]) by smtp.gmail.com with ESMTPSA id jr9-20020a0562142a8900b006905c8b37bbsm376330qvb.133.2024.03.25.09.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:31:37 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 25 Mar 2024 16:31:35 +0000 Subject: [PATCH v3 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: <20240325-guenter-mini-v3-3-c4bc61d84e03@chromium.org> References: <20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org> In-Reply-To: <20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org> To: Mauro Carvalho Chehab Cc: Guenter Roeck , Max Staudt , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus X-Mailer: b4 0.12.4 If there is no in_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. 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 ff66482346dde..f644ac7e67427 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