FAILED: patch "[PATCH] media: v4l2-ctrls: Don't reset handler's error in" failed to apply to 5.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y
git checkout FETCH_HEAD
git cherry-pick -x 5a0400aca5fa7c6b8ba456c311a460e733571c88
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025082154-botany-sandstone-7eeb@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 5a0400aca5fa7c6b8ba456c311a460e733571c88 Mon Sep 17 00:00:00 2001
From: Sakari Ailus <[email protected]>
Date: Thu, 8 May 2025 18:55:38 +0300
Subject: [PATCH] media: v4l2-ctrls: Don't reset handler's error in
v4l2_ctrl_handler_free()
It's a common pattern in drivers to free the control handler's resources and then return the handler's error code on drivers' error handling paths. Alas, the v4l2_ctrl_handler_free() function also zeroes the error field, effectively indicating successful return to the caller.
There's no apparent need to touch the error field while releasing the control handler's resources and cleaning up stale pointers. Not touching the handler's error field is a more certain way to address this problem than changing all the users, in which case the pattern would be likely to re-emerge in new drivers.
Do just that, don't touch the control handler's error field in v4l2_ctrl_handler_free().
drivers/media/v4l2-core/v4l2-ctrls-core.c +0 -1
@@ -1661,7 +1661,6 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)kvfree (hdl->buckets); hdl->buckets =NULL ; hdl->cached =NULL ; - hdl->error =0 ;mutex_unlock (hdl->lock);mutex_destroy (&hdl->_lock); }
Sasha Levin
maintainerPATCH 1/2 media: v4l2-ctrls: always copy the controls on completion
From: Hans Verkuil <[email protected]>
[ 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.
Stable-dep-of: 5a0400aca5fa ("media: v4l2-ctrls: Don't reset handler's error in v4l2_ctrl_handler_free()")
--- drivers/media/v4l2-core/v4l2-ctrls.c | 36 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +32 -4
@@ -3529,8 +3529,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)
@@ -3541,8 +3552,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); }
@@ -4113,8 +4124,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) {
Signature · 1 line
2.50.1
Sasha Levin
maintainerPATCH 2/2 media: v4l2-ctrls: Don't reset handler's error in v4l2_ctrl_handler_free()
From: Sakari Ailus <[email protected]>
[ Upstream commit 5a0400aca5fa7c6b8ba456c311a460e733571c88 ]
It's a common pattern in drivers to free the control handler's resources and then return the handler's error code on drivers' error handling paths. Alas, the v4l2_ctrl_handler_free() function also zeroes the error field, effectively indicating successful return to the caller.
There's no apparent need to touch the error field while releasing the control handler's resources and cleaning up stale pointers. Not touching the handler's error field is a more certain way to address this problem than changing all the users, in which case the pattern would be likely to re-emerge in new drivers.
Do just that, don't touch the control handler's error field in v4l2_ctrl_handler_free().
--- drivers/media/v4l2-core/v4l2-ctrls.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +0 -1
@@ -2187,7 +2187,6 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)kvfree (hdl->buckets); hdl->buckets =NULL ; hdl->cached =NULL ; - hdl->error =0 ;mutex_unlock (hdl->lock);mutex_destroy (&hdl->_lock); }
Signature · 1 line
2.50.1