Skip to contentSkip to conversation

gspca: fix vidioc_s_jpegcomp locking

PATCH Jim Paris 2 participants 4 messages Dec 9, 2008 – Dec 10, 2008 Media (V4L/DVB)

lore
Share & tools
lore

Jim Paris

author
#0 lore raw

This locking looked wrong.

-jim

--

gspca: fix vidioc_s_jpegcomp locking

linux/drivers/media/video/gspca/gspca.c +2 -2
diff -r b50857fea6df linux/drivers/media/video/gspca/gspca.c
@@ -1320,10 +1320,10 @@
 	struct gspca_dev *gspca_dev = priv;
 	int ret;
 
+	if (!gspca_dev->sd_desc->set_jcomp)
+		return -EINVAL;
 	if (mutex_lock_interruptible(&gspca_dev->usb_lock))
 		return -ERESTARTSYS;
-	if (!gspca_dev->sd_desc->set_jcomp)
-		return -EINVAL;
 	ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp);
 	mutex_unlock(&gspca_dev->usb_lock);
 	return ret;

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#1 lore raw
Quoted 2 lines · Jim Paris

This locking looked wrong.

Hi,

I appreciate the effort, but please do not send patches just because something looks wrong. The original code is perfectly fine. It check if the sub driver supports set_jcomp at all, this check does not need locking.

Regards,

Hans

Quoted 26 lines

-jim

--

gspca: fix vidioc_s_jpegcomp locking

diff -r b50857fea6df linux/drivers/media/video/gspca/gspca.c

linux/drivers/media/video/gspca/gspca.c +2 -3
@@ -1320,10 +1320,10 @@
 	struct gspca_dev *gspca_dev = priv;
 	int ret;
 
+	if (!gspca_dev->sd_desc->set_jcomp)
+		return -EINVAL;
 	if (mutex_lock_interruptible(&gspca_dev->usb_lock))
 		return -ERESTARTSYS;
-	if (!gspca_dev->sd_desc->set_jcomp)
-		return -EINVAL;
 	ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp);
 	mutex_unlock(&gspca_dev->usb_lock);
 	return ret;
 
--
Quoted 4 lines

video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

author
#2 lore raw
Quoted 10 lines · Hans de Goede
Quoted 2 lines · Jim Paris

This locking looked wrong.

Hi,

I appreciate the effort, but please do not send patches just because something looks wrong. The original code is perfectly fine. It check if the sub driver supports set_jcomp at all, this check does not need locking.

Well, the patch was a request for comments. But please double-check. In the current code, if set_jcomp is NULL, the lock is taken but never released.

I agree that the check does not need locking, which is why my change moved the check outside the lock.

-jim

Quoted 4 lines
Quoted 4 lines

gspca: fix vidioc_s_jpegcomp locking

Quoted 15 lines
Quoted 5 lines

diff -r b50857fea6df linux/drivers/media/video/gspca/gspca.c

linux/drivers/media/video/gspca/gspca.c +0 -0
@@ -1320,10 +1320,10 @@
 	struct gspca_dev *gspca_dev = priv;

linux/drivers/media/video/gspca/gspca.c line 1328

Quoted 10 lines
linux/drivers/media/video/gspca/gspca.c +2 -2
 	int ret;
+	if (!gspca_dev->sd_desc->set_jcomp)
+		return -EINVAL;
 	if (mutex_lock_interruptible(&gspca_dev->usb_lock))
 		return -ERESTARTSYS;
-	if (!gspca_dev->sd_desc->set_jcomp)
-		return -EINVAL;
 	ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp);
 	mutex_unlock(&gspca_dev->usb_lock);
 	return ret;

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#3 lore raw
Quoted 6 lines · Jim Paris
Quoted 5 lines · Hans de Goede
Quoted 2 lines · Jim Paris

This locking looked wrong.

Hi,

Quoted 9 lines
Quoted 1 line

I appreciate the effort, but please do not send patches just because something looks wrong. The original code is perfectly fine. It check if the sub driver supports set_jcomp at all, this check does not need locking.

Well, the patch was a request for comments. But please double-check. In the current code, if set_jcomp is NULL, the lock is taken but never released.

I agree that the check does not need locking, which is why my change moved the check outside the lock.

Blergh, sorry I completely misread your patch, somehow reversing what it did in my head.

You are completely right, the original code is wrong, and this patch needs to be applied.

Sorry!

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list