[PATCH RFC] media: gspca: mars: validate controls before setting flags

Slavin Liu posted 1 patch 2 weeks ago
drivers/media/usb/gspca/mars.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH RFC] media: gspca: mars: validate controls before setting flags
Posted by Slavin Liu 2 weeks ago
Both illuminator controls can be NULL after a handler allocation
failure. Set their flags only after the existing handler error check.

Detected by static analysis and reviewed with AI-assisted source auditing.

Fixes: 98684298f9ed ("[media] gspca_mars: Convert to the control framework")
Assisted-by: LLM
Signed-off-by: Slavin Liu <bolin.liu@seu.edu.cn>
---
 drivers/media/usb/gspca/mars.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/gspca/mars.c b/drivers/media/usb/gspca/mars.c
index eb9342ee32af..e3b0af11be15 100644
--- a/drivers/media/usb/gspca/mars.c
+++ b/drivers/media/usb/gspca/mars.c
@@ -204,14 +204,14 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
 			V4L2_CID_SHARPNESS, 0, 2, 1, 1);
 	sd->illum_top = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops,
 			V4L2_CID_ILLUMINATORS_1, 0, 1, 1, 0);
-	sd->illum_top->flags |= V4L2_CTRL_FLAG_UPDATE;
 	sd->illum_bottom = v4l2_ctrl_new_std(hdl, &mars_ctrl_ops,
 			V4L2_CID_ILLUMINATORS_2, 0, 1, 1, 0);
-	sd->illum_bottom->flags |= V4L2_CTRL_FLAG_UPDATE;
 	if (hdl->error) {
 		pr_err("Could not initialize controls\n");
 		return hdl->error;
 	}
+	sd->illum_top->flags |= V4L2_CTRL_FLAG_UPDATE;
+	sd->illum_bottom->flags |= V4L2_CTRL_FLAG_UPDATE;
 	v4l2_ctrl_cluster(2, &sd->illum_top);
 	return 0;
 }