linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] fix error return code
@ 2015-12-26 15:28 Julia Lawall
  2015-12-26 15:28 ` [PATCH 1/7] umem: " Julia Lawall
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: netdev
  Cc: kernel-janitors, linux-usb, linux-kernel, linux-omap,
	linux-fbdev, linux-arm-kernel

The complate semantic patch that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@ok exists@
identifier f,ret,i;
expression e;
constant c;
@@

// identify a function that returns a negative return value at least once.
f(...) {
... when any
(
return -c@i;
|
ret = -c@i;
... when != ret = e
return ret;
|
if (ret < 0) { ... return ret; }
)
... when any
}

@r exists@
identifier ret,ok.f,fn;
expression e1,e2,e3,e4,e5,e6,x;
statement S,S1;
position p1,p2,p3;
@@

// identify a case where the return variable is set to a non-negative value
// and then returned in error-handling code
f(...) {
... when any
(
if@p1 (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != \(ret = e1\|ret++\|ret--\|ret+=e1\|ret-=e1\)
    when != &ret
    when any
(
 if (<+... ret = e5 ...+>) S1
|
 if (<+... &ret ...+>) S1
|
if@p2(<+...x = fn(...)...+>)
 {
  ... when != ret = e6
      when forall
 return@p3 ret;
}
|
break;
|
x = fn(...)
... when != \(ret = e4\|ret++\|ret--\|ret+=e4\|ret-=e4\)
    when != &ret
(
 if (<+... ret = e3 ...+>) S
|
 if (<+... &ret ...+>) S
|
if@p2(<+...\(x != 0\|x < 0\|x == NULL\|IS_ERR(x)\)...+>)
 {
  ... when != ret = e2
      when forall
 return@p3 ret;
}
)
)
... when any
}

@printer depends on r@
position p;
identifier ok.f,pr;
constant char [] c;
@@

f(...) { <...pr@p(...,c,...)...> }

@bad0 exists@
identifier r.ret,ok.f,g != {ERR_PTR,IS_ERR};
position p != printer.p;
@@

f(...) { ... when any
g@p(...,ret,...)
... when any
 }

@bad depends on !bad0 exists@
position r.p1,r.p2;
statement S1,S2;
identifier r.ret;
expression e1;
@@

// ignore the above if there is some path where the variable is set to
// something else
(
if@p1 (\(ret < 0\|ret != 0\)) S1
|
ret@p1 = 0
)
... when any
 \(ret = e1\|ret++\|ret--\|ret+=e1\|ret-=e1\|&ret\)
... when any
if@p2(...) S2

@bad1 depends on !bad0 && !bad exists@
position r.p2;
statement S2;
identifier r.ret;
expression e1;
constant c;
@@

ret = -c
... when != \(ret = e1\|ret++\|ret--\|ret+=e1\|ret-=e1\)
    when != &ret
    when any
if@p2(...) S2

@bad2 depends on !bad0 && !bad && !bad1 exists@
position r.p1,r.p2;
identifier r.ret;
expression e1;
statement S2;
constant c;
@@

// likewise ignore it if there has been an intervening return
ret@p1 = 0
... when != if (...) { ... ret = e1 ... return ret; }
    when != if (...) { ... return -c; }
    when any
if@p2(...) S2

@script:python depends on !bad0 && !bad && !bad1 && !bad2@
p1 << r.p1;
p2 << r.p2;
p3 << r.p3;
@@

cocci.print_main("",p1)
cocci.print_secs("",p2)
cocci.print_secs("",p3)
// </smpl>

---

 drivers/block/rsxx/core.c                                     |    1 
 drivers/block/umem.c                                          |    5 +++-
 drivers/cdrom/gdrom.c                                         |    8 +++++-
 drivers/net/ethernet/ti/cpsw.c                                |    8 +++++-
 drivers/soc/ti/knav_qmss_queue.c                              |    1 
 drivers/soc/ti/wkup_m3_ipc.c                                  |    1 
 drivers/usb/gadget/legacy/acm_ms.c                            |    4 ++-
 drivers/usb/gadget/legacy/audio.c                             |    4 ++-
 drivers/usb/gadget/legacy/cdc2.c                              |    4 ++-
 drivers/usb/gadget/legacy/ether.c                             |    4 ++-
 drivers/usb/gadget/legacy/hid.c                               |    4 ++-
 drivers/usb/gadget/legacy/mass_storage.c                      |    4 ++-
 drivers/usb/gadget/legacy/ncm.c                               |    4 ++-
 drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c |   12 +++++++---
 14 files changed, 49 insertions(+), 15 deletions(-)

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

* [PATCH 1/7] umem: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  2015-12-26 15:28 ` [PATCH 2/7] gdrom: " Julia Lawall
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/block/umem.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 7939b9f..873e9fe 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -883,6 +883,7 @@ static int mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	if (card->mm_pages[0].desc == NULL ||
 	    card->mm_pages[1].desc == NULL) {
 		dev_printk(KERN_ERR, &card->dev->dev, "alloc failed\n");
+		ret = -ENOMEM;
 		goto failed_alloc;
 	}
 	reset_page(&card->mm_pages[0]);
@@ -893,8 +894,10 @@ static int mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	card->biotail = &card->bio;
 
 	card->queue = blk_alloc_queue(GFP_KERNEL);
-	if (!card->queue)
+	if (!card->queue) {
+		ret = -ENOMEM;
 		goto failed_alloc;
+	}
 
 	blk_queue_make_request(card->queue, mm_make_request);
 	card->queue->queue_lock = &card->lock;


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

* [PATCH 2/7] gdrom: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
  2015-12-26 15:28 ` [PATCH 1/7] umem: " Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  2015-12-26 15:28 ` [PATCH 3/7] omapfb: " Julia Lawall
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/cdrom/gdrom.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 584bc31..46ecd95 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -807,16 +807,20 @@ static int probe_gdrom(struct platform_device *devptr)
 	if (err)
 		goto probe_fail_cmdirq_register;
 	gd.gdrom_rq = blk_init_queue(gdrom_request, &gdrom_lock);
-	if (!gd.gdrom_rq)
+	if (!gd.gdrom_rq) {
+		err = -ENOMEM;
 		goto probe_fail_requestq;
+	}
 
 	err = probe_gdrom_setupqueue();
 	if (err)
 		goto probe_fail_toc;
 
 	gd.toc = kzalloc(sizeof(struct gdromtoc), GFP_KERNEL);
-	if (!gd.toc)
+	if (!gd.toc) {
+		err = -ENOMEM;
 		goto probe_fail_toc;
+	}
 	add_disk(gd.disk);
 	return 0;
 


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

* [PATCH 3/7] omapfb: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
  2015-12-26 15:28 ` [PATCH 1/7] umem: " Julia Lawall
  2015-12-26 15:28 ` [PATCH 2/7] gdrom: " Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  2015-12-29  9:06   ` Tomi Valkeinen
  2015-12-26 15:28 ` [PATCH 4/7] usb: gadget: legacy: " Julia Lawall
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: Tomi Valkeinen
  Cc: kernel-janitors, Jean-Christophe Plagniol-Villard, linux-omap,
	linux-fbdev, linux-kernel

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c |   12 +++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c
index 677e254..fc4cfa9 100644
--- a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c
+++ b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c
@@ -241,22 +241,28 @@ static int tpd_probe(struct platform_device *pdev)
 
 	gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,
 		GPIOD_OUT_LOW);
-	if (IS_ERR(gpio))
+	if (IS_ERR(gpio)) {
+		r = PTR_ERR(gpio);
 		goto err_gpio;
+	}
 
 	ddata->ct_cp_hpd_gpio = gpio;
 
 	gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,
 		GPIOD_OUT_LOW);
-	if (IS_ERR(gpio))
+	if (IS_ERR(gpio)) {
+		r = PTR_ERR(gpio);
 		goto err_gpio;
+	}
 
 	ddata->ls_oe_gpio = gpio;
 
 	gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2,
 		GPIOD_IN);
-	if (IS_ERR(gpio))
+	if (IS_ERR(gpio)) {
+		r = PTR_ERR(gpio);
 		goto err_gpio;
+	}
 
 	ddata->hpd_gpio = gpio;
 


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

* [PATCH 4/7] usb: gadget: legacy: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
                   ` (2 preceding siblings ...)
  2015-12-26 15:28 ` [PATCH 3/7] omapfb: " Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  2015-12-26 15:28 ` [PATCH 5/7] rsxx: " Julia Lawall
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: kernel-janitors, Greg Kroah-Hartman, linux-usb, linux-kernel

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/usb/gadget/legacy/acm_ms.c       |    4 +++-
 drivers/usb/gadget/legacy/audio.c        |    4 +++-
 drivers/usb/gadget/legacy/cdc2.c         |    4 +++-
 drivers/usb/gadget/legacy/ether.c        |    4 +++-
 drivers/usb/gadget/legacy/hid.c          |    4 +++-
 drivers/usb/gadget/legacy/mass_storage.c |    4 +++-
 drivers/usb/gadget/legacy/ncm.c          |    4 +++-
 7 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/legacy/acm_ms.c b/drivers/usb/gadget/legacy/acm_ms.c
index c16089e..2679264 100644
--- a/drivers/usb/gadget/legacy/acm_ms.c
+++ b/drivers/usb/gadget/legacy/acm_ms.c
@@ -211,8 +211,10 @@ static int acm_ms_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail_string_ids;
+		}
 		usb_otg_descriptor_init(gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c
index 5d7b3c6..f61936b 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -249,8 +249,10 @@ static int audio_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail;
+		}
 		usb_otg_descriptor_init(cdev->gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
diff --git a/drivers/usb/gadget/legacy/cdc2.c b/drivers/usb/gadget/legacy/cdc2.c
index 51c0868..94261a1 100644
--- a/drivers/usb/gadget/legacy/cdc2.c
+++ b/drivers/usb/gadget/legacy/cdc2.c
@@ -183,8 +183,10 @@ static int cdc_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail1;
+		}
 		usb_otg_descriptor_init(gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
diff --git a/drivers/usb/gadget/legacy/ether.c b/drivers/usb/gadget/legacy/ether.c
index 25a2c2e..3396e71 100644
--- a/drivers/usb/gadget/legacy/ether.c
+++ b/drivers/usb/gadget/legacy/ether.c
@@ -407,8 +407,10 @@ static int eth_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail1;
+		}
 		usb_otg_descriptor_init(gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
index a71a884..cccbb94 100644
--- a/drivers/usb/gadget/legacy/hid.c
+++ b/drivers/usb/gadget/legacy/hid.c
@@ -175,8 +175,10 @@ static int hid_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto put;
+		}
 		usb_otg_descriptor_init(gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
diff --git a/drivers/usb/gadget/legacy/mass_storage.c b/drivers/usb/gadget/legacy/mass_storage.c
index e61af53..93f2b8f 100644
--- a/drivers/usb/gadget/legacy/mass_storage.c
+++ b/drivers/usb/gadget/legacy/mass_storage.c
@@ -200,8 +200,10 @@ static int msg_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail_string_ids;
+		}
 		usb_otg_descriptor_init(cdev->gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;
diff --git a/drivers/usb/gadget/legacy/ncm.c b/drivers/usb/gadget/legacy/ncm.c
index 0aba682..d71e368 100644
--- a/drivers/usb/gadget/legacy/ncm.c
+++ b/drivers/usb/gadget/legacy/ncm.c
@@ -162,8 +162,10 @@ static int gncm_bind(struct usb_composite_dev *cdev)
 		struct usb_descriptor_header *usb_desc;
 
 		usb_desc = usb_otg_descriptor_alloc(gadget);
-		if (!usb_desc)
+		if (!usb_desc) {
+			status = -ENOMEM;
 			goto fail;
+		}
 		usb_otg_descriptor_init(gadget, usb_desc);
 		otg_desc[0] = usb_desc;
 		otg_desc[1] = NULL;


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

* [PATCH 5/7] rsxx: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
                   ` (3 preceding siblings ...)
  2015-12-26 15:28 ` [PATCH 4/7] usb: gadget: legacy: " Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  2015-12-26 15:28 ` [PATCH 6/7] drivers: net: cpsw: " Julia Lawall
  2015-12-26 15:28 ` [PATCH 7/7] soc: ti: " Julia Lawall
  6 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: Joshua Morris; +Cc: kernel-janitors, Philip Kelleher, linux-kernel

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/block/rsxx/core.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index d8b2488..3801721 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -893,6 +893,7 @@ static int rsxx_pci_probe(struct pci_dev *dev,
 	card->event_wq = create_singlethread_workqueue(DRIVER_NAME"_event");
 	if (!card->event_wq) {
 		dev_err(CARD_TO_DEV(card), "Failed card event setup.\n");
+		st = -ENOMEM;
 		goto failed_event_handler;
 	}
 


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

* [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
                   ` (4 preceding siblings ...)
  2015-12-26 15:28 ` [PATCH 5/7] rsxx: " Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  2015-12-26 17:36   ` Sergei Shtylyov
  2015-12-26 15:28 ` [PATCH 7/7] soc: ti: " Julia Lawall
  6 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: netdev; +Cc: kernel-janitors, linux-kernel

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/net/ethernet/ti/cpsw.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 3409e80..6a76992 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device *pdev)
 
 	/* RX IRQ */
 	irq = platform_get_irq(pdev, 1);
-	if (irq < 0)
+	if (irq < 0) {
+		ret = -ENOENT;
 		goto clean_ale_ret;
+	}
 
 	priv->irqs_table[0] = irq;
 	ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt,
@@ -2461,8 +2463,10 @@ static int cpsw_probe(struct platform_device *pdev)
 
 	/* TX IRQ */
 	irq = platform_get_irq(pdev, 2);
-	if (irq < 0)
+	if (irq < 0) {
+		ret = -ENOENT;
 		goto clean_ale_ret;
+	}
 
 	priv->irqs_table[1] = irq;
 	ret = devm_request_irq(&pdev->dev, irq, cpsw_tx_interrupt,


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

* [PATCH 7/7] soc: ti: fix error return code
  2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
                   ` (5 preceding siblings ...)
  2015-12-26 15:28 ` [PATCH 6/7] drivers: net: cpsw: " Julia Lawall
@ 2015-12-26 15:28 ` Julia Lawall
  6 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 15:28 UTC (permalink / raw)
  To: Santosh Shilimkar; +Cc: kernel-janitors, linux-kernel, linux-arm-kernel

Return a negative error code on failure.

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

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
 drivers/soc/ti/knav_qmss_queue.c |    1 +
 drivers/soc/ti/wkup_m3_ipc.c     |    1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
index 8c03a80..b401a28 100644
--- a/drivers/soc/ti/knav_qmss_queue.c
+++ b/drivers/soc/ti/knav_qmss_queue.c
@@ -1787,6 +1787,7 @@ static int knav_queue_probe(struct platform_device *pdev)
 	regions =  of_get_child_by_name(node, "descriptor-regions");
 	if (!regions) {
 		dev_err(dev, "descriptor-regions not specified\n");
+		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_queue_setup_regions(kdev, regions);
diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c
index 8823cc8..5bb3760 100644
--- a/drivers/soc/ti/wkup_m3_ipc.c
+++ b/drivers/soc/ti/wkup_m3_ipc.c
@@ -459,6 +459,7 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
 
 	if (IS_ERR(task)) {
 		dev_err(dev, "can't create rproc_boot thread\n");
+		ret = PTR_ERR(task);
 		goto err_put_rproc;
 	}
 


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

* Re: [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 15:28 ` [PATCH 6/7] drivers: net: cpsw: " Julia Lawall
@ 2015-12-26 17:36   ` Sergei Shtylyov
  2015-12-26 17:40     ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: Sergei Shtylyov @ 2015-12-26 17:36 UTC (permalink / raw)
  To: Julia Lawall, netdev; +Cc: kernel-janitors, linux-kernel

Hello.

On 12/26/2015 6:28 PM, Julia Lawall wrote:

> Return a negative error code on failure.
>
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> identifier ret; expression e1,e2;
> @@
> (
> if (\(ret < 0\|ret != 0\))
>   { ... return ret; }
> |
> ret = 0
> )
> ... when != ret = e1
>      when != &ret
> *if(...)
> {
>    ... when != ret = e2
>        when forall
>   return ret;
> }
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>   drivers/net/ethernet/ti/cpsw.c |    8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
> index 3409e80..6a76992 100644
> --- a/drivers/net/ethernet/ti/cpsw.c
> +++ b/drivers/net/ethernet/ti/cpsw.c
> @@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device *pdev)
>
>   	/* RX IRQ */
>   	irq = platform_get_irq(pdev, 1);
> -	if (irq < 0)
> +	if (irq < 0) {
> +		ret = -ENOENT;

    Why not just propagate an error returned by that function?

>   		goto clean_ale_ret;
> +	}
>
>   	priv->irqs_table[0] = irq;
>   	ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt,
> @@ -2461,8 +2463,10 @@ static int cpsw_probe(struct platform_device *pdev)
>
>   	/* TX IRQ */
>   	irq = platform_get_irq(pdev, 2);
> -	if (irq < 0)
> +	if (irq < 0) {
> +		ret = -ENOENT;

    Likewise?

[...]

MBR, Sergei


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

* Re: [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 17:36   ` Sergei Shtylyov
@ 2015-12-26 17:40     ` Julia Lawall
  2015-12-26 17:50       ` Sergei Shtylyov
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 17:40 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: netdev, kernel-janitors, linux-kernel

> > diff --git a/drivers/net/ethernet/ti/cpsw.c
> > b/drivers/net/ethernet/ti/cpsw.c
> > index 3409e80..6a76992 100644
> > --- a/drivers/net/ethernet/ti/cpsw.c
> > +++ b/drivers/net/ethernet/ti/cpsw.c
> > @@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device *pdev)
> > 
> >   	/* RX IRQ */
> >   	irq = platform_get_irq(pdev, 1);
> > -	if (irq < 0)
> > +	if (irq < 0) {
> > +		ret = -ENOENT;
> 
>    Why not just propagate an error returned by that function?

OK, I did what was done a few lines before in the same function:

        ndev->irq = platform_get_irq(pdev, 1);
        if (ndev->irq < 0) {
		dev_err(priv->dev, "error getting irq resource\n");
                ret = -ENOENT;
                goto clean_ale_ret;
        }

Maybe they should all be changed?

julia

> >   		goto clean_ale_ret;
> > +	}
> > 
> >   	priv->irqs_table[0] = irq;
> >   	ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt,
> > @@ -2461,8 +2463,10 @@ static int cpsw_probe(struct platform_device *pdev)
> > 
> >   	/* TX IRQ */
> >   	irq = platform_get_irq(pdev, 2);
> > -	if (irq < 0)
> > +	if (irq < 0) {
> > +		ret = -ENOENT;
> 
>    Likewise?
> 
> [...]
> 
> MBR, Sergei
> 
> 

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

* Re: [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 17:40     ` Julia Lawall
@ 2015-12-26 17:50       ` Sergei Shtylyov
  2015-12-26 19:12         ` [PATCH 6/7 v2] " Julia Lawall
  2015-12-26 19:51         ` [PATCH 6/7] " Sergei Shtylyov
  0 siblings, 2 replies; 18+ messages in thread
From: Sergei Shtylyov @ 2015-12-26 17:50 UTC (permalink / raw)
  To: Julia Lawall; +Cc: netdev, kernel-janitors, linux-kernel

On 12/26/2015 8:40 PM, Julia Lawall wrote:

>>> diff --git a/drivers/net/ethernet/ti/cpsw.c
>>> b/drivers/net/ethernet/ti/cpsw.c
>>> index 3409e80..6a76992 100644
>>> --- a/drivers/net/ethernet/ti/cpsw.c
>>> +++ b/drivers/net/ethernet/ti/cpsw.c
>>> @@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device *pdev)
>>>
>>>    	/* RX IRQ */
>>>    	irq = platform_get_irq(pdev, 1);
>>> -	if (irq < 0)
>>> +	if (irq < 0) {
>>> +		ret = -ENOENT;
>>
>>     Why not just propagate an error returned by that function?
>
> OK, I did what was done a few lines before in the same function:
>
>          ndev->irq = platform_get_irq(pdev, 1);
>          if (ndev->irq < 0) {
> 		dev_err(priv->dev, "error getting irq resource\n");
>                  ret = -ENOENT;
>                  goto clean_ale_ret;
>          }
>
> Maybe they should all be changed?

    Yeah, I'd vote for it. I'm seeing no sense in overriding an actual error.

[...]

> julia

MBR, Sergei


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

* [PATCH 6/7 v2] drivers: net: cpsw: fix error return code
  2015-12-26 17:50       ` Sergei Shtylyov
@ 2015-12-26 19:12         ` Julia Lawall
  2015-12-26 19:51         ` [PATCH 6/7] " Sergei Shtylyov
  1 sibling, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 19:12 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: netdev, kernel-janitors, linux-kernel

Propagate the return value of platform_get_irq on failure.

A simplified version of the semantic match that finds the two cases where
no error code is returned at all is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
identifier ret; expression e1,e2;
@@
(
if (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

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

---
v2: propagate platform_get_irq return value, at all calls

 drivers/net/ethernet/ti/cpsw.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 3409e80..34ce7dc 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2427,7 +2427,7 @@ static int cpsw_probe(struct platform_device *pdev)
 	ndev->irq = platform_get_irq(pdev, 1);
 	if (ndev->irq < 0) {
 		dev_err(priv->dev, "error getting irq resource\n");
-		ret = -ENOENT;
+		ret = ndev->irq;
 		goto clean_ale_ret;
 	}
 
@@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device *pdev)
 
 	/* RX IRQ */
 	irq = platform_get_irq(pdev, 1);
-	if (irq < 0)
+	if (irq < 0) {
+		ret = irq;
 		goto clean_ale_ret;
+	}
 
 	priv->irqs_table[0] = irq;
 	ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt,
@@ -2461,8 +2463,10 @@ static int cpsw_probe(struct platform_device *pdev)
 
 	/* TX IRQ */
 	irq = platform_get_irq(pdev, 2);
-	if (irq < 0)
+	if (irq < 0) {
+		ret = irq;
 		goto clean_ale_ret;
+	}
 
 	priv->irqs_table[1] = irq;
 	ret = devm_request_irq(&pdev->dev, irq, cpsw_tx_interrupt,

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

* Re: [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 17:50       ` Sergei Shtylyov
  2015-12-26 19:12         ` [PATCH 6/7 v2] " Julia Lawall
@ 2015-12-26 19:51         ` Sergei Shtylyov
  2015-12-26 20:07           ` Julia Lawall
  1 sibling, 1 reply; 18+ messages in thread
From: Sergei Shtylyov @ 2015-12-26 19:51 UTC (permalink / raw)
  To: Julia Lawall; +Cc: netdev, kernel-janitors, linux-kernel

Hello.

On 12/26/2015 08:50 PM, Sergei Shtylyov wrote:

>>>> diff --git a/drivers/net/ethernet/ti/cpsw.c
>>>> b/drivers/net/ethernet/ti/cpsw.c
>>>> index 3409e80..6a76992 100644
>>>> --- a/drivers/net/ethernet/ti/cpsw.c
>>>> +++ b/drivers/net/ethernet/ti/cpsw.c
>>>> @@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device *pdev)
>>>>
>>>>        /* RX IRQ */
>>>>        irq = platform_get_irq(pdev, 1);
>>>> -    if (irq < 0)
>>>> +    if (irq < 0) {
>>>> +        ret = -ENOENT;
>>>
>>>     Why not just propagate an error returned by that function?
>>
>> OK, I did what was done a few lines before in the same function:
>>
>>          ndev->irq = platform_get_irq(pdev, 1);
>>          if (ndev->irq < 0) {
>>         dev_err(priv->dev, "error getting irq resource\n");
>>                  ret = -ENOENT;
>>                  goto clean_ale_ret;
>>          }
>>
>> Maybe they should all be changed?
>
>     Yeah, I'd vote for it. I'm seeing no sense in overriding an actual error.

    Hm, I decided to check drivers/base/dd.c and I think I maybe know the 
reason now: -ENXIO, usually returned by platform_get_irq(), is silently 
"swallowed" by really_probe(); to be precise, -ENODEV and -ENXIO are only 
reported with pr_debug(), while -ENOENT causes printk(KERN_WARNING, ...)...

> [...]
>
>> julia

MBR, Sergei


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

* Re: [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 19:51         ` [PATCH 6/7] " Sergei Shtylyov
@ 2015-12-26 20:07           ` Julia Lawall
  2015-12-26 20:11             ` Sergei Shtylyov
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2015-12-26 20:07 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: netdev, kernel-janitors, linux-kernel

On Sat, 26 Dec 2015, Sergei Shtylyov wrote:

> Hello.
> 
> On 12/26/2015 08:50 PM, Sergei Shtylyov wrote:
> 
> > > > > diff --git a/drivers/net/ethernet/ti/cpsw.c
> > > > > b/drivers/net/ethernet/ti/cpsw.c
> > > > > index 3409e80..6a76992 100644
> > > > > --- a/drivers/net/ethernet/ti/cpsw.c
> > > > > +++ b/drivers/net/ethernet/ti/cpsw.c
> > > > > @@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device
> > > > > *pdev)
> > > > > 
> > > > >        /* RX IRQ */
> > > > >        irq = platform_get_irq(pdev, 1);
> > > > > -    if (irq < 0)
> > > > > +    if (irq < 0) {
> > > > > +        ret = -ENOENT;
> > > > 
> > > >     Why not just propagate an error returned by that function?
> > > 
> > > OK, I did what was done a few lines before in the same function:
> > > 
> > >          ndev->irq = platform_get_irq(pdev, 1);
> > >          if (ndev->irq < 0) {
> > >         dev_err(priv->dev, "error getting irq resource\n");
> > >                  ret = -ENOENT;
> > >                  goto clean_ale_ret;
> > >          }
> > > 
> > > Maybe they should all be changed?
> > 
> >     Yeah, I'd vote for it. I'm seeing no sense in overriding an actual
> > error.
> 
>    Hm, I decided to check drivers/base/dd.c and I think I maybe know the
> reason now: -ENXIO, usually returned by platform_get_irq(), is silently
> "swallowed" by really_probe(); to be precise, -ENODEV and -ENXIO are only
> reported with pr_debug(), while -ENOENT causes printk(KERN_WARNING, ...)...

Sorry, I'm confused...  What should it be?  v1 or v2?  Here are the counts 
of the different constants returned on failure of platform_get_irq:

ENODEV: 84
ENXIO: 67
EINVAL: 61
ENOENT: 29
EBUSY: 11
EIO: 2
EPROBE_DEFER: 1

julia

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

* Re: [PATCH 6/7] drivers: net: cpsw: fix error return code
  2015-12-26 20:07           ` Julia Lawall
@ 2015-12-26 20:11             ` Sergei Shtylyov
  0 siblings, 0 replies; 18+ messages in thread
From: Sergei Shtylyov @ 2015-12-26 20:11 UTC (permalink / raw)
  To: Julia Lawall; +Cc: netdev, kernel-janitors, linux-kernel

On 12/26/2015 11:07 PM, Julia Lawall wrote:

>>>>>> diff --git a/drivers/net/ethernet/ti/cpsw.c
>>>>>> b/drivers/net/ethernet/ti/cpsw.c
>>>>>> index 3409e80..6a76992 100644
>>>>>> --- a/drivers/net/ethernet/ti/cpsw.c
>>>>>> +++ b/drivers/net/ethernet/ti/cpsw.c
>>>>>> @@ -2448,8 +2448,10 @@ static int cpsw_probe(struct platform_device
>>>>>> *pdev)
>>>>>>
>>>>>>         /* RX IRQ */
>>>>>>         irq = platform_get_irq(pdev, 1);
>>>>>> -    if (irq < 0)
>>>>>> +    if (irq < 0) {
>>>>>> +        ret = -ENOENT;
>>>>>
>>>>>      Why not just propagate an error returned by that function?
>>>>
>>>> OK, I did what was done a few lines before in the same function:
>>>>
>>>>           ndev->irq = platform_get_irq(pdev, 1);
>>>>           if (ndev->irq < 0) {
>>>>          dev_err(priv->dev, "error getting irq resource\n");
>>>>                   ret = -ENOENT;
>>>>                   goto clean_ale_ret;
>>>>           }
>>>>
>>>> Maybe they should all be changed?
>>>
>>>      Yeah, I'd vote for it. I'm seeing no sense in overriding an actual
>>> error.
>>
>>     Hm, I decided to check drivers/base/dd.c and I think I maybe know the
>> reason now: -ENXIO, usually returned by platform_get_irq(), is silently
>> "swallowed" by really_probe(); to be precise, -ENODEV and -ENXIO are only
>> reported with pr_debug(), while -ENOENT causes printk(KERN_WARNING, ...)...

> Sorry, I'm confused...  What should it be?  v1 or v2?  Here are the counts
> of the different constants returned on failure of platform_get_irq:

    I was somewhat confused myself but then I remembered about the deferred 
probing -- overriding error code basically just disables it in this case.

> ENODEV: 84
> ENXIO: 67

   Those 2 totally make no sense. :-)

> EINVAL: 61
> ENOENT: 29
> EBUSY: 11

    Hm...

> EIO: 2
> EPROBE_DEFER: 1

    Hm, and that last one is unconditional?

> julia

MBR, Sergei


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

* Re: [PATCH 3/7] omapfb: fix error return code
  2015-12-26 15:28 ` [PATCH 3/7] omapfb: " Julia Lawall
@ 2015-12-29  9:06   ` Tomi Valkeinen
  0 siblings, 0 replies; 18+ messages in thread
From: Tomi Valkeinen @ 2015-12-29  9:06 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Jean-Christophe Plagniol-Villard, linux-omap,
	linux-fbdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1947 bytes --]


On 26/12/15 17:28, Julia Lawall wrote:
> Return a negative error code on failure.
> 
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> identifier ret; expression e1,e2;
> @@
> (
> if (\(ret < 0\|ret != 0\))
>  { ... return ret; }
> |
> ret = 0
> )
> ... when != ret = e1
>     when != &ret
> *if(...)
> {
>   ... when != ret = e2
>       when forall
>  return ret;
> }
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
>  drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c |   12 +++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c
> index 677e254..fc4cfa9 100644
> --- a/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c
> +++ b/drivers/video/fbdev/omap2/omapfb/displays/encoder-tpd12s015.c
> @@ -241,22 +241,28 @@ static int tpd_probe(struct platform_device *pdev)
>  
>  	gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,
>  		GPIOD_OUT_LOW);
> -	if (IS_ERR(gpio))
> +	if (IS_ERR(gpio)) {
> +		r = PTR_ERR(gpio);
>  		goto err_gpio;
> +	}
>  
>  	ddata->ct_cp_hpd_gpio = gpio;
>  
>  	gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,
>  		GPIOD_OUT_LOW);
> -	if (IS_ERR(gpio))
> +	if (IS_ERR(gpio)) {
> +		r = PTR_ERR(gpio);
>  		goto err_gpio;
> +	}
>  
>  	ddata->ls_oe_gpio = gpio;
>  
>  	gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2,
>  		GPIOD_IN);
> -	if (IS_ERR(gpio))
> +	if (IS_ERR(gpio)) {
> +		r = PTR_ERR(gpio);
>  		goto err_gpio;
> +	}
>  
>  	ddata->hpd_gpio = gpio;

Thanks. Looks like recent changes to the driver break the error
handling. I'll just drop those patches from my for-next branch, and let
the author fix the patches.

 Tomi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [PATCH 0/7] fix error return code
@ 2014-11-20 17:33 Julia Lawall
  0 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2014-11-20 17:33 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: kernel-janitors, linux-serial, linux-kernel, linux-usb, linux-omap

The complate semantic patch that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@ok exists@
identifier f,ret,i;
expression e;
constant c;
@@

// identify a function that returns a negative return value at least once.
f(...) {
... when any
(
return -c@i;
|
ret = -c@i;
... when != ret = e
return ret;
|
if (ret < 0) { ... return ret; }
)
... when any
}

@r exists@
identifier ret,ok.f,fn;
expression e1,e2,e3,e4,e5,e6,x;
statement S,S1;
position p1,p2,p3;
@@

// identify a case where the return variable is set to a non-negative value
// and then returned in error-handling code
f(...) {
... when any
(
if@p1 (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != \(ret = e1\|ret++\|ret--\|ret+=e1\|ret-=e1\)
    when != &ret
    when any
(
 if (<+... ret = e5 ...+>) S1
|
 if (<+... &ret ...+>) S1
|
if@p2(<+...x = fn(...)...+>)
 {
  ... when != ret = e6
      when forall
 return@p3 ret;
}
|
break;
|
x = fn(...)
... when != \(ret = e4\|ret++\|ret--\|ret+=e4\|ret-=e4\)
    when != &ret
(
 if (<+... ret = e3 ...+>) S
|
 if (<+... &ret ...+>) S
|
if@p2(<+...\(x != 0\|x < 0\|x == NULL\|IS_ERR(x)\)...+>)
 {
  ... when != ret = e2
      when forall
 return@p3 ret;
}
)
)
... when any
}

@printer depends on r@
position p;
identifier ok.f,pr;
constant char [] c;
@@

f(...) { <...pr@p(...,c,...)...> }

@bad0 exists@
identifier r.ret,ok.f,g != {ERR_PTR,IS_ERR};
position p != printer.p;
@@

f(...) { ... when any
g@p(...,ret,...)
... when any
 }

@bad depends on !bad0 exists@
position r.p1,r.p2;
statement S1,S2;
identifier r.ret;
expression e1;
@@

// ignore the above if there is some path where the variable is set to
// something else
(
if@p1 (\(ret < 0\|ret != 0\)) S1
|
ret@p1 = 0
)
... when any
 \(ret = e1\|ret++\|ret--\|ret+=e1\|ret-=e1\|&ret\)
... when any
if@p2(...) S2

@bad1 depends on !bad0 && !bad exists@
position r.p2;
statement S2;
identifier r.ret;
expression e1;
constant c;
@@

ret = -c
... when != \(ret = e1\|ret++\|ret--\|ret+=e1\|ret-=e1\)
    when != &ret
    when any
if@p2(...) S2

@bad2 depends on !bad0 && !bad && !bad1 exists@
position r.p1,r.p2;
identifier r.ret;
expression e1;
statement S2;
constant c;
@@

// likewise ignore it if there has been an intervening return
ret@p1 = 0
... when != if (...) { ... ret = e1 ... return ret; }
    when != if (...) { ... return -c; }
    when any
if@p2(...) S2


@script:python depends on !bad0 && !bad && !bad1 && !bad2@
p1 << r.p1;
p2 << r.p2;
p3 << r.p3;
@@

cocci.print_main("",p1)
cocci.print_secs("",p2)
cocci.print_secs("",p3)

// </smpl>


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

* [PATCH 0/7] fix error return code
@ 2012-08-29 16:49 Julia Lawall
  0 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2012-08-29 16:49 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

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

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

// <smpl>
@ok exists@
identifier f,ret,i;
expression e;
constant c;
@@

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

@r exists@
identifier ret,l,ok.f;
expression e1,e2,e3;
statement S;
position p1,p2,p3;
@@

f(...) {
... when any
(
if@p1 (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
    when != &ret
(
 if (<+... ret = e3 ...+>) S
|
 if (<+... &ret ...+>) S
|
if@p2(...)
 {
  ... when != ret = e2
      when forall
 return@p3 ret;
}
)
... when any
}

@bad exists@
position r.p1,r.p2;
statement S1,S2;
identifier r.ret;
expression e1;
@@

(
if@p1 (\(ret < 0\|ret != 0\)) S1
|
ret@p1 = 0
)
... when any
ret = e1
... when any
if@p2(...) S2

@bad2@
position r.p1,r.p2;
identifier r.ret;
expression e1;
statement S2;
@@

ret@p1 = 0
... when != if (...) { ... ret = e1 ... return ret; }
    when any
if@p2(...) S2


@script:python depends on !bad && !bad2@
p1 << r.p1;
p2 << r.p2;
p3 << r.p3;
@@

cocci.print_main("",p1)
cocci.print_secs("",p2)
cocci.print_secs("",p3)
// </smpl>


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

end of thread, other threads:[~2015-12-29  9:06 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-26 15:28 [PATCH 0/7] fix error return code Julia Lawall
2015-12-26 15:28 ` [PATCH 1/7] umem: " Julia Lawall
2015-12-26 15:28 ` [PATCH 2/7] gdrom: " Julia Lawall
2015-12-26 15:28 ` [PATCH 3/7] omapfb: " Julia Lawall
2015-12-29  9:06   ` Tomi Valkeinen
2015-12-26 15:28 ` [PATCH 4/7] usb: gadget: legacy: " Julia Lawall
2015-12-26 15:28 ` [PATCH 5/7] rsxx: " Julia Lawall
2015-12-26 15:28 ` [PATCH 6/7] drivers: net: cpsw: " Julia Lawall
2015-12-26 17:36   ` Sergei Shtylyov
2015-12-26 17:40     ` Julia Lawall
2015-12-26 17:50       ` Sergei Shtylyov
2015-12-26 19:12         ` [PATCH 6/7 v2] " Julia Lawall
2015-12-26 19:51         ` [PATCH 6/7] " Sergei Shtylyov
2015-12-26 20:07           ` Julia Lawall
2015-12-26 20:11             ` Sergei Shtylyov
2015-12-26 15:28 ` [PATCH 7/7] soc: ti: " Julia Lawall
  -- strict thread matches above, loose matches on Subject: below --
2014-11-20 17:33 [PATCH 0/7] " Julia Lawall
2012-08-29 16:49 Julia Lawall

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).