ata: sata_dwc_460ex: fix error path
Subsystems (2)
PATCH 1/1 ata: sata_dwc_460ex: fix error path
Free all allocated resources on error path.
---
I cannot compile this driver at all, so it is not tested.
drivers/ata/sata_dwc_460ex.c | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-)
drivers/ata/sata_dwc_460ex.c +14 -7
@@ -727,11 +727,15 @@ static int dma_dwc_xfer_setup(struct scatterlist *sg, int num_elems,static void dma_dwc_exit (struct sata_dwc_device *hsdev) {dev_dbg (host_pvt.dwc_dev,"%s:\n" , __func__); -if (host_pvt.sata_dma_regs) +if (host_pvt.sata_dma_regs) {iounmap (host_pvt.sata_dma_regs); + host_pvt.sata_dma_regs =NULL ; + } -if (hsdev->irq_dma) +if (hsdev->irq_dma) {free_irq (hsdev->irq_dma, hsdev); + hsdev->irq_dma =0 ; + } }/*
@@ -1606,7 +1610,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,if (hsdev =NULL ) {dev_err (&ofdev->dev,"kmalloc failed for hsdev\n" ); err = -ENOMEM ; - goto error_out; + goto error; }memset (hsdev,0 ,sizeof (*hsdev));
@@ -1616,7 +1620,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,dev_err (&ofdev->dev,"ioremap failed for SATA register" " address\n" ); err = -ENODEV ; - goto error_out; + goto error_kmalloc; } hsdev->reg_base = base;dev_dbg (&ofdev->dev,"ioremap done for SATA register address\n" );
@@ -1629,7 +1633,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,if (!host) {dev_err (&ofdev->dev,"ata_host_alloc_pinfo failed\n" ); err = -ENOMEM ; - goto error_out; + goto error_iomap; } host->private_data = hsdev;
@@ -1697,8 +1701,11 @@ error_out:/* Free SATA DMA resources */ dma_dwc_exit (hsdev); -if (base) -iounmap (base); +error_iomap: +iounmap (base); +error_kmalloc: +kfree (hsdev); +error:return err; }
Signature · 1 line
1.7.0.4
Hello.
Quoted 5 lines · Vasiliy Kulikov
Free all allocated resources on error path.
Signed-off-by Vasiliy Kulikov <[email protected]>---
I cannot compile this driver at all, so it is not tested.
I can at least compile-test the patch...
Quoted 13 lines
drivers/ata/sata_dwc_460ex.c | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-)drivers/ata/sata_dwc_460ex.c +1
-1@@ -727,11 +727,15 @@ static int dma_dwc_xfer_setup(struct scatterlist *sg, int num_elems,static void dma_dwc_exit (struct sata_dwc_device *hsdev) {dev_dbg (host_pvt.dwc_dev,"%s:\n" , __func__); -if (host_pvt.sata_dma_regs) +if (host_pvt.sata_dma_regs) {
drivers/ata/sata_dwc_460ex.c static int dma_dwc_xfer_setup(struct scatterlist *sg, int num_elems, · line 739
Quoted 10 lines
drivers/ata/sata_dwc_460ex.c +5
-1iounmap (host_pvt.sata_dma_regs); + host_pvt.sata_dma_regs =NULL ; + } -if (hsdev->irq_dma) +if (hsdev->irq_dma) {free_irq (hsdev->irq_dma, hsdev); + hsdev->irq_dma =0 ; + } }
Are those changes really necessary, i.e. is dma_dwc_exit() called more than
once?
drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev, · line 1613
Quoted 6 lines
drivers/ata/sata_dwc_460ex.c +1
-1@@ -1606,7 +1610,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,if (hsdev =NULL ) {dev_err (&ofdev->dev,"kmalloc failed for hsdev\n" ); err = -ENOMEM ; - goto error_out; + goto error;
Why not just:
return err;
Quoted 24 lines
drivers/ata/sata_dwc_460ex.c +2
-2}memset (hsdev,0 ,sizeof (*hsdev));@@ -1616,7 +1620,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,dev_err (&ofdev->dev,"ioremap failed for SATA register" " address\n" ); err = -ENODEV ; - goto error_out; + goto error_kmalloc; } hsdev->reg_base = base;dev_dbg (&ofdev->dev,"ioremap done for SATA register address\n" );@@ -1629,7 +1633,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,if (!host) {dev_err (&ofdev->dev,"ata_host_alloc_pinfo failed\n" ); err = -ENOMEM ; - goto error_out; + goto error_iomap; } host->private_data = hsdev;@@ -1697,8 +1701,11 @@ error_out:/* Free SATA DMA resources */ dma_dwc_exit (hsdev);
drivers/ata/sata_dwc_460ex.c error_out: · line 1710
Quoted 10 lines
drivers/ata/sata_dwc_460ex.c +5
-2-if (base) -iounmap (base); +error_iomap: +iounmap (base); +error_kmalloc: +kfree (hsdev); +error:return err; }
Jeff, what's become with this patch? Will you queue it? And will you queue
my 4 fixes (and 1 cleanup)?
WBR, Sergei
Hi Sergei,
Quoted 10 lines · Sergei Shtylyov
Quoted 10 lines
drivers/ata/sata_dwc_460ex.c +3
-2@@ -727,11 +727,15 @@ static int dma_dwc_xfer_setup(struct scatterlist *sg, int num_elems,static void dma_dwc_exit (struct sata_dwc_device *hsdev) {dev_dbg (host_pvt.dwc_dev,"%s:\n" , __func__); -if (host_pvt.sata_dma_regs) +if (host_pvt.sata_dma_regs) {iounmap (host_pvt.sata_dma_regs); + host_pvt.sata_dma_regs =NULL ; + } -if (hsdev->irq_dma)
Quoted 8 lines
drivers/ata/sata_dwc_460ex.c static int dma_dwc_xfer_setup(struct scatterlist *sg, int num_elems, · line 739
Quoted 5 lines
drivers/ata/sata_dwc_460ex.c +3
-0+if (hsdev->irq_dma) {free_irq (hsdev->irq_dma, hsdev); + hsdev->irq_dma =0 ; + } }Are those changes really necessary, i.e. is
dma_dwc_exit()called
more than once?
Because this function may be called once again before host_pvt.sata_dma_regs gains new value in sata_dwc_probe(). This would lead to double iounmap() and double free_irq().
Quoted 10 lines
drivers/ata/sata_dwc_460ex.c static int sata_dwc_probe(struct platform_device *ofdev, · line 1613
Quoted 6 lines
drivers/ata/sata_dwc_460ex.c +1
-1@@ -1606,7 +1610,7 @@ static int sata_dwc_probe(struct platform_device *ofdev,if (hsdev =NULL ) {dev_err (&ofdev->dev,"kmalloc failed for hsdev\n" ); err = -ENOMEM ; - goto error_out; + goto error;Why not just:
return err;
If some resource allocation is added before this line in future then "return err" should be changed. With goto the single cleanup is just added to the end of the function.
Thanks,
Signature · 1 line
Vasiliy
Hello.
Quoted 7 lines · I wrote:
Quoted 5 lines
Free all allocated resources on error path.
Signed-off-by Vasiliy Kulikov <[email protected]>---
I cannot compile this driver at all, so it is not tested.I can at least compile-test the patch...
No new errors/warnings are added by the patch.
WBR, Sergei
Hello.
Quoted 9 lines · Sergei Shtylyov
Quoted 7 lines
Quoted 5 lines
Free all allocated resources on error path.
Signed-off-by Vasiliy Kulikov <[email protected]>---
I cannot compile this driver at all, so it is not tested.I can at least compile-test the patch...
No new errors/warnings are added by the patch.
Vasiliy, could you repost this patch? I'm not sure why Jeff hasn't taken
it, maybe he will now...
WBR, Sergei