Skip to contentSkip to conversation

drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci()

PATCH Applied Zou Wei 2 participants 2 messages May 18, 2021 – May 19, 2021

Subsystems (2)
lore
Share & tools
lore

Zou Wei

author
#0 lore raw

PATCH 1/1 drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci()

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")
---
 drivers/gpu/drm/drm_bufs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_bufs.c +9 -1
index 4805726..c23d7f7 100644
@@ -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,
Signature · 1 line
2.6.2
#1 lore raw
Quoted 6 lines · Zou Wei

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")

Applied to drm-misc-next, thanks for your patch.
-Daniel

Quoted 29 lines
---
 drivers/gpu/drm/drm_bufs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_bufs.c +9 -1
index 4805726..c23d7f7 100644
@@ -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,
Signature · 1 line
2.6.2
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch