Skip to contentSkip to conversation

V4L/DVB:usbvideo:don't use part of buffer for USB transfer #3

RESEND/PATCH Laurent Pinchart 1 participant 1 message Sep 15, 2008 1 message not in the archive Media (V4L/DVB)

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi,

sorry for the late reply, I was on holidays.

Quoted 8 lines · On Monday 15 September 2008, [email protected] wrote:

From: Ming Lei <[email protected]>

The status[] is part of uvc_device structure. We can't make sure the address of status is at a cache-line boundary in all archs,so status[] might share a cache-line with some fields in uvc_structure. This can lead to some cache coherence issues(http://lwn.net/Articles/2265/). Use dynamically allocated buffer instead.

Thanks for catching this. Comments below.

Quoted 20 lines
---
 drivers/media/video/uvc/uvc_driver.c |    7 +++++++
 drivers/media/video/uvc/uvc_status.c |    2 +-
 drivers/media/video/uvc/uvcvideo.h   |    4 +++-
 3 files changed, 11 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvc_driver.c index 7e10203..fbb6bfb 100644

drivers/media/video/uvc/uvc_driver.c +1 -0
@@ -1529,6 +1529,7 @@ void uvc_delete(struct kref *kref)
 		kfree(streaming);
 	}
 
+	kfree(dev->status);
 	kfree(dev);
 }
 

drivers/media/video/uvc/uvc_driver.c static int uvc_probe(struct usb_interface *intf, · line 1564

Quoted 9 lines
drivers/media/video/uvc/uvc_driver.c +6 -0
@@ -1555,6 +1556,12 @@ static int uvc_probe(struct usb_interface *intf,
 	INIT_LIST_HEAD(&dev->streaming);
 	kref_init(&dev->kref);
 
+	dev->status = kzalloc(UVC_MAX_STATUS_SIZE, GFP_KERNEL);
+	if (dev->status == NULL) {
+		kfree(dev);
+		return -ENOMEM;
+	}
+

To keep all status-related code in a single place, please allocate the status buffer in uvc_status_init (and free it in uvc_status_cleanup).

Quoted 30 lines
drivers/media/video/uvc/uvc_driver.c +0 -0
 	dev->udev = usb_get_dev(udev);
 	dev->intf = usb_get_intf(intf);
 	dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvc_status.c index 75e678a..9f4f987 100644

drivers/media/video/uvc/uvc_status.c +1 -1
@@ -192,7 +192,7 @@ int uvc_status_init(struct uvc_device *dev)
 		interval = fls(interval) - 1;
 
 	usb_fill_int_urb(dev->int_urb, dev->udev, pipe,
-		dev->status, sizeof dev->status, uvc_status_complete,
+		dev->status, UVC_MAX_STATUS_SIZE, uvc_status_complete,
 		dev, interval);
 
 	return usb_submit_urb(dev->int_urb, GFP_KERNEL);
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvcvideo.h index bafe340..9a6bc1a 100644

drivers/media/video/uvc/uvcvideo.h +2 -0
@@ -303,6 +303,8 @@ struct uvc_xu_control {
 #define UVC_MAX_FRAME_SIZE	(16*1024*1024)
 /* Maximum number of video buffers. */
 #define UVC_MAX_VIDEO_BUFFERS	32
+/* Maximum status buffer size in bytes of interrupt URB. */
+#define UVC_MAX_STATUS_SIZE	16
 
 #define UVC_CTRL_CONTROL_TIMEOUT	300
 #define UVC_CTRL_STREAMING_TIMEOUT	1000

drivers/media/video/uvc/uvcvideo.h struct uvc_device { · line 642

Quoted 8 lines
drivers/media/video/uvc/uvcvideo.h +1 -1
@@ -634,7 +636,7 @@ struct uvc_device {
 	/* Status Interrupt Endpoint */
 	struct usb_host_endpoint *int_ep;
 	struct urb *int_urb;
-	__u8 status[16];
+	__u8 *status;
 	struct input_dev *input;
 
 	/* Video Streaming interfaces */

Otherwise the patch looks good.

Best regards,

Laurent Pinchart

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