]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: v4l2-ctrls: always copy the controls on completion
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Sat, 23 Aug 2025 01:46:18 +0000 (21:46 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:22:57 +0000 (16:22 +0200)
[ Upstream commit c3bf5129f33923c92bf3bddaf4359b7b25ecb4ba ]

When v4l2_ctrl_request_complete() is called and there is no control
handler object found in the request, then create such an object so
that all controls at completion state can be stored and are available
to userspace.

Otherwise any attempt by userspace to read the completed request data
will fail.

If allocating the control handler object failed, then indicate that
by returning ENOMEM when attempting to get the controls from the
completed request instead of returning ENOENT.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Stable-dep-of: 5a0400aca5fa ("media: v4l2-ctrls: Don't reset handler's error in v4l2_ctrl_handler_free()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/v4l2-core/v4l2-ctrls.c

index 41f8410d08d65fe27cf36ccc8770d716f64c2ab4..a84136f76d8ec8ed04ddb78ade5cee3376dd8a35 100644 (file)
@@ -3767,8 +3767,19 @@ v4l2_ctrls_find_req_obj(struct v4l2_ctrl_handler *hdl,
        obj = media_request_object_find(req, &req_ops, hdl);
        if (obj)
                return obj;
+       /*
+        * If there are no controls in this completed request,
+        * then that can only happen if:
+        *
+        * 1) no controls were present in the queued request, and
+        * 2) v4l2_ctrl_request_complete() could not allocate a
+        *    control handler object to store the completed state in.
+        *
+        * So return ENOMEM to indicate that there was an out-of-memory
+        * error.
+        */
        if (!set)
-               return ERR_PTR(-ENOENT);
+               return ERR_PTR(-ENOMEM);
 
        new_hdl = kzalloc(sizeof(*new_hdl), GFP_KERNEL);
        if (!new_hdl)
@@ -3779,8 +3790,8 @@ v4l2_ctrls_find_req_obj(struct v4l2_ctrl_handler *hdl,
        if (!ret)
                ret = v4l2_ctrl_request_bind(req, new_hdl, hdl);
        if (ret) {
+               v4l2_ctrl_handler_free(new_hdl);
                kfree(new_hdl);
-
                return ERR_PTR(ret);
        }
 
@@ -4369,8 +4380,25 @@ void v4l2_ctrl_request_complete(struct media_request *req,
         * wants to leave the controls unchanged.
         */
        obj = media_request_object_find(req, &req_ops, main_hdl);
-       if (!obj)
-               return;
+       if (!obj) {
+               int ret;
+
+               /* Create a new request so the driver can return controls */
+               hdl = kzalloc(sizeof(*hdl), GFP_KERNEL);
+               if (!hdl)
+                       return;
+
+               ret = v4l2_ctrl_handler_init(hdl, (main_hdl->nr_of_buckets - 1) * 8);
+               if (!ret)
+                       ret = v4l2_ctrl_request_bind(req, hdl, main_hdl);
+               if (ret) {
+                       v4l2_ctrl_handler_free(hdl);
+                       kfree(hdl);
+                       return;
+               }
+               hdl->request_is_queued = true;
+               obj = media_request_object_find(req, &req_ops, main_hdl);
+       }
        hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);
 
        list_for_each_entry(ref, &hdl->ctrl_refs, node) {