Skip to contentSkip to conversation

sound/soc/davinci/davinci-mcasp.c: Return error code in failure

PATCH Applied Julia Lawall 3 participants 3 messages Oct 18, 2010

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

PATCH 1/2 sound/soc/davinci/davinci-mcasp.c: Return error code in failure

In this code, 0 is returned on failure, even though other failures return -ENOMEM or other similar values.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@a@
identifier alloc;
identifier ret;
constant C;
expression x;
@@

x = alloc(...);
if (x == NULL) { <+... \(ret = -C; \| return -C; \) ...+> }

@@
identifier f, a.alloc;
expression ret;
expression x,e1,e2,e3;
@@

ret = 0
... when != ret = e1
*x = alloc(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
return ret;
}
// </smpl>

---
Another call to platform_get_resource in the same function returns -ENODEV on error, so I have used that value.

 sound/soc/davinci/davinci-mcasp.c |    2 ++
 1 file changed, 2 insertions(+)
sound/soc/davinci/davinci-mcasp.c +2 -0
index c8e97dc..86918ee 100644
@@ -898,6 +898,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
 	if (!res) {
 		dev_err(&pdev->dev, "no DMA resource\n");
+		ret = -ENODEV;
 		goto err_release_region;
 	}
 
@@ -912,6 +913,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
 	if (!res) {
 		dev_err(&pdev->dev, "no DMA resource\n");
+		ret = -ENODEV;
 		goto err_release_region;
 	}
Acked-by on v1 1/2
#1 lore raw
Quoted 55 lines · Julia Lawall

In this code, 0 is returned on failure, even though other failures return -ENOMEM or other similar values.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@a@
identifier alloc;
identifier ret;
constant C;
expression x;
@@

x = alloc(...);
if (x = NULL) { <+... \(ret = -C; \| return -C; \) ...+> }

@@
identifier f, a.alloc;
expression ret;
expression x,e1,e2,e3;
@@

ret = 0
... when != ret = e1
*x = alloc(...)
... when != ret = e2
if (x = NULL) { ... when != ret = e3
return ret;
}
// </smpl>

---
Another call to platform_get_resource in the same function returns -ENODEV on error, so I have used that value.

 sound/soc/davinci/davinci-mcasp.c |    2 ++
 1 file changed, 2 insertions(+)
sound/soc/davinci/davinci-mcasp.c +1 -0
index c8e97dc..86918ee 100644
@@ -898,6 +898,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
 	if (!res) {
 		dev_err(&pdev->dev, "no DMA resource\n");
+		ret = -ENODEV;
 		goto err_release_region;
 	}
 

sound/soc/davinci/davinci-mcasp.c static int davinci_mcasp_probe(struct platform_device *pdev) · line 919

Quoted 7 lines
sound/soc/davinci/davinci-mcasp.c +1 -0
@@ -912,6 +913,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
 	if (!res) {
 		dev_err(&pdev->dev, "no DMA resource\n");
+		ret = -ENODEV;
 		goto err_release_region;
 	}
 
Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
Applied
#2 lore raw
In reply to Julia Lawall
Quoted 2 lines · Julia Lawall

In this code, 0 is returned on failure, even though other failures return -ENOMEM or other similar values.

Applied, thanks.