]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci()
authorZou Wei <zou_wei@huawei.com>
Tue, 18 May 2021 12:35:02 +0000 (20:35 +0800)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 20 May 2021 20:09:46 +0000 (22:09 +0200)
Add the missing unlock and free before return from function
drm_legacy_addbufs_pci() in the error handling case.

Fixes: 70556e24e18e ("drm: remove usage of drm_pci_alloc/free")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/1621341302-112089-1-git-send-email-zou_wei@huawei.com
drivers/gpu/drm/drm_bufs.c

index 4805726b34ac411f6dbf67af0909679e88f75bd1..c23d7f7c023217d10a91396dc67d9c4916b0fe12 100644 (file)
@@ -984,8 +984,16 @@ int drm_legacy_addbufs_pci(struct drm_device *dev,
 
        while (entry->buf_count < count) {
                dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
-               if (!dmah)
+               if (!dmah) {
+                       /* Set count correctly so we free the proper amount. */
+                       entry->buf_count = count;
+                       entry->seg_count = count;
+                       drm_cleanup_buf_error(dev, entry);
+                       kfree(temp_pagelist);
+                       mutex_unlock(&dev->struct_mutex);
+                       atomic_dec(&dev->buf_alloc);
                        return -ENOMEM;
+               }
 
                dmah->size = total;
                dmah->vaddr = dma_alloc_coherent(dev->dev,