dmaengine: idxd: Fix memory leak in idxd_alloc()
Subsystems (2)
PATCH 1/1 dmaengine: idxd: Fix memory leak in idxd_alloc()
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.
--- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dma/idxd/init.c +3 -1
@@ -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;
Signature · 1 line
2.34.1
Quoted 6 lines · Rafael Mendonca
If the IDA id allocation fails, then the allocated memory for the
idxd_devicestruct 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 <[email protected]>
I think there needs to be a kfree(idxd) where it checks rc < 0 after the call to dev_set_name() as well, yes?
Regards,
Jerry
Quoted 23 lines
--- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/dma/idxd/init.c +3
-1@@ -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;Signature · 1 line
2.34.1
Dave Jiang
reviewerQuoted 8 lines · Jerry Snitselaar
Quoted 6 lines · Rafael Mendonca
If the IDA id allocation fails, then the allocated memory for the
idxd_devicestruct 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 <[email protected]>I think there needs to be a kfree(idxd) where it checks rc < 0 after the call to
dev_set_name()as well, yes?
The idxd_conf_device_release() should take care of freeing idxd with the put_device(). So I think we are good here.
Quoted 27 lines
Regards,
JerryQuoted 23 lines
--- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/dma/idxd/init.c +3
-1@@ -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;Signature · 1 line
2.34.1
Quoted 7 lines · Dave Jiang
Quoted 5 lines · Jerry Snitselaar
Quoted 4 lines · Rafael Mendonca
If the IDA id allocation fails, then the allocated memory for the
idxd_devicestruct doesn't get freed before returning NULL, which leads to a memleak.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Fixes 47c16ac27d4c ("dmaengine: idxd: fix idxd conf_dev 'struct device' lifetime")Signed-off-by Rafael Mendonca <[email protected]>I think there needs to be a kfree(idxd) where it checks rc < 0 after the call to
dev_set_name()as well, yes?The
idxd_conf_device_release()should take care of freeing idxd with theput_device(). So I think we are good here.
Ah, right. Thanks.
Jerry
Quoted 26 lines
Quoted 26 lines
Regards,
JerryQuoted 22 lines
--- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/dma/idxd/init.c +3
-1@@ -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;Signature · 1 line
2.34.1
Quoted 6 lines · Rafael Mendonca
If the IDA id allocation fails, then the allocated memory for the
idxd_devicestruct 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 <[email protected]>
Thanks!
Quoted 20 lines
--- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/dma/idxd/init.c +3
-1@@ -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;
Quoted 6 lines · Rafael Mendonca
If the IDA id allocation fails, then the allocated memory for the
idxd_devicestruct 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 <[email protected]>
Quoted 23 lines
--- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/dma/idxd/init.c +3
-1@@ -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;Signature · 1 line
2.34.1
Quoted 3 lines · Rafael Mendonca
If the IDA id allocation fails, then the allocated memory for the
idxd_devicestruct doesn't get freed before returning NULL, which leads to a memleak.
Applied, thanks
Signature · 1 line
~Vinod