Skip to contentSkip to conversation

media: v4l2-ctrls-api: add find_ref_lock()'s result check in prepare_ext_ctrls()

RFC PATCH In review Sergey Shtylyov 1 participant 2 messages Jan 22 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 media: v4l2-ctrls-api: add find_ref_lock()'s result check in prepare_ext_ctrls()

In prepare_ext_ctrls(), find_ref_lock() is called twice from the 1st *for* loop but its result is only checked after the 1st call. I'm not positive that the 2nd call can't ever fail, so let's add a NULL check after it as well...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
The patch is against the next branch of the linuxtv.org/media.git repo...

 drivers/media/v4l2-core/v4l2-ctrls-api.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls-api.c +7 -1
index 0078a04c5445..238695a7555e 100644
@@ -286,8 +286,14 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
 
 		if (ctrl->cluster[0]->ncontrols > 1)
 			have_clusters = true;
-		if (ctrl->cluster[0] != ctrl)
+		if (ctrl->cluster[0] != ctrl) {
 			ref = find_ref_lock(hdl, ctrl->cluster[0]->id);
+			if (!ref) {
+				dprintk(vdev, "cannot find control id 0x%x\n",
+					ctrl->cluster[0]->id);
+				return -EINVAL;
+			}
+		}
 		if (ctrl->is_dyn_array) {
 			unsigned int max_size = ctrl->dims[0] * ctrl->elem_size;
 			unsigned int tot_size = ctrl->elem_size;
Signature · 1 line
2.52.0
#1 lore raw

Hello!

Oops, extra space went unnoticed in the subject. Do I need to resend?

MBR, Sergey