Skip to contentSkip to conversation

lpss8250_dma_setup: there is memory leak when second allocation fails

PATCH NAK Navid Emamdoost 2 participants 2 messages Jul 19, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lpss8250_dma_setup: there is memory leak when second allocation fails

in lpss8250_dma_setup, we need to release the first dma slave object allocated in case of the second allocation failure.

---
 drivers/tty/serial/8250/8250_lpss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_lpss.c +3 -1
index d07e431110d9..6e1f86db88b2 100644
@@ -259,8 +259,10 @@ static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port
 		return -ENOMEM;
 
 	tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL);
-	if (!tx_param)
+	if (!tx_param) {
+		kfree(rx_param);
 		return -ENOMEM;
+	}
 
 	*rx_param = lpss->dma_param;
 	dma->rxconf.src_maxburst = lpss->dma_maxburst;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Navid Emamdoost

in lpss8250_dma_setup, we need to release the first dma slave object allocated in case of the second allocation failure.

This will bring a double free instead of fixing anything.

NAK.

Quoted 24 lines
---
 drivers/tty/serial/8250/8250_lpss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_lpss.c +3 -2
index d07e431110d9..6e1f86db88b2 100644
@@ -259,8 +259,10 @@ static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port
                return -ENOMEM;
 
        tx_param = devm_kzalloc(dev, sizeof(*tx_param), GFP_KERNEL);
-       if (!tx_param)
+       if (!tx_param) {
+               kfree(rx_param);
                return -ENOMEM;
+       }
 
        *rx_param = lpss->dma_param;
        dma->rxconf.src_maxburst = lpss->dma_maxburst;
--

2.17.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko