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

[media] stk1160: Try to continue with fewer transfer buffers

Many people are trying to use stk1160 on low memory devices.
Instead of failing if one allocation fails, we allow the driver
to continue working if fewer transfer buffers are available.

Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Ezequiel Garcia and committed by
Mauro Carvalho Chehab
2902fb7e 2948b0b3

+24 -4
+21 -2
drivers/media/usb/stk1160/stk1160-video.c
··· 475 475 if (!dev->isoc_ctl.transfer_buffer[i]) { 476 476 stk1160_err("cannot alloc %d bytes for tx[%d] buffer\n", 477 477 sb_size, i); 478 - goto free_i_bufs; 478 + 479 + /* Not enough transfer buffers, so just give up */ 480 + if (i < STK1160_MIN_BUFS) 481 + goto free_i_bufs; 482 + goto nomore_tx_bufs; 479 483 } 480 484 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); 481 485 ··· 510 506 } 511 507 } 512 508 513 - stk1160_dbg("urbs allocated\n"); 509 + stk1160_dbg("%d urbs allocated\n", num_bufs); 514 510 515 511 /* At last we can say we have some buffers */ 516 512 dev->isoc_ctl.num_bufs = num_bufs; 513 + 514 + return 0; 515 + 516 + nomore_tx_bufs: 517 + /* 518 + * Failed to allocate desired buffer count. However, we may have 519 + * enough to work fine, so we just free the extra urb, 520 + * store the allocated count and keep going, fingers crossed! 521 + */ 522 + usb_free_urb(dev->isoc_ctl.urb[i]); 523 + dev->isoc_ctl.urb[i] = NULL; 524 + 525 + stk1160_warn("%d urbs allocated. Trying to continue...\n", i - 1); 526 + 527 + dev->isoc_ctl.num_bufs = i - 1; 517 528 518 529 return 0; 519 530
+3 -2
drivers/media/usb/stk1160/stk1160.h
··· 30 30 #define STK1160_VERSION "0.9.5" 31 31 #define STK1160_VERSION_NUM 0x000905 32 32 33 - /* TODO: Decide on number of packets for each buffer */ 33 + /* Decide on number of packets for each buffer */ 34 34 #define STK1160_NUM_PACKETS 64 35 35 36 36 /* Number of buffers for isoc transfers */ 37 - #define STK1160_NUM_BUFS 16 /* TODO */ 37 + #define STK1160_NUM_BUFS 16 38 + #define STK1160_MIN_BUFS 1 38 39 39 40 /* TODO: This endpoint address should be retrieved */ 40 41 #define STK1160_EP_VIDEO 0x82