Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Thierry MERLE <thierry.merle@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

authored by

Thierry MERLE and committed by
Mauro Carvalho Chehab
38284ba3 3a4456a0

+19 -48
+12 -36
drivers/media/video/usbvision/usbvision-core.c
··· 374 374 375 375 int usbvision_scratch_alloc(struct usb_usbvision *usbvision) 376 376 { 377 - usbvision->scratch = vmalloc(scratch_buf_size); 377 + usbvision->scratch = vmalloc_32(scratch_buf_size); 378 378 scratch_reset(usbvision); 379 379 if(usbvision->scratch == NULL) { 380 380 err("%s: unable to allocate %d bytes for scratch", ··· 485 485 int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 486 486 { 487 487 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 488 - usbvision->IntraFrameBuffer = vmalloc(IFB_size); 488 + usbvision->IntraFrameBuffer = vmalloc_32(IFB_size); 489 489 if (usbvision->IntraFrameBuffer == NULL) { 490 490 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size); 491 491 return -ENOMEM; ··· 2204 2204 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2205 2205 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2206 2206 USBVISION_SSPND_EN | USBVISION_RES2); 2207 + 2207 2208 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2208 2209 USBVISION_SSPND_EN | USBVISION_PWR_VID); 2209 2210 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, ··· 2352 2351 return USBVISION_IS_OPERATIONAL(usbvision); 2353 2352 } 2354 2353 2355 - 2356 - int usbvision_sbuf_alloc(struct usb_usbvision *usbvision) 2357 - { 2358 - int i, errCode = 0; 2359 - const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE; 2360 - 2361 - /* Clean pointers so we know if we allocated something */ 2362 - for (i = 0; i < USBVISION_NUMSBUF; i++) 2363 - usbvision->sbuf[i].data = NULL; 2364 - 2365 - for (i = 0; i < USBVISION_NUMSBUF; i++) { 2366 - usbvision->sbuf[i].data = kzalloc(sb_size, GFP_KERNEL); 2367 - if (usbvision->sbuf[i].data == NULL) { 2368 - err("%s: unable to allocate %d bytes for sbuf", __FUNCTION__, sb_size); 2369 - errCode = -ENOMEM; 2370 - break; 2371 - } 2372 - } 2373 - return errCode; 2374 - } 2375 - 2376 - 2377 - void usbvision_sbuf_free(struct usb_usbvision *usbvision) 2378 - { 2379 - int i; 2380 - 2381 - for (i = 0; i < USBVISION_NUMSBUF; i++) { 2382 - if (usbvision->sbuf[i].data != NULL) { 2383 - kfree(usbvision->sbuf[i].data); 2384 - usbvision->sbuf[i].data = NULL; 2385 - } 2386 - } 2387 - } 2388 - 2389 2354 /* 2390 2355 * usbvision_init_isoc() 2391 2356 * ··· 2360 2393 { 2361 2394 struct usb_device *dev = usbvision->dev; 2362 2395 int bufIdx, errCode, regValue; 2396 + const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE; 2363 2397 2364 2398 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2365 2399 return -EFAULT; ··· 2396 2428 return -ENOMEM; 2397 2429 } 2398 2430 usbvision->sbuf[bufIdx].urb = urb; 2431 + usbvision->sbuf[bufIdx].data = usb_buffer_alloc(usbvision->dev, sb_size, GFP_KERNEL,&urb->transfer_dma); 2399 2432 urb->dev = dev; 2400 2433 urb->context = usbvision; 2401 2434 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); ··· 2438 2469 void usbvision_stop_isoc(struct usb_usbvision *usbvision) 2439 2470 { 2440 2471 int bufIdx, errCode, regValue; 2472 + const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE; 2441 2473 2442 2474 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL)) 2443 2475 return; ··· 2446 2476 /* Unschedule all of the iso td's */ 2447 2477 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2448 2478 usb_kill_urb(usbvision->sbuf[bufIdx].urb); 2479 + if (usbvision->sbuf[bufIdx].data){ 2480 + usb_buffer_free(usbvision->dev, 2481 + sb_size, 2482 + usbvision->sbuf[bufIdx].data, 2483 + usbvision->sbuf[bufIdx].urb->transfer_dma); 2484 + } 2449 2485 usb_free_urb(usbvision->sbuf[bufIdx].urb); 2450 2486 usbvision->sbuf[bufIdx].urb = NULL; 2451 2487 }
+3
drivers/media/video/usbvision/usbvision-i2c.c
··· 319 319 case 0x4a: 320 320 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected."); 321 321 break; 322 + case 0x48: 323 + PDEBUG(DBG_I2C,"attach_inform: saa7111 detected."); 324 + break; 322 325 case 0xa0: 323 326 PDEBUG(DBG_I2C,"attach_inform: eeprom detected."); 324 327 break;
+4 -10
drivers/media/video/usbvision/usbvision-video.c
··· 353 353 if(!errCode) { 354 354 /* Allocate memory for the scratch ring buffer */ 355 355 errCode = usbvision_scratch_alloc(usbvision); 356 - if(!errCode) { 357 - /* Allocate memory for the USB S buffers */ 358 - errCode = usbvision_sbuf_alloc(usbvision); 359 - if ((!errCode) && (usbvision->isocMode==ISOC_MODE_COMPRESS)) { 360 - /* Allocate intermediate decompression buffers only if needed */ 361 - errCode = usbvision_decompress_alloc(usbvision); 362 - } 356 + if ((!errCode) && (isocMode==ISOC_MODE_COMPRESS)) { 357 + /* Allocate intermediate decompression buffers only if needed */ 358 + errCode = usbvision_decompress_alloc(usbvision); 363 359 } 364 360 } 365 361 if (errCode) { 366 362 /* Deallocate all buffers if trouble */ 367 363 usbvision_frames_free(usbvision); 368 364 usbvision_scratch_free(usbvision); 369 - usbvision_sbuf_free(usbvision); 370 365 usbvision_decompress_free(usbvision); 371 366 } 372 367 } ··· 432 437 usbvision_stop_isoc(usbvision); 433 438 434 439 usbvision_decompress_free(usbvision); 435 - usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 440 + usbvision_frames_free(usbvision); 436 441 usbvision_scratch_free(usbvision); 437 - usbvision_sbuf_free(usbvision); 438 442 439 443 usbvision->user--; 440 444
-2
drivers/media/video/usbvision/usbvision.h
··· 495 495 void usbvision_frames_free(struct usb_usbvision *usbvision); 496 496 int usbvision_scratch_alloc(struct usb_usbvision *usbvision); 497 497 void usbvision_scratch_free(struct usb_usbvision *usbvision); 498 - int usbvision_sbuf_alloc(struct usb_usbvision *usbvision); 499 - void usbvision_sbuf_free(struct usb_usbvision *usbvision); 500 498 int usbvision_decompress_alloc(struct usb_usbvision *usbvision); 501 499 void usbvision_decompress_free(struct usb_usbvision *usbvision); 502 500