public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci()
@ 2021-05-18 12:35 Zou Wei
  2021-05-19 10:21 ` Daniel Vetter
  0 siblings, 1 reply; 2+ messages in thread
From: Zou Wei @ 2021-05-18 12:35 UTC (permalink / raw)
  To: maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: joseph.kogut, dri-devel, linux-kernel, 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")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/gpu/drm/drm_bufs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 4805726..c23d7f7 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -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,
-- 
2.6.2


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

* Re: [PATCH -next] drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci()
  2021-05-18 12:35 [PATCH -next] drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci() Zou Wei
@ 2021-05-19 10:21 ` Daniel Vetter
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2021-05-19 10:21 UTC (permalink / raw)
  To: Zou Wei
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, daniel,
	joseph.kogut, dri-devel, linux-kernel

On Tue, May 18, 2021 at 08:35:02PM +0800, Zou Wei wrote:
> 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>

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

> ---
>  drivers/gpu/drm/drm_bufs.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
> index 4805726..c23d7f7 100644
> --- a/drivers/gpu/drm/drm_bufs.c
> +++ b/drivers/gpu/drm/drm_bufs.c
> @@ -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,
> -- 
> 2.6.2
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

end of thread, other threads:[~2021-05-19 10:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-18 12:35 [PATCH -next] drm: Fix missing unlock and free on error in drm_legacy_addbufs_pci() Zou Wei
2021-05-19 10:21 ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox