Skip to contentSkip to conversation

mem2mem_testdev: unlock and return error code properly

PATCH In review Dan Carpenter 2 participants 2 messages Aug 14, 2012 – Aug 17, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mem2mem_testdev: unlock and return error code properly

We recently added locking to this function, but there was an error path which accidentally returned holding a lock. Also we returned zero on failure on some paths instead of the error code.

---
Applies to linux-next.

drivers/media/video/mem2mem_testdev.c +3 -4
index 0aa8c47..0b496f3 100644
@@ -911,10 +911,9 @@ static int m2mtest_open(struct file *file)
 	v4l2_ctrl_new_custom(hdl, &m2mtest_ctrl_trans_time_msec, NULL);
 	v4l2_ctrl_new_custom(hdl, &m2mtest_ctrl_trans_num_bufs, NULL);
 	if (hdl->error) {
-		int err = hdl->error;
-
+		rc = hdl->error;
 		v4l2_ctrl_handler_free(hdl);
-		return err;
+		goto open_unlock;
 	}
 	ctx->fh.ctrl_handler = hdl;
 	v4l2_ctrl_handler_setup(hdl);
@@ -946,7 +945,7 @@ static int m2mtest_open(struct file *file)
 
 open_unlock:
 	mutex_unlock(&dev->dev_mutex);
-	return 0;
+	return rc;
 }
 
 static int m2mtest_release(struct file *file)
Acked-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 5 lines · Dan Carpenter

We recently added locking to this function, but there was an error path which accidentally returned holding a lock. Also we returned zero on failure on some paths instead of the error code.

Thanks for the patch!

Quoted 21 lines

---
Applies to linux-next.

drivers/media/video/mem2mem_testdev.c +2 -3
index 0aa8c47..0b496f3 100644
@@ -911,10 +911,9 @@ static int m2mtest_open(struct file *file)
 	v4l2_ctrl_new_custom(hdl, &m2mtest_ctrl_trans_time_msec, NULL);
 	v4l2_ctrl_new_custom(hdl, &m2mtest_ctrl_trans_num_bufs, NULL);
 	if (hdl->error) {
-		int err = hdl->error;
-
+		rc = hdl->error;
 		v4l2_ctrl_handler_free(hdl);
-		return err;
+		goto open_unlock;
 	}
 	ctx->fh.ctrl_handler = hdl;
 	v4l2_ctrl_handler_setup(hdl);

drivers/media/video/mem2mem_testdev.c static int m2mtest_open(struct file *file) · line 951

Quoted 8 lines
drivers/media/video/mem2mem_testdev.c +1 -1
@@ -946,7 +945,7 @@ static int m2mtest_open(struct file *file)
 
 open_unlock:
 	mutex_unlock(&dev->dev_mutex);
-	return 0;
+	return rc;
 }
 
 static int m2mtest_release(struct file *file)

Best regards

Signature · 2 lines
Marek Szyprowski
Samsung Poland R&D Center