linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] fix error return code
@ 2012-08-14  6:47 Julia Lawall
  2012-08-14  6:47 ` [PATCH 1/5] drivers/usb/gadget/s3c-hsotg.c: " Julia Lawall
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Julia Lawall @ 2012-08-14  6:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: kernel-janitors, linux-kernel

These patches fix cases where the return code appears to be unintentially 0.

The complete semantic match that finds the problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier f;
expression ret,e;
constant C;
@@

f(...) { <+...
(
return -C;
|
ret = -C
... when != ret = e
return ret;
|
if (ret < 0) { ... return ret; }
)
...+> }

@s@
identifier r.f,ret;
@@

f(...) { <+... return ret; ...+> }

@@
identifier r.f,s.ret;
expression e,e1,e2,e3,e4,x;
@@

f(...) { <+...
(
if (\(ret != 0\|ret < 0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
    when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
...+> }
// </smpl>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] drivers/usb/gadget/s3c-hsotg.c: fix error return code
  2012-08-14  6:47 [PATCH 0/5] fix error return code Julia Lawall
@ 2012-08-14  6:47 ` Julia Lawall
  2012-08-14  6:47 ` [PATCH 2/5] drivers/tty/moxa.c: " Julia Lawall
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2012-08-14  6:47 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: kernel-janitors, Greg Kroah-Hartman, linux-usb, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Convert a 0 error return code to a negative one, as returned elsewhere in the
function.

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

// <smpl>
@@
identifier ret;
expression e,e1,e2,e3,e4,x;
@@

(
if (\(ret != 0\|ret < 0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
    when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/usb/gadget/s3c-hsotg.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index b13e0bb..0bb617e 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -3599,6 +3599,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
 
 	if (hsotg->num_of_eps == 0) {
 		dev_err(dev, "wrong number of EPs (zero)\n");
+		ret = -EINVAL;
 		goto err_supplies;
 	}
 
@@ -3606,6 +3607,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
 		      GFP_KERNEL);
 	if (!eps) {
 		dev_err(dev, "cannot get memory\n");
+		ret = -ENOMEM;
 		goto err_supplies;
 	}
 
@@ -3622,6 +3624,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
 						     GFP_KERNEL);
 	if (!hsotg->ctrl_req) {
 		dev_err(dev, "failed to allocate ctrl req\n");
+		ret = -ENOMEM;
 		goto err_ep_mem;
 	}
 


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/5] drivers/tty/moxa.c: fix error return code
  2012-08-14  6:47 [PATCH 0/5] fix error return code Julia Lawall
  2012-08-14  6:47 ` [PATCH 1/5] drivers/usb/gadget/s3c-hsotg.c: " Julia Lawall
@ 2012-08-14  6:47 ` Julia Lawall
  2012-08-14  6:47 ` [PATCH 3/5] drivers/usb/wusbcore/wa-hc.c: " Julia Lawall
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2012-08-14  6:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: kernel-janitors, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Convert a 0 error return code to a negative one, as returned elsewhere in the
function.

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

// <smpl>
@@
identifier ret;
expression e,e1,e2,e3,e4,x;
@@

(
if (\(ret != 0\|ret < 0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
    when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/tty/moxa.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 89cc934..8b510c5 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -967,6 +967,7 @@ static int __devinit moxa_pci_probe(struct pci_dev *pdev,
 	board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000);
 	if (board->basemem == NULL) {
 		dev_err(&pdev->dev, "can't remap io space 2\n");
+		retval = -ENOMEM;
 		goto err_reg;
 	}
 


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/5] drivers/usb/wusbcore/wa-hc.c: fix error return code
  2012-08-14  6:47 [PATCH 0/5] fix error return code Julia Lawall
  2012-08-14  6:47 ` [PATCH 1/5] drivers/usb/gadget/s3c-hsotg.c: " Julia Lawall
  2012-08-14  6:47 ` [PATCH 2/5] drivers/tty/moxa.c: " Julia Lawall
@ 2012-08-14  6:47 ` Julia Lawall
  2012-08-14  6:47 ` [PATCH 4/5] drivers/usb/host/ohci-platform.c: " Julia Lawall
  2012-08-14  6:47 ` [PATCH 5/5] drivers/usb/host/ehci-platform.c: " Julia Lawall
  4 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2012-08-14  6:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: kernel-janitors, linux-usb, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Convert a 0 error return code to a negative one, as returned elsewhere in the
function.

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

// <smpl>
@@
identifier ret;
expression e,e1,e2,e3,e4,x;
@@

(
if (\(ret != 0\|ret < 0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
    when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/usb/wusbcore/wa-hc.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c
index 9e4a924..a09b65e 100644
--- a/drivers/usb/wusbcore/wa-hc.c
+++ b/drivers/usb/wusbcore/wa-hc.c
@@ -46,8 +46,10 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
 	wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc;
 	wa->xfer_result_size = usb_endpoint_maxp(wa->dti_epd);
 	wa->xfer_result = kmalloc(wa->xfer_result_size, GFP_KERNEL);
-	if (wa->xfer_result == NULL)
+	if (wa->xfer_result == NULL) {
+		result = -ENOMEM;
 		goto error_xfer_result_alloc;
+	}
 	result = wa_nep_create(wa, iface);
 	if (result < 0) {
 		dev_err(dev, "WA-CDS: can't initialize notif endpoint: %d\n",


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/5] drivers/usb/host/ohci-platform.c: fix error return code
  2012-08-14  6:47 [PATCH 0/5] fix error return code Julia Lawall
                   ` (2 preceding siblings ...)
  2012-08-14  6:47 ` [PATCH 3/5] drivers/usb/wusbcore/wa-hc.c: " Julia Lawall
@ 2012-08-14  6:47 ` Julia Lawall
  2012-08-15 14:37   ` Alan Stern
  2012-08-14  6:47 ` [PATCH 5/5] drivers/usb/host/ehci-platform.c: " Julia Lawall
  4 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2012-08-14  6:47 UTC (permalink / raw)
  To: Alan Stern; +Cc: kernel-janitors, Greg Kroah-Hartman, linux-usb, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Convert a possibly 0 error return code to a negative one, as returned
elsewhere in the function.

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

// <smpl>
@@
identifier ret;
expression e,e1,e2,e3,e4,x;
@@

(
if (\(ret != 0\|ret < 0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
    when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/usb/host/ohci-platform.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index 10d85b9..e24ec9f 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -130,8 +130,10 @@ static int __devinit ohci_platform_probe(struct platform_device *dev)
 	}
 
 	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
-	if (!hcd->regs)
+	if (!hcd->regs) {
+		err = -ENOMEM;
 		goto err_release_region;
+	}
 	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
 	if (err)
 		goto err_iounmap;


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/5] drivers/usb/host/ehci-platform.c: fix error return code
  2012-08-14  6:47 [PATCH 0/5] fix error return code Julia Lawall
                   ` (3 preceding siblings ...)
  2012-08-14  6:47 ` [PATCH 4/5] drivers/usb/host/ohci-platform.c: " Julia Lawall
@ 2012-08-14  6:47 ` Julia Lawall
  2012-08-15 14:37   ` Alan Stern
  4 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2012-08-14  6:47 UTC (permalink / raw)
  To: Alan Stern; +Cc: kernel-janitors, Greg Kroah-Hartman, linux-usb, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Convert a possibly 0 error return code to a negative one, as returned
elsewhere in the function.

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

// <smpl>
@@
identifier ret;
expression e,e1,e2,e3,e4,x;
@@

(
if (\(ret != 0\|ret < 0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = \(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
    when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/usb/host/ehci-platform.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 91acdde..764e010 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -128,8 +128,10 @@ static int __devinit ehci_platform_probe(struct platform_device *dev)
 	}
 
 	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
-	if (!hcd->regs)
+	if (!hcd->regs) {
+		err = -ENOMEM;
 		goto err_release_region;
+	}
 	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
 	if (err)
 		goto err_iounmap;


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] drivers/usb/host/ehci-platform.c: fix error return code
  2012-08-14  6:47 ` [PATCH 5/5] drivers/usb/host/ehci-platform.c: " Julia Lawall
@ 2012-08-15 14:37   ` Alan Stern
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Stern @ 2012-08-15 14:37 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kernel-janitors, Greg Kroah-Hartman, linux-usb, linux-kernel

On Tue, 14 Aug 2012, Julia Lawall wrote:

> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Convert a possibly 0 error return code to a negative one, as returned
> elsewhere in the function.

...

> diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
> index 91acdde..764e010 100644
> --- a/drivers/usb/host/ehci-platform.c
> +++ b/drivers/usb/host/ehci-platform.c
> @@ -128,8 +128,10 @@ static int __devinit ehci_platform_probe(struct platform_device *dev)
>  	}
>  
>  	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
> -	if (!hcd->regs)
> +	if (!hcd->regs) {
> +		err = -ENOMEM;
>  		goto err_release_region;
> +	}
>  	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
>  	if (err)
>  		goto err_iounmap;

Acked-by: Alan Stern <stern@rowland.harvard.edu>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/5] drivers/usb/host/ohci-platform.c: fix error return code
  2012-08-14  6:47 ` [PATCH 4/5] drivers/usb/host/ohci-platform.c: " Julia Lawall
@ 2012-08-15 14:37   ` Alan Stern
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Stern @ 2012-08-15 14:37 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kernel-janitors, Greg Kroah-Hartman, linux-usb, linux-kernel

On Tue, 14 Aug 2012, Julia Lawall wrote:

> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Convert a possibly 0 error return code to a negative one, as returned
> elsewhere in the function.

> diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
> index 10d85b9..e24ec9f 100644
> --- a/drivers/usb/host/ohci-platform.c
> +++ b/drivers/usb/host/ohci-platform.c
> @@ -130,8 +130,10 @@ static int __devinit ohci_platform_probe(struct platform_device *dev)
>  	}
>  
>  	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
> -	if (!hcd->regs)
> +	if (!hcd->regs) {
> +		err = -ENOMEM;
>  		goto err_release_region;
> +	}
>  	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
>  	if (err)
>  		goto err_iounmap;

Acked-by: Alan Stern <stern@rowland.harvard.edu>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-15 14:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-14  6:47 [PATCH 0/5] fix error return code Julia Lawall
2012-08-14  6:47 ` [PATCH 1/5] drivers/usb/gadget/s3c-hsotg.c: " Julia Lawall
2012-08-14  6:47 ` [PATCH 2/5] drivers/tty/moxa.c: " Julia Lawall
2012-08-14  6:47 ` [PATCH 3/5] drivers/usb/wusbcore/wa-hc.c: " Julia Lawall
2012-08-14  6:47 ` [PATCH 4/5] drivers/usb/host/ohci-platform.c: " Julia Lawall
2012-08-15 14:37   ` Alan Stern
2012-08-14  6:47 ` [PATCH 5/5] drivers/usb/host/ehci-platform.c: " Julia Lawall
2012-08-15 14:37   ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).