Commit 06574184 authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Mauro Carvalho Chehab

[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: default avatarEzequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 18ad8965
...@@ -462,8 +462,7 @@ int stk1160_alloc_isoc(struct stk1160 *dev) ...@@ -462,8 +462,7 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
urb = usb_alloc_urb(max_packets, GFP_KERNEL); urb = usb_alloc_urb(max_packets, GFP_KERNEL);
if (!urb) { if (!urb) {
stk1160_err("cannot alloc urb[%d]\n", i); stk1160_err("cannot alloc urb[%d]\n", i);
stk1160_uninit_isoc(dev); goto free_i_bufs;
return -ENOMEM;
} }
dev->isoc_ctl.urb[i] = urb; dev->isoc_ctl.urb[i] = urb;
...@@ -474,10 +473,9 @@ int stk1160_alloc_isoc(struct stk1160 *dev) ...@@ -474,10 +473,9 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
dev->isoc_ctl.transfer_buffer[i] = kmalloc(sb_size, GFP_KERNEL); dev->isoc_ctl.transfer_buffer[i] = kmalloc(sb_size, GFP_KERNEL);
#endif #endif
if (!dev->isoc_ctl.transfer_buffer[i]) { if (!dev->isoc_ctl.transfer_buffer[i]) {
stk1160_err("cannot alloc %d bytes for tx buffer\n", stk1160_err("cannot alloc %d bytes for tx[%d] buffer\n",
sb_size); sb_size, i);
stk1160_uninit_isoc(dev); goto free_i_bufs;
return -ENOMEM;
} }
memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
...@@ -514,5 +512,11 @@ int stk1160_alloc_isoc(struct stk1160 *dev) ...@@ -514,5 +512,11 @@ int stk1160_alloc_isoc(struct stk1160 *dev)
dev->isoc_ctl.num_bufs = num_bufs; dev->isoc_ctl.num_bufs = num_bufs;
return 0; return 0;
free_i_bufs:
/* Save the allocated buffers so far, so we can properly free them */
dev->isoc_ctl.num_bufs = i+1;
stk1160_free_isoc(dev);
return -ENOMEM;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment