Skip to contentSkip to conversation

gpu: drm: fix possible memory leak in drm_addmap_core()

PATCH In review Hangyu Hua 1 participant 3 messages May 9, 2022 – Jun 23, 2022

Subsystems (2)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 gpu: drm: fix possible memory leak in drm_addmap_core()

map->handle need to be handled correctly when map->type is _DRM_SHM or _DRM_CONSISTENT just like map->type is _DRM_REGISTERS.

Fixes 8d153f7107ff ("drm: update user token hashing and map handles")
---
 drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/gpu/drm/drm_bufs.c +18 -0
index fcca21e8efac..2b3f504c5f9c 100644
@@ -344,6 +344,15 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset,
 	if (!list) {
 		if (map->type == _DRM_REGISTERS)
 			iounmap(map->handle);
+		else if (map->type == _DRM_SHM) {
+			dev->sigdata.lock = dev->master->lock.hw_lock = NULL;
+			vfree(map->handle);
+		} else if (map->type == _DRM_CONSISTENT) {
+			dma_free_coherent(dev->dev,
+					  map->size,
+					  map->handle,
+					  map->offset);
+		}
 		kfree(map);
 		return -EINVAL;
 	}
@@ -361,6 +370,15 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset,
 	if (ret) {
 		if (map->type == _DRM_REGISTERS)
 			iounmap(map->handle);
+		else if (map->type == _DRM_SHM) {
+			dev->sigdata.lock = dev->master->lock.hw_lock = NULL;
+			vfree(map->handle);
+		} else if (map->type == _DRM_CONSISTENT) {
+			dma_free_coherent(dev->dev,
+					  map->size,
+					  map->handle,
+					  map->offset);
+		}
 		kfree(map);
 		kfree(list);
 		mutex_unlock(&dev->struct_mutex);
Signature · 1 line
2.25.1
author
#1 lore raw
Quoted 35 lines · Hangyu Hua

map->handle need to be handled correctly when map->type is _DRM_SHM or _DRM_CONSISTENT just like map->type is _DRM_REGISTERS.

Fixes 8d153f7107ff ("drm: update user token hashing and map handles")
---
  drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
drivers/gpu/drm/drm_bufs.c +11 -0
index fcca21e8efac..2b3f504c5f9c 100644
@@ -344,6 +344,15 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset,
  	if (!list) {
  		if (map->type == _DRM_REGISTERS)
  			iounmap(map->handle);
+		else if (map->type == _DRM_SHM) {
+			dev->sigdata.lock = dev->master->lock.hw_lock = NULL;
+			vfree(map->handle);
+		} else if (map->type == _DRM_CONSISTENT) {
+			dma_free_coherent(dev->dev,
+					  map->size,
+					  map->handle,
+					  map->offset);
+		}
  		kfree(map);
  		return -EINVAL;
  	}
@@ -361,6 +370,15 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset,
  	if (ret) {
  		if (map->type == _DRM_REGISTERS)
  			iounmap(map->handle);
+		else if (map->type == _DRM_SHM) {
+			dev->sigdata.lock = dev->master->lock.hw_lock = NULL;

drivers/gpu/drm/drm_bufs.c static int drm_addmap_core(struct drm_device *dev, resource_size_t offset, · line 384

Quoted 10 lines
drivers/gpu/drm/drm_bufs.c +7 -0
+			vfree(map->handle);
+		} else if (map->type == _DRM_CONSISTENT) {
+			dma_free_coherent(dev->dev,
+					  map->size,
+					  map->handle,
+					  map->offset);
+		}
  		kfree(map);
  		kfree(list);
  		mutex_unlock(&dev->struct_mutex);

Gentel ping.

author
#2 lore raw
Quoted 42 lines · Hangyu Hua
Quoted 41 lines · Hangyu Hua

map->handle need to be handled correctly when map->type is _DRM_SHM or _DRM_CONSISTENT just like map->type is _DRM_REGISTERS.

Fixes 8d153f7107ff ("drm: update user token hashing and map handles")

---
  drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++

  1 file changed, 18 insertions(+)
drivers/gpu/drm/drm_bufs.c +9 -0
index fcca21e8efac..2b3f504c5f9c 100644
@@ -344,6 +344,15 @@ static int drm_addmap_core(struct drm_device 
 *dev, resource_size_t offset,
       if (!list) {
           if (map->type == _DRM_REGISTERS)
               iounmap(map->handle);
+        else if (map->type == _DRM_SHM) {
+            dev->sigdata.lock = dev->master->lock.hw_lock = NULL;
+            vfree(map->handle);
+        } else if (map->type == _DRM_CONSISTENT) {
+            dma_free_coherent(dev->dev,
+                      map->size,
+                      map->handle,
+                      map->offset);
+        }
           kfree(map);
           return -EINVAL;

      }

drivers/gpu/drm/drm_bufs.c +6 -0
@@ -361,6 +370,15 @@ static int drm_addmap_core(struct drm_device 
 *dev, resource_size_t offset,
       if (ret) {
           if (map->type == _DRM_REGISTERS)
               iounmap(map->handle);
+        else if (map->type == _DRM_SHM) {
+            dev->sigdata.lock = dev->master->lock.hw_lock = NULL;
+            vfree(map->handle);
+        } else if (map->type == _DRM_CONSISTENT) {
+            dma_free_coherent(dev->dev,
+                      map->size,
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/drm_bufs.c +3 -0
+                      map->handle,
+                      map->offset);
+        }
           kfree(map);
           kfree(list);

          mutex_unlock(&dev->struct_mutex);

Gentel ping.

Gentel ping.