linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][V2][next] drm/vmwgfx: Fix memory allocation check and a leak of object fifo
@ 2021-05-14 14:49 Colin King
  2021-05-14 18:32 ` Zack Rusin
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-05-14 14:49 UTC (permalink / raw)
  To: VMware Graphics, Roland Scheidegger, Zack Rusin, David Airlie,
	Daniel Vetter, dri-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The allocation of fifo is lacking an allocation failure check, so
fix this by adding one.

In the case where fifo->static_buffer fails to be allocated the
error return path neglects to kfree the fifo object. Fix this by
adding in the missing kfree.

Kudos to Dan Carpenter for spotting the missing kzalloc failure
check.

Addresses-Coverity: ("Resource leak")
Fixes: 2cd80dbd3551 ("drm/vmwgfx: Add basic support for SVGA3")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: Add missing allocation failure check
    Update $SUBJECT to reflect this extra change

---
 drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c
index 027d7d504e78..d9acd2f3f673 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c
@@ -105,10 +105,14 @@ struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv)
 		return NULL;
 
 	fifo = kzalloc(sizeof(*fifo), GFP_KERNEL);
+	if (!fifo)
+		return ERR_PTR(-ENOMEM);
 	fifo->static_buffer_size = VMWGFX_FIFO_STATIC_SIZE;
 	fifo->static_buffer = vmalloc(fifo->static_buffer_size);
-	if (unlikely(fifo->static_buffer == NULL))
+	if (unlikely(fifo->static_buffer == NULL)) {
+		kfree(fifo);
 		return ERR_PTR(-ENOMEM);
+	}
 
 	fifo->dynamic_buffer = NULL;
 	fifo->reserved_size = 0;
-- 
2.30.2


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

* Re: [PATCH][V2][next] drm/vmwgfx: Fix memory allocation check and a leak of object fifo
  2021-05-14 14:49 [PATCH][V2][next] drm/vmwgfx: Fix memory allocation check and a leak of object fifo Colin King
@ 2021-05-14 18:32 ` Zack Rusin
  0 siblings, 0 replies; 2+ messages in thread
From: Zack Rusin @ 2021-05-14 18:32 UTC (permalink / raw)
  To: Colin King, VMware Graphics, Roland Scheidegger, David Airlie,
	Daniel Vetter, dri-devel
  Cc: kernel-janitors, linux-kernel

On 5/14/21 10:49 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The allocation of fifo is lacking an allocation failure check, so
> fix this by adding one.
> 
> In the case where fifo->static_buffer fails to be allocated the
> error return path neglects to kfree the fifo object. Fix this by
> adding in the missing kfree.
> 
> Kudos to Dan Carpenter for spotting the missing kzalloc failure
> check.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: 2cd80dbd3551 ("drm/vmwgfx: Add basic support for SVGA3")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> 
> V2: Add missing allocation failure check
>      Update $SUBJECT to reflect this extra change

Looks good. Thanks. I'll push it through drm-misc-next.

z

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

end of thread, other threads:[~2021-05-14 18:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 14:49 [PATCH][V2][next] drm/vmwgfx: Fix memory allocation check and a leak of object fifo Colin King
2021-05-14 18:32 ` Zack Rusin

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