public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] ensure a consistent return value in error case
@ 2012-07-14 16:43 Julia Lawall
  2012-07-14 16:43 ` [PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: " Julia Lawall
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

The semantic match that finds this problem is:
(http://coccinelle.lip6.fr/)

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e2,e3,e4;
@@

ret = -C
... when != ret = e1
    when != ret += e1
    when any
if@p (...)
{
  ... when != ret = e2
      when != ret + e2
  return ret;
}
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...)
{
  ...
  return ...;
}
... when != ret = e3
    when != ret += e3
    when any
if@p (...)
{
  ... when != ret = e4
      when != ret += e4
  return ret;
}

@@
identifier r.ret;
position r.p;
statement S;
@@

(
if@p (<+...ret...+>) S
|
*if@p (...) S
)
//</smpl>


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

* [PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: ensure a consistent return value in error case
  2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
@ 2012-07-14 16:43 ` Julia Lawall
  2012-07-14 16:43 ` [PATCH 2/6] drivers/net/can/softing/softing_main.c: " Julia Lawall
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: Scott Murray; +Cc: kernel-janitors, Bjorn Helgaas, linux-pci, linux-kernel

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

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

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

---
 drivers/pci/hotplug/cpci_hotplug_core.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index 3fadf2f..2b4c412 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -225,7 +225,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
 	struct hotplug_slot *hotplug_slot;
 	struct hotplug_slot_info *info;
 	char name[SLOT_NAME_SIZE];
-	int status = -ENOMEM;
+	int status;
 	int i;
 
 	if (!(controller && bus))
@@ -237,18 +237,24 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
 	 */
 	for (i = first; i <= last; ++i) {
 		slot = kzalloc(sizeof (struct slot), GFP_KERNEL);
-		if (!slot)
+		if (!slot) {
+			status = -ENOMEM;
 			goto error;
+		}
 
 		hotplug_slot =
 			kzalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
-		if (!hotplug_slot)
+		if (!hotplug_slot) {
+			status = -ENOMEM;
 			goto error_slot;
+		}
 		slot->hotplug_slot = hotplug_slot;
 
 		info = kzalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
-		if (!info)
+		if (!info) {
+			status = -ENOMEM;
 			goto error_hpslot;
+		}
 		hotplug_slot->info = info;
 
 		slot->bus = bus;


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

* [PATCH 2/6] drivers/net/can/softing/softing_main.c: ensure a consistent return value in error case
  2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
  2012-07-14 16:43 ` [PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: " Julia Lawall
@ 2012-07-14 16:43 ` Julia Lawall
  2012-07-15 20:21   ` Kurt Van Dijck
  2012-07-16  7:34   ` Marc Kleine-Budde
  2012-07-14 16:43 ` [PATCH 3/6] arch/arm/mach-netx/xc.c: " Julia Lawall
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: kernel-janitors, Marc Kleine-Budde, linux-can, netdev,
	linux-kernel

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

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

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

---
 drivers/net/can/softing/softing_main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
index a7c77c7..f2a221e 100644
--- a/drivers/net/can/softing/softing_main.c
+++ b/drivers/net/can/softing/softing_main.c
@@ -826,12 +826,12 @@ static __devinit int softing_pdev_probe(struct platform_device *pdev)
 		goto sysfs_failed;
 	}
 
-	ret = -ENOMEM;
 	for (j = 0; j < ARRAY_SIZE(card->net); ++j) {
 		card->net[j] = netdev =
 			softing_netdev_create(card, card->id.chip[j]);
 		if (!netdev) {
 			dev_alert(&pdev->dev, "failed to make can[%i]", j);
+			ret = -ENOMEM;
 			goto netdev_failed;
 		}
 		priv = netdev_priv(card->net[j]);


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

* [PATCH 3/6] arch/arm/mach-netx/xc.c: ensure a consistent return value in error case
  2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
  2012-07-14 16:43 ` [PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: " Julia Lawall
  2012-07-14 16:43 ` [PATCH 2/6] drivers/net/can/softing/softing_main.c: " Julia Lawall
@ 2012-07-14 16:43 ` Julia Lawall
  2012-07-14 16:43 ` [PATCH 4/6] drivers/cpuidle/sysfs.c: " Julia Lawall
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: Russell King; +Cc: kernel-janitors, linux-arm-kernel, linux-kernel

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

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

Resetting ret to 0 at the end of the function is not necessary because the
return value of xc_patch is either 0 or a negative integer.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

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

---
If relying on the return value of xc_patch to set ret to 0 is considered
too fragile this part of the patch could be dropped.

 arch/arm/mach-netx/xc.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-netx/xc.c b/arch/arm/mach-netx/xc.c
index e4cfb7e..18a98e0 100644
--- a/arch/arm/mach-netx/xc.c
+++ b/arch/arm/mach-netx/xc.c
@@ -149,16 +149,16 @@ int xc_request_firmware(struct xc *x)
 	x->type = head->type;
 	x->version = head->version;
 
-	ret = -EINVAL;
-
 	for (i = 0; i < 3; i++) {
 		src = fw->data + head->fw_desc[i].ofs;
 		dst = *(unsigned int *)src;
 		src += sizeof (unsigned int);
 		size = head->fw_desc[i].size - sizeof (unsigned int);
 
-		if (xc_check_ptr(x, dst, size))
+		if (xc_check_ptr(x, dst, size)) {
+			ret = -EINVAL;
 			goto exit_release_firmware;
+		}
 
 		memcpy((void *)io_p2v(dst), src, size);
 
@@ -169,8 +169,6 @@ int xc_request_firmware(struct xc *x)
 			goto exit_release_firmware;
 	}
 
-	ret = 0;
-
       exit_release_firmware:
 	release_firmware(fw);
 


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

* [PATCH 4/6] drivers/cpuidle/sysfs.c: ensure a consistent return value in error case
  2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
                   ` (2 preceding siblings ...)
  2012-07-14 16:43 ` [PATCH 3/6] arch/arm/mach-netx/xc.c: " Julia Lawall
@ 2012-07-14 16:43 ` Julia Lawall
  2012-07-14 16:43 ` [PATCH 5/6] drivers/pci/hotplug: " Julia Lawall
  2012-07-14 16:43 ` [PATCH 6/6] arch/x86/kernel/kdebugfs.c: " Julia Lawall
  5 siblings, 0 replies; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

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

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

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

---
 drivers/cpuidle/sysfs.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 5f809e3..06df57c 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -361,15 +361,17 @@ static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
  */
 int cpuidle_add_state_sysfs(struct cpuidle_device *device)
 {
-	int i, ret = -ENOMEM;
+	int i, ret;
 	struct cpuidle_state_kobj *kobj;
 	struct cpuidle_driver *drv = cpuidle_get_driver();
 
 	/* state statistics */
 	for (i = 0; i < device->state_count; i++) {
 		kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
-		if (!kobj)
+		if (!kobj) {
+			ret = -ENOMEM;
 			goto error_state;
+		}
 		kobj->state = &drv->states[i];
 		kobj->state_usage = &device->states_usage[i];
 		init_completion(&kobj->kobj_unregister);


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

* [PATCH 5/6] drivers/pci/hotplug: ensure a consistent return value in error case
  2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
                   ` (3 preceding siblings ...)
  2012-07-14 16:43 ` [PATCH 4/6] drivers/cpuidle/sysfs.c: " Julia Lawall
@ 2012-07-14 16:43 ` Julia Lawall
  2012-07-16 15:54   ` Bjorn Helgaas
  2012-07-14 16:43 ` [PATCH 6/6] arch/x86/kernel/kdebugfs.c: " Julia Lawall
  5 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: kernel-janitors, linux-pci, linux-kernel

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

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

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

---
 drivers/pci/hotplug/cpqphp_core.c    |   14 ++++++++++----
 drivers/pci/hotplug/pcihp_skeleton.c |   14 ++++++++++----
 drivers/pci/hotplug/shpchp_core.c    |   14 ++++++++++----
 3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 187a199..c8eaeb4 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -611,7 +611,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
 	u32 tempdword;
 	char name[SLOT_NAME_SIZE];
 	void __iomem *slot_entry= NULL;
-	int result = -ENOMEM;
+	int result;
 
 	dbg("%s\n", __func__);
 
@@ -623,19 +623,25 @@ static int ctrl_slot_setup(struct controller *ctrl,
 
 	while (number_of_slots) {
 		slot = kzalloc(sizeof(*slot), GFP_KERNEL);
-		if (!slot)
+		if (!slot) {
+			result = -ENOMEM;
 			goto error;
+		}
 
 		slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
 						GFP_KERNEL);
-		if (!slot->hotplug_slot)
+		if (!slot->hotplug_slot) {
+			result = -ENOMEM;
 			goto error_slot;
+		}
 		hotplug_slot = slot->hotplug_slot;
 
 		hotplug_slot->info = kzalloc(sizeof(*(hotplug_slot->info)),
 							GFP_KERNEL);
-		if (!hotplug_slot->info)
+		if (!hotplug_slot->info) {
+			result = -ENOMEM;
 			goto error_hpslot;
+		}
 		hotplug_slot_info = hotplug_slot->info;
 
 		slot->ctrl = ctrl;
diff --git a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c
index b20ceaa..1f00b93 100644
--- a/drivers/pci/hotplug/pcihp_skeleton.c
+++ b/drivers/pci/hotplug/pcihp_skeleton.c
@@ -252,7 +252,7 @@ static int __init init_slots(void)
 	struct slot *slot;
 	struct hotplug_slot *hotplug_slot;
 	struct hotplug_slot_info *info;
-	int retval = -ENOMEM;
+	int retval;
 	int i;
 
 	/*
@@ -261,17 +261,23 @@ static int __init init_slots(void)
 	 */
 	for (i = 0; i < num_slots; ++i) {
 		slot = kzalloc(sizeof(*slot), GFP_KERNEL);
-		if (!slot)
+		if (!slot) {
+			retval = -ENOMEM;
 			goto error;
+		}
 
 		hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
-		if (!hotplug_slot)
+		if (!hotplug_slot) {
+			retval = -ENOMEM;
 			goto error_slot;
+		}
 		slot->hotplug_slot = hotplug_slot;
 
 		info = kzalloc(sizeof(*info), GFP_KERNEL);
-		if (!info)
+		if (!info) {
+			retval = -ENOMEM;
 			goto error_hpslot;
+		}
 		hotplug_slot->info = info;
 
 		slot->number = i;
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 7414fd9..b6de307 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -99,22 +99,28 @@ static int init_slots(struct controller *ctrl)
 	struct hotplug_slot *hotplug_slot;
 	struct hotplug_slot_info *info;
 	char name[SLOT_NAME_SIZE];
-	int retval = -ENOMEM;
+	int retval;
 	int i;
 
 	for (i = 0; i < ctrl->num_slots; i++) {
 		slot = kzalloc(sizeof(*slot), GFP_KERNEL);
-		if (!slot)
+		if (!slot) {
+			retval = -ENOMEM;
 			goto error;
+		}
 
 		hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
-		if (!hotplug_slot)
+		if (!hotplug_slot) {
+			retval = -ENOMEM;
 			goto error_slot;
+		}
 		slot->hotplug_slot = hotplug_slot;
 
 		info = kzalloc(sizeof(*info), GFP_KERNEL);
-		if (!info)
+		if (!info) {
+			retval = -ENOMEM;
 			goto error_hpslot;
+		}
 		hotplug_slot->info = info;
 
 		slot->hp_slot = i;


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

* [PATCH 6/6] arch/x86/kernel/kdebugfs.c: ensure a consistent return value in error case
  2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
                   ` (4 preceding siblings ...)
  2012-07-14 16:43 ` [PATCH 5/6] drivers/pci/hotplug: " Julia Lawall
@ 2012-07-14 16:43 ` Julia Lawall
  2012-07-26 15:19   ` [tip:x86/urgent] arch/x86/kernel/kdebugfs.c: Ensure " tip-bot for Julia Lawall
  5 siblings, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2012-07-14 16:43 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: kernel-janitors, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

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

Typically, the return value desired for the failure of a function with an
integer return value is a negative integer.  In these cases, the return
value is sometimes a negative integer and sometimes 0, due to a subsequent
initialization of the return variable within the loop.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

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

---
 arch/x86/kernel/kdebugfs.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
index 1d5d31e..dc1404b 100644
--- a/arch/x86/kernel/kdebugfs.c
+++ b/arch/x86/kernel/kdebugfs.c
@@ -107,7 +107,7 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 {
 	struct setup_data_node *node;
 	struct setup_data *data;
-	int error = -ENOMEM;
+	int error;
 	struct dentry *d;
 	struct page *pg;
 	u64 pa_data;
@@ -121,8 +121,10 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 
 	while (pa_data) {
 		node = kmalloc(sizeof(*node), GFP_KERNEL);
-		if (!node)
+		if (!node) {
+			error = -ENOMEM;
 			goto err_dir;
+		}
 
 		pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
 		if (PageHighMem(pg)) {


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

* Re: [PATCH 2/6] drivers/net/can/softing/softing_main.c: ensure a consistent return value in error case
  2012-07-14 16:43 ` [PATCH 2/6] drivers/net/can/softing/softing_main.c: " Julia Lawall
@ 2012-07-15 20:21   ` Kurt Van Dijck
  2012-07-16  7:34   ` Marc Kleine-Budde
  1 sibling, 0 replies; 11+ messages in thread
From: Kurt Van Dijck @ 2012-07-15 20:21 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Wolfgang Grandegger, kernel-janitors, Marc Kleine-Budde,
	linux-can, netdev, linux-kernel

I see the problem, and the solution. You may add
Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be>

On Sat, Jul 14, 2012 at 06:43:04PM +0200, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Typically, the return value desired for the failure of a function with an
> integer return value is a negative integer.  In these cases, the return
> value is sometimes a negative integer and sometimes 0, due to a subsequent
> initialization of the return variable within the loop.
> 
> A simplified version of the semantic match that finds this problem is:
> (http://coccinelle.lip6.fr/)
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
>  drivers/net/can/softing/softing_main.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
> index a7c77c7..f2a221e 100644
> --- a/drivers/net/can/softing/softing_main.c
> +++ b/drivers/net/can/softing/softing_main.c
> @@ -826,12 +826,12 @@ static __devinit int softing_pdev_probe(struct platform_device *pdev)
>  		goto sysfs_failed;
>  	}
>  
> -	ret = -ENOMEM;
>  	for (j = 0; j < ARRAY_SIZE(card->net); ++j) {
>  		card->net[j] = netdev =
>  			softing_netdev_create(card, card->id.chip[j]);
>  		if (!netdev) {
>  			dev_alert(&pdev->dev, "failed to make can[%i]", j);
> +			ret = -ENOMEM;
>  			goto netdev_failed;
>  		}
>  		priv = netdev_priv(card->net[j]);
> 

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

* Re: [PATCH 2/6] drivers/net/can/softing/softing_main.c: ensure a consistent return value in error case
  2012-07-14 16:43 ` [PATCH 2/6] drivers/net/can/softing/softing_main.c: " Julia Lawall
  2012-07-15 20:21   ` Kurt Van Dijck
@ 2012-07-16  7:34   ` Marc Kleine-Budde
  1 sibling, 0 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2012-07-16  7:34 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Wolfgang Grandegger, kernel-janitors, linux-can, netdev,
	linux-kernel

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

On 07/14/2012 06:43 PM, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Typically, the return value desired for the failure of a function with an
> integer return value is a negative integer.  In these cases, the return
> value is sometimes a negative integer and sometimes 0, due to a subsequent
> initialization of the return variable within the loop.
> 
> A simplified version of the semantic match that finds this problem is:
> (http://coccinelle.lip6.fr/)
> 
> //<smpl>
> @r exists@
> identifier ret;
> position p;
> constant C;
> expression e1,e3,e4;
> statement S;
> @@
> 
> ret = -C
> ... when != ret = e3
>     when any
> if@p (...) S
> ... when any
> if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
> ... when != ret = e3
>     when any
> *if@p (...)
> {
>   ... when != ret = e4
>   return ret;
> }
> //</smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Thanks, applied to can-next

Marc
> 
> ---
>  drivers/net/can/softing/softing_main.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c
> index a7c77c7..f2a221e 100644
> --- a/drivers/net/can/softing/softing_main.c
> +++ b/drivers/net/can/softing/softing_main.c
> @@ -826,12 +826,12 @@ static __devinit int softing_pdev_probe(struct platform_device *pdev)
>  		goto sysfs_failed;
>  	}
>  
> -	ret = -ENOMEM;
>  	for (j = 0; j < ARRAY_SIZE(card->net); ++j) {
>  		card->net[j] = netdev =
>  			softing_netdev_create(card, card->id.chip[j]);
>  		if (!netdev) {
>  			dev_alert(&pdev->dev, "failed to make can[%i]", j);
> +			ret = -ENOMEM;
>  			goto netdev_failed;
>  		}
>  		priv = netdev_priv(card->net[j]);
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


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

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

* Re: [PATCH 5/6] drivers/pci/hotplug: ensure a consistent return value in error case
  2012-07-14 16:43 ` [PATCH 5/6] drivers/pci/hotplug: " Julia Lawall
@ 2012-07-16 15:54   ` Bjorn Helgaas
  0 siblings, 0 replies; 11+ messages in thread
From: Bjorn Helgaas @ 2012-07-16 15:54 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kernel-janitors, linux-pci, linux-kernel

On Sat, Jul 14, 2012 at 10:43 AM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> Typically, the return value desired for the failure of a function with an
> integer return value is a negative integer.  In these cases, the return
> value is sometimes a negative integer and sometimes 0, due to a subsequent
> initialization of the return variable within the loop.
>
> A simplified version of the semantic match that finds this problem is:
> (http://coccinelle.lip6.fr/)
>
> //<smpl>
> @r exists@
> identifier ret;
> position p;
> constant C;
> expression e1,e3,e4;
> statement S;
> @@
>
> ret = -C
> ... when != ret = e3
>     when any
> if@p (...) S
> ... when any
> if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
> ... when != ret = e3
>     when any
> *if@p (...)
> {
>   ... when != ret = e4
>   return ret;
> }
> //</smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
>  drivers/pci/hotplug/cpqphp_core.c    |   14 ++++++++++----
>  drivers/pci/hotplug/pcihp_skeleton.c |   14 ++++++++++----
>  drivers/pci/hotplug/shpchp_core.c    |   14 ++++++++++----
>  3 files changed, 30 insertions(+), 12 deletions(-)

I squashed this patch and patch [1/6] (for the same problem in
drivers/pci/hotplug/cpci_hotplug_core.c) and applied it to my "next"
branch.  Thanks!

> diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
> index 187a199..c8eaeb4 100644
> --- a/drivers/pci/hotplug/cpqphp_core.c
> +++ b/drivers/pci/hotplug/cpqphp_core.c
> @@ -611,7 +611,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
>         u32 tempdword;
>         char name[SLOT_NAME_SIZE];
>         void __iomem *slot_entry= NULL;
> -       int result = -ENOMEM;
> +       int result;
>
>         dbg("%s\n", __func__);
>
> @@ -623,19 +623,25 @@ static int ctrl_slot_setup(struct controller *ctrl,
>
>         while (number_of_slots) {
>                 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
> -               if (!slot)
> +               if (!slot) {
> +                       result = -ENOMEM;
>                         goto error;
> +               }
>
>                 slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
>                                                 GFP_KERNEL);
> -               if (!slot->hotplug_slot)
> +               if (!slot->hotplug_slot) {
> +                       result = -ENOMEM;
>                         goto error_slot;
> +               }
>                 hotplug_slot = slot->hotplug_slot;
>
>                 hotplug_slot->info = kzalloc(sizeof(*(hotplug_slot->info)),
>                                                         GFP_KERNEL);
> -               if (!hotplug_slot->info)
> +               if (!hotplug_slot->info) {
> +                       result = -ENOMEM;
>                         goto error_hpslot;
> +               }
>                 hotplug_slot_info = hotplug_slot->info;
>
>                 slot->ctrl = ctrl;
> diff --git a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c
> index b20ceaa..1f00b93 100644
> --- a/drivers/pci/hotplug/pcihp_skeleton.c
> +++ b/drivers/pci/hotplug/pcihp_skeleton.c
> @@ -252,7 +252,7 @@ static int __init init_slots(void)
>         struct slot *slot;
>         struct hotplug_slot *hotplug_slot;
>         struct hotplug_slot_info *info;
> -       int retval = -ENOMEM;
> +       int retval;
>         int i;
>
>         /*
> @@ -261,17 +261,23 @@ static int __init init_slots(void)
>          */
>         for (i = 0; i < num_slots; ++i) {
>                 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
> -               if (!slot)
> +               if (!slot) {
> +                       retval = -ENOMEM;
>                         goto error;
> +               }
>
>                 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
> -               if (!hotplug_slot)
> +               if (!hotplug_slot) {
> +                       retval = -ENOMEM;
>                         goto error_slot;
> +               }
>                 slot->hotplug_slot = hotplug_slot;
>
>                 info = kzalloc(sizeof(*info), GFP_KERNEL);
> -               if (!info)
> +               if (!info) {
> +                       retval = -ENOMEM;
>                         goto error_hpslot;
> +               }
>                 hotplug_slot->info = info;
>
>                 slot->number = i;
> diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
> index 7414fd9..b6de307 100644
> --- a/drivers/pci/hotplug/shpchp_core.c
> +++ b/drivers/pci/hotplug/shpchp_core.c
> @@ -99,22 +99,28 @@ static int init_slots(struct controller *ctrl)
>         struct hotplug_slot *hotplug_slot;
>         struct hotplug_slot_info *info;
>         char name[SLOT_NAME_SIZE];
> -       int retval = -ENOMEM;
> +       int retval;
>         int i;
>
>         for (i = 0; i < ctrl->num_slots; i++) {
>                 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
> -               if (!slot)
> +               if (!slot) {
> +                       retval = -ENOMEM;
>                         goto error;
> +               }
>
>                 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
> -               if (!hotplug_slot)
> +               if (!hotplug_slot) {
> +                       retval = -ENOMEM;
>                         goto error_slot;
> +               }
>                 slot->hotplug_slot = hotplug_slot;
>
>                 info = kzalloc(sizeof(*info), GFP_KERNEL);
> -               if (!info)
> +               if (!info) {
> +                       retval = -ENOMEM;
>                         goto error_hpslot;
> +               }
>                 hotplug_slot->info = info;
>
>                 slot->hp_slot = i;
>

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

* [tip:x86/urgent] arch/x86/kernel/kdebugfs.c: Ensure a consistent return value in error case
  2012-07-14 16:43 ` [PATCH 6/6] arch/x86/kernel/kdebugfs.c: " Julia Lawall
@ 2012-07-26 15:19   ` tip-bot for Julia Lawall
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Julia Lawall @ 2012-07-26 15:19 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, Julia.Lawall, tglx

Commit-ID:  41fb433b63cc4745f4918fdaf295763da5ca826c
Gitweb:     http://git.kernel.org/tip/41fb433b63cc4745f4918fdaf295763da5ca826c
Author:     Julia Lawall <Julia.Lawall@lip6.fr>
AuthorDate: Sat, 14 Jul 2012 18:43:08 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 26 Jul 2012 15:07:20 +0200

arch/x86/kernel/kdebugfs.c: Ensure a consistent return value in error case

Typically, the return value desired for the failure of a
function with an integer return value is a negative integer.  In
these cases, the return value is sometimes a negative integer
and sometimes 0, due to a subsequent initialization of the
return variable within the loop.

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

//<smpl>
@r exists@
identifier ret;
position p;
constant C;
expression e1,e3,e4;
statement S;
@@

ret = -C
... when != ret = e3
    when any
if@p (...) S
... when any
if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; }
... when != ret = e3
    when any
*if@p (...)
{
  ... when != ret = e4
  return ret;
}
//</smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Link: http://lkml.kernel.org/r/1342284188-19176-7-git-send-email-Julia.Lawall@lip6.fr
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/kdebugfs.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
index 1d5d31e..dc1404b 100644
--- a/arch/x86/kernel/kdebugfs.c
+++ b/arch/x86/kernel/kdebugfs.c
@@ -107,7 +107,7 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 {
 	struct setup_data_node *node;
 	struct setup_data *data;
-	int error = -ENOMEM;
+	int error;
 	struct dentry *d;
 	struct page *pg;
 	u64 pa_data;
@@ -121,8 +121,10 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 
 	while (pa_data) {
 		node = kmalloc(sizeof(*node), GFP_KERNEL);
-		if (!node)
+		if (!node) {
+			error = -ENOMEM;
 			goto err_dir;
+		}
 
 		pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
 		if (PageHighMem(pg)) {

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

end of thread, other threads:[~2012-07-26 15:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-14 16:43 [PATCH 0/6] ensure a consistent return value in error case Julia Lawall
2012-07-14 16:43 ` [PATCH 1/6] drivers/pci/hotplug/cpci_hotplug_core.c: " Julia Lawall
2012-07-14 16:43 ` [PATCH 2/6] drivers/net/can/softing/softing_main.c: " Julia Lawall
2012-07-15 20:21   ` Kurt Van Dijck
2012-07-16  7:34   ` Marc Kleine-Budde
2012-07-14 16:43 ` [PATCH 3/6] arch/arm/mach-netx/xc.c: " Julia Lawall
2012-07-14 16:43 ` [PATCH 4/6] drivers/cpuidle/sysfs.c: " Julia Lawall
2012-07-14 16:43 ` [PATCH 5/6] drivers/pci/hotplug: " Julia Lawall
2012-07-16 15:54   ` Bjorn Helgaas
2012-07-14 16:43 ` [PATCH 6/6] arch/x86/kernel/kdebugfs.c: " Julia Lawall
2012-07-26 15:19   ` [tip:x86/urgent] arch/x86/kernel/kdebugfs.c: Ensure " tip-bot for Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox