linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core()
@ 2022-05-09  5:44 Hangyu Hua
  2022-05-23  1:57 ` Hangyu Hua
  0 siblings, 1 reply; 3+ messages in thread
From: Hangyu Hua @ 2022-05-09  5:44 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel, 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")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index fcca21e8efac..2b3f504c5f9c 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core()
  2022-05-09  5:44 [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core() Hangyu Hua
@ 2022-05-23  1:57 ` Hangyu Hua
  2022-06-23  1:45   ` Hangyu Hua
  0 siblings, 1 reply; 3+ messages in thread
From: Hangyu Hua @ 2022-05-23  1:57 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel

On 2022/5/9 13:44, Hangyu Hua wrote:
> 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 <hbh25y@gmail.com>
> ---
>   drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index fcca21e8efac..2b3f504c5f9c 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -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);

Gentel ping.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core()
  2022-05-23  1:57 ` Hangyu Hua
@ 2022-06-23  1:45   ` Hangyu Hua
  0 siblings, 0 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-06-23  1:45 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: dri-devel, linux-kernel

On 2022/5/23 09:57, Hangyu Hua wrote:
> On 2022/5/9 13:44, Hangyu Hua wrote:
>> 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 <hbh25y@gmail.com>
>> ---
>>   drivers/gpu/drm/drm_bufs.c | 18 ++++++++++++++++++
>>   1 file changed, 18 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
>> index fcca21e8efac..2b3f504c5f9c 100644
>> --- a/drivers/gpu/drm/drm_bufs.c
>> +++ b/drivers/gpu/drm/drm_bufs.c
>> @@ -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);
> 
> Gentel ping.

Gentel ping.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-23  1:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09  5:44 [PATCH] gpu: drm: fix possible memory leak in drm_addmap_core() Hangyu Hua
2022-05-23  1:57 ` Hangyu Hua
2022-06-23  1:45   ` Hangyu Hua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).