提交 38284ba3 编写于 作者: T Thierry MERLE 提交者: Mauro Carvalho Chehab

V4L/DVB (4970): Usbvision memory fixes

- fix decompression buffer allocation not done at first driver open
- simplification of USB sbuf allocation (use of usb_buffer_alloc)
- replaced vmalloc by vmalloc_32 (for homogeneity)
- add of saa7111 (i2cAddr=0x48) detection printout in attach_inform
Signed-off-by: NThierry MERLE <thierry.merle@free.fr>
Signed-off-by: NMauro Carvalho Chehab <mchehab@infradead.org>
上级 3a4456a0
...@@ -374,7 +374,7 @@ static void scratch_reset(struct usb_usbvision *usbvision) ...@@ -374,7 +374,7 @@ static void scratch_reset(struct usb_usbvision *usbvision)
int usbvision_scratch_alloc(struct usb_usbvision *usbvision) int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
{ {
usbvision->scratch = vmalloc(scratch_buf_size); usbvision->scratch = vmalloc_32(scratch_buf_size);
scratch_reset(usbvision); scratch_reset(usbvision);
if(usbvision->scratch == NULL) { if(usbvision->scratch == NULL) {
err("%s: unable to allocate %d bytes for scratch", err("%s: unable to allocate %d bytes for scratch",
...@@ -485,7 +485,7 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision, ...@@ -485,7 +485,7 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
int usbvision_decompress_alloc(struct usb_usbvision *usbvision) int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
{ {
int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
usbvision->IntraFrameBuffer = vmalloc(IFB_size); usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
if (usbvision->IntraFrameBuffer == NULL) { if (usbvision->IntraFrameBuffer == NULL) {
err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size); err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size);
return -ENOMEM; return -ENOMEM;
...@@ -2204,6 +2204,7 @@ int usbvision_power_on(struct usb_usbvision *usbvision) ...@@ -2204,6 +2204,7 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
usbvision_write_reg(usbvision, USBVISION_PWR_REG, usbvision_write_reg(usbvision, USBVISION_PWR_REG,
USBVISION_SSPND_EN | USBVISION_RES2); USBVISION_SSPND_EN | USBVISION_RES2);
usbvision_write_reg(usbvision, USBVISION_PWR_REG, usbvision_write_reg(usbvision, USBVISION_PWR_REG,
USBVISION_SSPND_EN | USBVISION_PWR_VID); USBVISION_SSPND_EN | USBVISION_PWR_VID);
errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
...@@ -2351,40 +2352,6 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format) ...@@ -2351,40 +2352,6 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format)
return USBVISION_IS_OPERATIONAL(usbvision); return USBVISION_IS_OPERATIONAL(usbvision);
} }
int usbvision_sbuf_alloc(struct usb_usbvision *usbvision)
{
int i, errCode = 0;
const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
/* Clean pointers so we know if we allocated something */
for (i = 0; i < USBVISION_NUMSBUF; i++)
usbvision->sbuf[i].data = NULL;
for (i = 0; i < USBVISION_NUMSBUF; i++) {
usbvision->sbuf[i].data = kzalloc(sb_size, GFP_KERNEL);
if (usbvision->sbuf[i].data == NULL) {
err("%s: unable to allocate %d bytes for sbuf", __FUNCTION__, sb_size);
errCode = -ENOMEM;
break;
}
}
return errCode;
}
void usbvision_sbuf_free(struct usb_usbvision *usbvision)
{
int i;
for (i = 0; i < USBVISION_NUMSBUF; i++) {
if (usbvision->sbuf[i].data != NULL) {
kfree(usbvision->sbuf[i].data);
usbvision->sbuf[i].data = NULL;
}
}
}
/* /*
* usbvision_init_isoc() * usbvision_init_isoc()
* *
...@@ -2393,6 +2360,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision) ...@@ -2393,6 +2360,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
{ {
struct usb_device *dev = usbvision->dev; struct usb_device *dev = usbvision->dev;
int bufIdx, errCode, regValue; int bufIdx, errCode, regValue;
const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
if (!USBVISION_IS_OPERATIONAL(usbvision)) if (!USBVISION_IS_OPERATIONAL(usbvision))
return -EFAULT; return -EFAULT;
...@@ -2428,6 +2396,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision) ...@@ -2428,6 +2396,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
return -ENOMEM; return -ENOMEM;
} }
usbvision->sbuf[bufIdx].urb = urb; usbvision->sbuf[bufIdx].urb = urb;
usbvision->sbuf[bufIdx].data = usb_buffer_alloc(usbvision->dev, sb_size, GFP_KERNEL,&urb->transfer_dma);
urb->dev = dev; urb->dev = dev;
urb->context = usbvision; urb->context = usbvision;
urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
...@@ -2469,6 +2438,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision) ...@@ -2469,6 +2438,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
void usbvision_stop_isoc(struct usb_usbvision *usbvision) void usbvision_stop_isoc(struct usb_usbvision *usbvision)
{ {
int bufIdx, errCode, regValue; int bufIdx, errCode, regValue;
const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL)) if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL))
return; return;
...@@ -2476,6 +2446,12 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision) ...@@ -2476,6 +2446,12 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
/* Unschedule all of the iso td's */ /* Unschedule all of the iso td's */
for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
usb_kill_urb(usbvision->sbuf[bufIdx].urb); usb_kill_urb(usbvision->sbuf[bufIdx].urb);
if (usbvision->sbuf[bufIdx].data){
usb_buffer_free(usbvision->dev,
sb_size,
usbvision->sbuf[bufIdx].data,
usbvision->sbuf[bufIdx].urb->transfer_dma);
}
usb_free_urb(usbvision->sbuf[bufIdx].urb); usb_free_urb(usbvision->sbuf[bufIdx].urb);
usbvision->sbuf[bufIdx].urb = NULL; usbvision->sbuf[bufIdx].urb = NULL;
} }
......
...@@ -319,6 +319,9 @@ static int attach_inform(struct i2c_client *client) ...@@ -319,6 +319,9 @@ static int attach_inform(struct i2c_client *client)
case 0x4a: case 0x4a:
PDEBUG(DBG_I2C,"attach_inform: saa7113 detected."); PDEBUG(DBG_I2C,"attach_inform: saa7113 detected.");
break; break;
case 0x48:
PDEBUG(DBG_I2C,"attach_inform: saa7111 detected.");
break;
case 0xa0: case 0xa0:
PDEBUG(DBG_I2C,"attach_inform: eeprom detected."); PDEBUG(DBG_I2C,"attach_inform: eeprom detected.");
break; break;
......
...@@ -353,20 +353,15 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file) ...@@ -353,20 +353,15 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
if(!errCode) { if(!errCode) {
/* Allocate memory for the scratch ring buffer */ /* Allocate memory for the scratch ring buffer */
errCode = usbvision_scratch_alloc(usbvision); errCode = usbvision_scratch_alloc(usbvision);
if(!errCode) { if ((!errCode) && (isocMode==ISOC_MODE_COMPRESS)) {
/* Allocate memory for the USB S buffers */ /* Allocate intermediate decompression buffers only if needed */
errCode = usbvision_sbuf_alloc(usbvision); errCode = usbvision_decompress_alloc(usbvision);
if ((!errCode) && (usbvision->isocMode==ISOC_MODE_COMPRESS)) {
/* Allocate intermediate decompression buffers only if needed */
errCode = usbvision_decompress_alloc(usbvision);
}
} }
} }
if (errCode) { if (errCode) {
/* Deallocate all buffers if trouble */ /* Deallocate all buffers if trouble */
usbvision_frames_free(usbvision); usbvision_frames_free(usbvision);
usbvision_scratch_free(usbvision); usbvision_scratch_free(usbvision);
usbvision_sbuf_free(usbvision);
usbvision_decompress_free(usbvision); usbvision_decompress_free(usbvision);
} }
} }
...@@ -437,9 +432,8 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file) ...@@ -437,9 +432,8 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
usbvision_stop_isoc(usbvision); usbvision_stop_isoc(usbvision);
usbvision_decompress_free(usbvision); usbvision_decompress_free(usbvision);
usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); usbvision_frames_free(usbvision);
usbvision_scratch_free(usbvision); usbvision_scratch_free(usbvision);
usbvision_sbuf_free(usbvision);
usbvision->user--; usbvision->user--;
......
...@@ -495,8 +495,6 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision); ...@@ -495,8 +495,6 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision);
void usbvision_frames_free(struct usb_usbvision *usbvision); void usbvision_frames_free(struct usb_usbvision *usbvision);
int usbvision_scratch_alloc(struct usb_usbvision *usbvision); int usbvision_scratch_alloc(struct usb_usbvision *usbvision);
void usbvision_scratch_free(struct usb_usbvision *usbvision); void usbvision_scratch_free(struct usb_usbvision *usbvision);
int usbvision_sbuf_alloc(struct usb_usbvision *usbvision);
void usbvision_sbuf_free(struct usb_usbvision *usbvision);
int usbvision_decompress_alloc(struct usb_usbvision *usbvision); int usbvision_decompress_alloc(struct usb_usbvision *usbvision);
void usbvision_decompress_free(struct usb_usbvision *usbvision); void usbvision_decompress_free(struct usb_usbvision *usbvision);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册