Skip to contentSkip to conversation

spi: dw-mid: don't leak memory on exit

PATCH In review Andy Shevchenko 3 participants 3 messages Aug 28, 2014 – Aug 29, 2014 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: dw-mid: don't leak memory on exit

When built with DMA support the memory for an internal structure is allocated but not freed. Converting to devm_kzalloc solves the issue.

Fixes 7063c0d942a1 (spi/dw_spi: add DMA support)
Cc <[email protected]> # v2.6.38+
---
 drivers/spi/spi-dw-mid.c | 4 ++--
 drivers/spi/spi-dw-pci.c | 5 ++---
 drivers/spi/spi-dw.h     | 3 ++-
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/spi/spi-dw-mid.c +2 -2
index c79bf96..ceb95b4 100644
@@ -202,7 +202,7 @@ static struct dw_spi_dma_ops mid_dma_ops = {
 #define CLK_SPI_CDIV_MASK	0x00000e00
 #define CLK_SPI_DISABLE_OFFSET	8
 
-int dw_spi_mid_init(struct dw_spi *dws)
+int dw_spi_mid_init(struct device *dev, struct dw_spi *dws)
 {
 	void __iomem *clk_reg;
 	u32 clk_cdiv;
@@ -220,7 +220,7 @@ int dw_spi_mid_init(struct dw_spi *dws)
 	dws->fifo_len = 40;	/* FIFO has 40 words buffer */
 
 #ifdef CONFIG_SPI_DW_MID_DMA
-	dws->dma_priv = kzalloc(sizeof(struct mid_dma), GFP_KERNEL);
+	dws->dma_priv = devm_kzalloc(dev, sizeof(struct mid_dma), GFP_KERNEL);
 	if (!dws->dma_priv)
 		return -ENOMEM;
 	dws->dma_ops = &mid_dma_ops;
drivers/spi/spi-dw-pci.c +2 -3
index b8b02d7..dd06c07 100644
@@ -28,8 +28,7 @@ struct dw_spi_pci {
 	struct dw_spi	dws;
 };
 
-static int spi_pci_probe(struct pci_dev *pdev,
-	const struct pci_device_id *ent)
+static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct dw_spi_pci *dwpci;
 	struct dw_spi *dws;
@@ -66,7 +65,7 @@ static int spi_pci_probe(struct pci_dev *pdev,
 	 * clock rate, FIFO depth.
 	 */
 	if (pdev->device == 0x0800) {
-		ret = dw_spi_mid_init(dws);
+		ret = dw_spi_mid_init(&pdev->dev, dws);
 		if (ret)
 			return ret;
 	}
drivers/spi/spi-dw.h +2 -1
index 0f8cece..b3ff9eb 100644
@@ -232,5 +232,6 @@ extern int dw_spi_resume_host(struct dw_spi *dws);
 extern void dw_spi_xfer_done(struct dw_spi *dws);
 
 /* platform related setup */
-extern int dw_spi_mid_init(struct dw_spi *dws); /* Intel MID platforms */
+/* Intel MID platforms */
+extern int dw_spi_mid_init(struct device *dev, struct dw_spi *dws);
 #endif /* DW_SPI_HEADER_H */
Signature · 6 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#1 lore raw
Quoted 6 lines · Andy Shevchenko

When built with DMA support the memory for an internal structure is allocated but not freed. Converting to devm_kzalloc solves the issue.

Fixes 7063c0d942a1 (spi/dw_spi: add DMA support)
Cc <[email protected]> # v2.6.38+

You've sent two versions of this with different changelogs and diffs - what's the story there?

This doesn't seem like an obvious stable candidate - it's a leak fix on probe.

#2 lore raw
Quoted 10 lines · Mark Brown
Quoted 6 lines · Andy Shevchenko

When built with DMA support the memory for an internal structure is allocated but not freed. Converting to devm_kzalloc solves the issue.

Fixes 7063c0d942a1 (spi/dw_spi: add DMA support)
Cc <[email protected]> # v2.6.38+

You've sent two versions of this with different changelogs and diffs - what's the story there?

Sorry for confusion.

There are two different fixes against MID support.
One of them to protect against crash on removal, another is this one.

Quoted 2 lines

This doesn't seem like an obvious stable candidate - it's a leak fix on probe.

Yes, I may agree with you. Then, please, do not consider this one. It would be a part of a patches against spi-dw-mid.c

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy