Skip to contentSkip to conversation

EDAC: altera: Delete an inappropriate dma_free_coherent() call in altr_sdr_mc_err_inject_write()

PATCH Applied Salah Triki 4 participants 4 messages Jul 31, 2025 – Aug 25, 2025

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EDAC: altera: Delete an inappropriate dma_free_coherent() call in altr_sdr_mc_err_inject_write()

dma_free_coherent() must only be called if the corresponding dma_alloc_coherent() call has succeeded. Calling it when the allocation fails leads to undefined behavior.

Add a check to ensure that the memory is only freed when the allocation was successful.

Fixes 71bcada88b0f3 ("edac: altera: Add Altera SDRAM EDAC support")
Cc Markus Elfring <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Tony Luck <[email protected]>
Cc James Morse <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Robert Richter <[email protected]>
---
 drivers/edac/altera_edac.c | 1 -
 1 file changed, 1 deletion(-)
drivers/edac/altera_edac.c +0 -1
index cae52c654a15..7685a8550d4b 100644
@@ -128,7 +128,6 @@ static ssize_t altr_sdr_mc_err_inject_write(struct file *file,
 
 	ptemp = dma_alloc_coherent(mci->pdev, 16, &dma_handle, GFP_KERNEL);
 	if (!ptemp) {
-		dma_free_coherent(mci->pdev, 16, ptemp, dma_handle);
 		edac_printk(KERN_ERR, EDAC_MC,
 			    "Inject: Buffer Allocation error\n");
 		return -ENOMEM;
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Salah Triki

dma_free_coherent() must only be called if the corresponding dma_alloc_coherent() call has succeeded. Calling it when the allocation fails leads to undefined behavior.

Add a check to ensure that the memory is only freed when the allocation was successful.

Fixes 71bcada88b0f3 ("edac: altera: Add Altera SDRAM EDAC support")
Cc Markus Elfring <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Tony Luck <[email protected]>
Cc James Morse <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Robert Richter <[email protected]>
---
  drivers/edac/altera_edac.c | 1 -
  1 file changed, 1 deletion(-)
drivers/edac/altera_edac.c +0 -0
index cae52c654a15..7685a8550d4b 100644

drivers/edac/altera_edac.c static ssize_t altr_sdr_mc_err_inject_write(struct file *file, · line 133

Quoted 7 lines
drivers/edac/altera_edac.c +0 -1
@@ -128,7 +128,6 @@ static ssize_t altr_sdr_mc_err_inject_write(struct file *file,
 
  	ptemp = dma_alloc_coherent(mci->pdev, 16, &dma_handle, GFP_KERNEL);
  	if (!ptemp) {
-		dma_free_coherent(mci->pdev, 16, ptemp, dma_handle);
  		edac_printk(KERN_ERR, EDAC_MC,
  			    "Inject: Buffer Allocation error\n");
  		return -ENOMEM;
#2 lore raw
In reply to Salah Triki

…> Add a check to ensure that the memory is only freed when the allocation

Quoted 1 line

was successful.

How good does such a wording fit to the proposed function call deletion?

Regards,
Markus

maintainer Applied
#3 lore raw
In reply to Salah Triki
Quoted 29 lines · Salah Triki

dma_free_coherent() must only be called if the corresponding dma_alloc_coherent() call has succeeded. Calling it when the allocation fails leads to undefined behavior.

Add a check to ensure that the memory is only freed when the allocation was successful.

Fixes 71bcada88b0f3 ("edac: altera: Add Altera SDRAM EDAC support")
Cc Markus Elfring <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Tony Luck <[email protected]>
Cc James Morse <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Robert Richter <[email protected]>
---
 drivers/edac/altera_edac.c | 1 -
 1 file changed, 1 deletion(-)
drivers/edac/altera_edac.c +0 -0
index cae52c654a15..7685a8550d4b 100644

drivers/edac/altera_edac.c static ssize_t altr_sdr_mc_err_inject_write(struct file *file, · line 133

Quoted 7 lines
drivers/edac/altera_edac.c +0 -1
@@ -128,7 +128,6 @@ static ssize_t altr_sdr_mc_err_inject_write(struct file *file,
 
 	ptemp = dma_alloc_coherent(mci->pdev, 16, &dma_handle, GFP_KERNEL);
 	if (!ptemp) {
-		dma_free_coherent(mci->pdev, 16, ptemp, dma_handle);
 		edac_printk(KERN_ERR, EDAC_MC,
 			    "Inject: Buffer Allocation error\n");
 		return -ENOMEM;

Applied, thanks.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette