fix error return code
Subsystems (13)
cover fix error return code
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>
PATCH 1/6 drivers/edac/i7core_edac.c: fix error return code
From: Julia Lawall <[email protected]>
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>
--- drivers/edac/i7core_edac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/i7core_edac.c +2 -2
@@ -1177,7 +1177,7 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci) pvt->addrmatch_dev =kzalloc (sizeof (*pvt->addrmatch_dev),GFP_KERNEL );if (!pvt->addrmatch_dev) -return rc; +return -ENOMEM ; pvt->addrmatch_dev->type = &addrmatch_type; pvt->addrmatch_dev->bus = mci->dev.bus;
@@ -1198,7 +1198,7 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)if (!pvt->chancounts_dev) {put_device (pvt->addrmatch_dev);device_del (pvt->addrmatch_dev); -return rc; +return -ENOMEM ; } pvt->chancounts_dev->type = &all_channel_counts_type;
PATCH 2/6 drivers/cpufreq/pcc-cpufreq.c: fix error return code
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
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>
--- drivers/cpufreq/pcc-cpufreq.c | 1 + 1 file changed, 1 insertion(+)
drivers/cpufreq/pcc-cpufreq.c +1 -0
@@ -454,6 +454,7 @@ static int __init pcc_cpufreq_probe(void) mem_resource->address_length);if (pcch_virt_addr ==NULL ) {pr_debug ("probe: could not map shared mem region\n" ); + ret = -ENOMEM ; goto out_free; } pcch_hdr = pcch_virt_addr;
Rafael J. Wysocki
AppliedRe: [PATCH 2/6] drivers/cpufreq/pcc-cpufreq.c: fix error return code
Quoted 23 lines · Julia Lawall
From: Julia Lawall <[email protected]>
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 = e2when != ret = e3
Quoted 8 lines
*if (x == NULL || ...)
{
... when != ret = e4
* return ret;
}
// </smpl>Signed-off-by Julia Lawall <[email protected]>
Applied to the linux-next branch of the linux-pm.git tree. I'm going to push it as a fix for v3.6.
Thanks,
Rafael
Quoted 19 lines
--- drivers/cpufreq/pcc-cpufreq.c | 1 + 1 file changed, 1 insertion(+)drivers/cpufreq/pcc-cpufreq.c +1
-0@@ -454,6 +454,7 @@ static int __init pcc_cpufreq_probe(void) mem_resource->address_length);if (pcch_virt_addr ==NULL ) {pr_debug ("probe: could not map shared mem region\n" ); + ret = -ENOMEM ; goto out_free; } pcch_hdr = pcch_virt_addr;
PATCH 3/6 arch/powerpc/kvm/e500_tlb.c: fix error return code
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
Convert a 0 error return code to a negative one, as returned elsewhere in the function.
A new label is also added to avoid freeing things that are known to not yet be allocated.
A simplified version of the semantic match that finds the first 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>
--- arch/powerpc/kvm/e500_tlb.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
arch/powerpc/kvm/e500_tlb.c +13 -6
@@ -1176,21 +1176,27 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, } virt =vmap (pages, num_pages,VM_MAP ,PAGE_KERNEL ); -if (!virt) +if (!virt) { + ret = -ENOMEM ; goto err_put_page; + } privs[0 ] =kzalloc (sizeof (struct tlbe_priv ) * params.tlb_sizes[0 ],GFP_KERNEL ); privs[1 ] =kzalloc (sizeof (struct tlbe_priv ) * params.tlb_sizes[1 ],GFP_KERNEL ); -if (!privs[0 ] || !privs[1 ]) - goto err_put_page; +if (!privs[0 ] || !privs[1 ]) { + ret = -ENOMEM ; + goto err_privs; + } g2h_bitmap =kzalloc (sizeof (u64) * params.tlb_sizes[1 ],GFP_KERNEL ); -if (!g2h_bitmap) - goto err_put_page; +if (!g2h_bitmap) { + ret = -ENOMEM ; + goto err_privs; + }free_gtlb (vcpu_e500);
@@ -1230,10 +1236,11 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,kvmppc_recalc_tlb1map_range (vcpu_e500);return 0 ; -err_put_page: +err_privs:kfree (privs[0 ]);kfree (privs[1 ]); +err_put_page:for (i =0 ; i < num_pages; i++)put_page (pages[i]);
Alexander Graf
AppliedRe: [PATCH 3/6] arch/powerpc/kvm/e500_tlb.c: fix error return code
Quoted 33 lines · Julia Lawall
From: Julia Lawall <[email protected]>
Convert a 0 error return code to a negative one, as returned elsewhere in the function.
A new label is also added to avoid freeing things that are known to not yet be allocated.
A simplified version of the semantic match that finds the first 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>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Thanks, applied to kvm-ppc-next.
Alex
PATCH 4/6 drivers/gpio/gpio-langwell.c: fix error return code
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
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>
--- drivers/gpio/gpio-langwell.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpio/gpio-langwell.c +5 -2
@@ -339,7 +339,7 @@ static int __devinit lnw_gpio_probe(struct pci_dev *pdev,resource_size_t start, len;struct lnw_gpio *lnw;u32 gpio_base; -int retval =0 ; +int retval;int ngpio = id->driver_data; retval =pci_enable_device (pdev);
@@ -357,6 +357,7 @@ static int __devinit lnw_gpio_probe(struct pci_dev *pdev, base =ioremap_nocache (start, len);if (!base) {dev_err (&pdev->dev,"error mapping bar1\n" ); + retval = -EFAULT ; goto err3; } gpio_base = *((u32 *)base +1 );
@@ -381,8 +382,10 @@ static int __devinit lnw_gpio_probe(struct pci_dev *pdev, lnw->domain =irq_domain_add_linear (pdev->dev.of_node, ngpio, &lnw_gpio_irq_ops, lnw); -if (!lnw->domain) +if (!lnw->domain) { + retval = -ENOMEM ; goto err3; + } lnw->reg_base = base; lnw->chip.label =dev_name (&pdev->dev);
Re: [PATCH 4/6] drivers/gpio/gpio-langwell.c: fix error return code
Quoted 4 lines · Julia Lawall
From: Julia Lawall <[email protected]>
Convert a 0 error return code to a negative one, as returned elsewhere in the function.
Patch applied.
Mika/Adrian: shout if this is incorrect.
Yours,
Linus Walleij
PATCH 5/6 drivers/char/tlclk.c: fix error return code
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
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>
--- drivers/char/tlclk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/tlclk.c +3 -1
@@ -784,8 +784,10 @@ static int __init tlclk_init(void) } tlclk_major = ret; alarm_events =kzalloc (sizeof (struct tlclk_alarms ),GFP_KERNEL ); -if (!alarm_events) +if (!alarm_events) { + ret = -ENOMEM ; goto out1; + }/* Read telecom clock IRQ number (Set by BIOS) */ if (!request_region (TLCLK_BASE ,8 ,"telco_clock" )) {
RE: [PATCH 5/6] drivers/char/tlclk.c: fix error return code
Acked-by <[email protected]>
--mark
Ps sorry for the outlook munged reply.
-----Original Message-----
From: Julia Lawall [mailto:[email protected]]
Sent: Sunday, August 05, 2012 2:53 AM
To: Gross, Mark
Cc: [email protected]; Arnd Bergmann; Greg Kroah-Hartman; [email protected]; Julia Lawall
Subject: [PATCH 5/6] drivers/char/tlclk.c: fix error return code
From: Julia Lawall <[email protected]>
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>
--- drivers/char/tlclk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/tlclk.c +3 -1
@@ -784,8 +784,10 @@ static int __init tlclk_init(void) } tlclk_major = ret; alarm_events =kzalloc (sizeof (struct tlclk_alarms ),GFP_KERNEL ); -if (!alarm_events) +if (!alarm_events) { + ret = -ENOMEM ; goto out1; + }/* Read telecom clock IRQ number (Set by BIOS) */ if (!request_region (TLCLK_BASE ,8 ,"telco_clock" )) {
PATCH 6/6 drivers/atm/iphase.c: fix error return code
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
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>
--- drivers/atm/iphase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/iphase.c +1 -1
@@ -2362,7 +2362,7 @@ static int __devinit ia_init(struct atm_dev *dev) {printk (DEV_LABEL " (itf %d): can't set up page mapping\n" , dev->number); -return error; +return -ENOMEM ; }IF_INIT (printk (DEV_LABEL " (itf %d): rev.%d,base=%p,irq=%d\n" , dev->number, iadev->pci->revision, base, iadev->irq);)
Re: [PATCH 6/6] drivers/atm/iphase.c: fix error return code
From: Julia Lawall <[email protected]>
Date: Sun, 5 Aug 2012 11:52:36 +0200
Quoted 7 lines
From: Julia Lawall <[email protected]>
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/)
...
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Applied.