gpu: drm: fix possible memory leak in drm_addmap_core()
Subsystems (2)
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")
Signed-off-by Hangyu Hua <[email protected]>
--- drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/gpu/drm/drm_bufs.c +18 -0
@@ -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
Quoted 35 lines · Hangyu Hua
map->handleneed to be handled correctly whenmap->typeis_DRM_SHMor_DRM_CONSISTENTjust likemap->typeis_DRM_REGISTERS.Fixes 8d153f7107ff ("drm: update user token hashing and map handles")Signed-off-by Hangyu Hua <[email protected]>--- drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)drivers/gpu/drm/drm_bufs.c +11
-0@@ -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.
Quoted 42 lines · Hangyu Hua
Quoted 41 lines · Hangyu Hua
map->handleneed to be handled correctly whenmap->typeis_DRM_SHMor_DRM_CONSISTENTjust likemap->typeis_DRM_REGISTERS.Fixes 8d153f7107ff ("drm: update user token hashing and map handles")Signed-off-by Hangyu Hua <[email protected]>---
drivers/gpu/drm/drm_bufs.c| 18 ++++++++++++++++++1 file changed, 18 insertions(+)drivers/gpu/drm/drm_bufs.c +9
-0@@ -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.