Skip to content

Commit 0657418

Browse files
ezequielgarciaMauro Carvalho Chehab
authored andcommitted
[media] stk1160: Handle urb allocation failure condition properly
When an urb buffer can't be allocated, the currently allocated buffer count must be saved so they can properly released. Moreover, it's sufficient to call stk1160_free_isoc to have all urb buffers released. Signed-off-by: Ezequiel Garcia <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 18ad896 commit 0657418

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/media/usb/stk1160/stk1160-video.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
462462
urb = usb_alloc_urb(max_packets, GFP_KERNEL);
463463
if (!urb) {
464464
stk1160_err("cannot alloc urb[%d]\n", i);
465-
stk1160_uninit_isoc(dev);
466-
return -ENOMEM;
465+
goto free_i_bufs;
467466
}
468467
dev->isoc_ctl.urb[i] = urb;
469468

@@ -474,10 +473,9 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
474473
dev->isoc_ctl.transfer_buffer[i] = kmalloc(sb_size, GFP_KERNEL);
475474
#endif
476475
if (!dev->isoc_ctl.transfer_buffer[i]) {
477-
stk1160_err("cannot alloc %d bytes for tx buffer\n",
478-
sb_size);
479-
stk1160_uninit_isoc(dev);
480-
return -ENOMEM;
476+
stk1160_err("cannot alloc %d bytes for tx[%d] buffer\n",
477+
sb_size, i);
478+
goto free_i_bufs;
481479
}
482480
memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
483481

@@ -514,5 +512,11 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
514512
dev->isoc_ctl.num_bufs = num_bufs;
515513

516514
return 0;
515+
516+
free_i_bufs:
517+
/* Save the allocated buffers so far, so we can properly free them */
518+
dev->isoc_ctl.num_bufs = i+1;
519+
stk1160_free_isoc(dev);
520+
return -ENOMEM;
517521
}
518522

0 commit comments

Comments
 (0)