lkml.org 
[lkml]   [2022]   [Sep]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] dmaengine: idxd: Fix memory leak in idxd_alloc()
Date
If the IDA id allocation fails, then the allocated memory for the
idxd_device struct doesn't get freed before returning NULL, which leads to
a memleak.

Fixes: 47c16ac27d4c ("dmaengine: idxd: fix idxd conf_dev 'struct device' lifetime")
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
---
drivers/dma/idxd/init.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index aa3478257ddb..fdc97519b8fb 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -445,8 +445,10 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d
idxd->data = data;
idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type);
idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL);
- if (idxd->id < 0)
+ if (idxd->id < 0) {
+ kfree(idxd);
return NULL;
+ }

device_initialize(conf_dev);
conf_dev->parent = dev;
--
2.34.1
\
 
 \ /
  Last update: 2022-09-15 01:09    [W:0.035 / U:1.808 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site