]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: uvcvideo: Only save async fh if success
authorRicardo Ribalda <ribalda@chromium.org>
Tue, 3 Dec 2024 21:20:08 +0000 (21:20 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:43 +0000 (12:47 +0100)
commit d9fecd096f67a4469536e040a8a10bbfb665918b upstream.

Now we keep a reference to the active fh for any call to uvc_ctrl_set,
regardless if it is an actual set or if it is a just a try or if the
device refused the operation.

We should only keep the file handle if the device actually accepted
applying the operation.

Cc: stable@vger.kernel.org
Fixes: e5225c820c05 ("media: uvcvideo: Send a control event when a Control Change interrupt arrives")
Suggested-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Link: https://lore.kernel.org/r/20241203-uvc-fix-async-v6-1-26c867231118@chromium.org
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/usb/uvc/uvc_ctrl.c

index dd2aa4df7d69362bed37b14ff6b24c54b0d0de1b..45f47ff4a154a1b7e78c4c5294103fb93f711cbd 100644 (file)
@@ -1526,7 +1526,9 @@ int uvc_ctrl_begin(struct uvc_video_chain *chain)
 }
 
 static int uvc_ctrl_commit_entity(struct uvc_device *dev,
-       struct uvc_entity *entity, int rollback)
+                                 struct uvc_fh *handle,
+                                 struct uvc_entity *entity,
+                                 int rollback)
 {
        struct uvc_control *ctrl;
        unsigned int i;
@@ -1570,6 +1572,10 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
 
                if (ret < 0)
                        return ret;
+
+               if (!rollback && handle &&
+                   ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS)
+                       ctrl->handle = handle;
        }
 
        return 0;
@@ -1585,7 +1591,8 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
 
        /* Find the control. */
        list_for_each_entry(entity, &chain->entities, chain) {
-               ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback);
+               ret = uvc_ctrl_commit_entity(chain->dev, handle, entity,
+                                            rollback);
                if (ret < 0)
                        goto done;
        }
@@ -1709,9 +1716,6 @@ int uvc_ctrl_set(struct uvc_fh *handle,
        mapping->set(mapping, value,
                uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
 
-       if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS)
-               ctrl->handle = handle;
-
        ctrl->dirty = 1;
        ctrl->modified = 1;
        return 0;
@@ -2040,7 +2044,7 @@ int uvc_ctrl_restore_values(struct uvc_device *dev)
                        ctrl->dirty = 1;
                }
 
-               ret = uvc_ctrl_commit_entity(dev, entity, 0);
+               ret = uvc_ctrl_commit_entity(dev, NULL, entity, 0);
                if (ret < 0)
                        return ret;
        }