Commit 542bb978 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Dave Airlie

udl-kms: handle allocation failure

Allocations larger than PAGE_ALLOC_COSTLY_ORDER are unreliable and they
may fail anytime. This patch fixes the udl kms driver so that when a large
alloactions fails, it tries to do multiple smaller allocations.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 8456b99c
...@@ -200,17 +200,22 @@ static void udl_free_urb_list(struct drm_device *dev) ...@@ -200,17 +200,22 @@ static void udl_free_urb_list(struct drm_device *dev)
static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size)
{ {
struct udl_device *udl = dev->dev_private; struct udl_device *udl = dev->dev_private;
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(&udl->urbs.lock); spin_lock_init(&udl->urbs.lock);
retry:
udl->urbs.size = size; udl->urbs.size = size;
INIT_LIST_HEAD(&udl->urbs.list); INIT_LIST_HEAD(&udl->urbs.list);
while (i < count) { sema_init(&udl->urbs.limit_sem, 0);
udl->urbs.count = 0;
udl->urbs.available = 0;
while (udl->urbs.count * size < wanted_size) {
unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL); unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL);
if (!unode) if (!unode)
break; break;
...@@ -226,11 +231,16 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) ...@@ -226,11 +231,16 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size)
} }
unode->urb = urb; unode->urb = urb;
buf = usb_alloc_coherent(udl->udev, MAX_TRANSFER, GFP_KERNEL, buf = usb_alloc_coherent(udl->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;
udl_free_urb_list(dev);
goto retry;
}
break; break;
} }
...@@ -241,16 +251,14 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size) ...@@ -241,16 +251,14 @@ static int udl_alloc_urb_list(struct drm_device *dev, int count, size_t size)
list_add_tail(&unode->entry, &udl->urbs.list); list_add_tail(&unode->entry, &udl->urbs.list);
i++; up(&udl->urbs.limit_sem);
udl->urbs.count++;
udl->urbs.available++;
} }
sema_init(&udl->urbs.limit_sem, i); DRM_DEBUG("allocated %d %d byte urbs\n", udl->urbs.count, (int) size);
udl->urbs.count = i;
udl->urbs.available = i;
DRM_DEBUG("allocated %d %d byte urbs\n", i, (int) size);
return i; return udl->urbs.count;
} }
struct urb *udl_get_urb(struct drm_device *dev) struct urb *udl_get_urb(struct drm_device *dev)
......
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