udlfb: handle allocation failure
Allocations larger than PAGE_ALLOC_COSTLY_ORDER are unreliable and they may fail anytime. This patch fixes the udlfb driver so that when a large alloactions fails, it tries to do multiple smaller allocations. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
This commit is contained in:
parent
bb24153a3f
commit
080fb5240b
|
@ -1843,17 +1843,22 @@ static void dlfb_free_urb_list(struct dlfb_data *dlfb)
|
||||||
|
|
||||||
static int dlfb_alloc_urb_list(struct dlfb_data *dlfb, int count, size_t size)
|
static int dlfb_alloc_urb_list(struct dlfb_data *dlfb, int count, size_t size)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
struct urb_node *unode;
|
struct urb_node *unode;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
size_t wanted_size = count * size;
|
||||||
|
|
||||||
spin_lock_init(&dlfb->urbs.lock);
|
spin_lock_init(&dlfb->urbs.lock);
|
||||||
|
|
||||||
|
retry:
|
||||||
dlfb->urbs.size = size;
|
dlfb->urbs.size = size;
|
||||||
INIT_LIST_HEAD(&dlfb->urbs.list);
|
INIT_LIST_HEAD(&dlfb->urbs.list);
|
||||||
|
|
||||||
while (i < count) {
|
sema_init(&dlfb->urbs.limit_sem, 0);
|
||||||
|
dlfb->urbs.count = 0;
|
||||||
|
dlfb->urbs.available = 0;
|
||||||
|
|
||||||
|
while (dlfb->urbs.count * size < wanted_size) {
|
||||||
unode = kzalloc(sizeof(*unode), GFP_KERNEL);
|
unode = kzalloc(sizeof(*unode), GFP_KERNEL);
|
||||||
if (!unode)
|
if (!unode)
|
||||||
break;
|
break;
|
||||||
|
@ -1866,11 +1871,16 @@ static int dlfb_alloc_urb_list(struct dlfb_data *dlfb, int count, size_t size)
|
||||||
}
|
}
|
||||||
unode->urb = urb;
|
unode->urb = urb;
|
||||||
|
|
||||||
buf = usb_alloc_coherent(dlfb->udev, MAX_TRANSFER, GFP_KERNEL,
|
buf = usb_alloc_coherent(dlfb->udev, size, GFP_KERNEL,
|
||||||
&urb->transfer_dma);
|
&urb->transfer_dma);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
kfree(unode);
|
kfree(unode);
|
||||||
usb_free_urb(urb);
|
usb_free_urb(urb);
|
||||||
|
if (size > PAGE_SIZE) {
|
||||||
|
size /= 2;
|
||||||
|
dlfb_free_urb_list(dlfb);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1881,14 +1891,12 @@ static int dlfb_alloc_urb_list(struct dlfb_data *dlfb, int count, size_t size)
|
||||||
|
|
||||||
list_add_tail(&unode->entry, &dlfb->urbs.list);
|
list_add_tail(&unode->entry, &dlfb->urbs.list);
|
||||||
|
|
||||||
i++;
|
up(&dlfb->urbs.limit_sem);
|
||||||
|
dlfb->urbs.count++;
|
||||||
|
dlfb->urbs.available++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sema_init(&dlfb->urbs.limit_sem, i);
|
return dlfb->urbs.count;
|
||||||
dlfb->urbs.count = i;
|
|
||||||
dlfb->urbs.available = i;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct urb *dlfb_get_urb(struct dlfb_data *dlfb)
|
static struct urb *dlfb_get_urb(struct dlfb_data *dlfb)
|
||||||
|
|
Loading…
Reference in New Issue