Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8295d99e authored by Jean-Francois Moine's avatar Jean-Francois Moine Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (8829): gspca: Have a clean kmalloc-ated buffer for USB exchanges.



The USB buffer may be used for DMA and there may be a caching problem
if the buffer is part of the device structure.
Thanks to Alan Stern.

Signed-off-by: default avatarJean-Francois Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 91de65ac
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
	struct usb_device *dev = gspca_dev->dev;

#ifdef GSPCA_DEBUG
	if (len > sizeof gspca_dev->usb_buf) {
	if (len > USB_BUF_SZ) {
		err("reg_r: buffer overflow");
		return;
	}
@@ -164,7 +164,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
	struct usb_device *dev = gspca_dev->dev;

#ifdef GSPCA_DEBUG
	if (len > sizeof gspca_dev->usb_buf) {
	if (len > USB_BUF_SZ) {
		err("reg_w: buffer overflow");
		return;
	}
+2 −2
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ static void reg_r(struct gspca_dev *gspca_dev,
	struct usb_device *dev = gspca_dev->dev;

#ifdef GSPCA_DEBUG
	if (len > sizeof gspca_dev->usb_buf) {
	if (len > USB_BUF_SZ) {
		err("reg_r: buffer overflow");
		return;
	}
@@ -273,7 +273,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
	struct usb_device *dev = gspca_dev->dev;

#ifdef GSPCA_DEBUG
	if (len > sizeof gspca_dev->usb_buf) {
	if (len > USB_BUF_SZ) {
		err("reg_w: buffer overflow");
		return;
	}
+8 −0
Original line number Diff line number Diff line
@@ -1731,6 +1731,12 @@ int gspca_dev_probe(struct usb_interface *intf,
		err("couldn't kzalloc gspca struct");
		return -EIO;
	}
	gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL);
	if (!gspca_dev->usb_buf) {
		err("out of memory");
		ret = -EIO;
		goto out;
	}
	gspca_dev->dev = dev;
	gspca_dev->iface = interface->bInterfaceNumber;
	gspca_dev->nbalt = intf->num_altsetting;
@@ -1774,6 +1780,7 @@ int gspca_dev_probe(struct usb_interface *intf,
	PDEBUG(D_PROBE, "probe ok");
	return 0;
out:
	kfree(gspca_dev->usb_buf);
	kfree(gspca_dev);
	return ret;
}
@@ -1806,6 +1813,7 @@ void gspca_disconnect(struct usb_interface *intf)
/* We don't want people trying to open up the device */
	video_unregister_device(&gspca_dev->vdev);
/* Free the memory */
	kfree(gspca_dev->usb_buf);
	kfree(gspca_dev);
	PDEBUG(D_PROBE, "disconnect complete");
}
+2 −1
Original line number Diff line number Diff line
@@ -127,7 +127,8 @@ struct gspca_dev {
	const struct sd_desc *sd_desc;		/* subdriver description */
	unsigned ctrl_dis;		/* disabled controls (bit map) */

	__u8 usb_buf[8];			/* buffer for USB exchanges */
#define USB_BUF_SZ 64
	__u8 *usb_buf;				/* buffer for USB exchanges */
	struct urb *urb[MAX_NURBS];

	__u8 *frbuf;				/* buffer for nframes */
+1 −20
Original line number Diff line number Diff line
@@ -100,22 +100,6 @@ static int reg_w(struct gspca_dev *gspca_dev,
	return rc;
}

static int reg_w_buf(struct gspca_dev *gspca_dev,
			__u16 index, __u8 *buf, int len)
{
	int rc;

	rc = usb_control_msg(gspca_dev->dev,
			 usb_sndbulkpipe(gspca_dev->dev, 4),
			 0x12,
			 0xc8,		/* ?? */
			 0,		/* value */
			 index, buf, len, 500);
	if (rc < 0)
		PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc);
	return rc;
}

static void bulk_w(struct gspca_dev *gspca_dev,
		   __u16 *pch,
		   __u16 Address)
@@ -175,7 +159,6 @@ static void sd_start(struct gspca_dev *gspca_dev)
	/*
	   Initialize the MR97113 chip register
	 */
	data = kmalloc(16, GFP_KERNEL);
	data[0] = 0x00;		/* address */
	data[1] = 0x0c | 0x01;	/* reg 0 */
	data[2] = 0x01;		/* reg 1 */
@@ -195,12 +178,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
	data[10] = 0x5d;	/* reg 9, I2C device address
				 *	[for PAS5101 (0x40)] [for MI (0x5d)] */

	err_code = reg_w_buf(gspca_dev, data[0], data, 11);
	kfree(data);
	err_code = reg_w(gspca_dev, data[0], 11);
	if (err_code < 0)
		return;

	data = gspca_dev->usb_buf;
	data[0] = 0x23;		/* address */
	data[1] = 0x09;		/* reg 35, append frame header */

Loading