* [PATCH 3/3] net: mvpp2: Return correct error codes
@ 2016-02-04 13:55 Amitoj Kaur Chawla
2016-02-13 10:58 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-04 13:55 UTC (permalink / raw)
To: netdev, linux-kernel; +Cc: julia.lawall
The return value of kzalloc on failure of allocation of memory should
be -ENOMEM and not -1.
Found using Coccinelle. A simplified version of the semantic patch
used is:
//<smpl>
@@
expression *e;
position p,q;
@@
e@q = kzalloc(...);
if@p (e == NULL) {
...
return
- -1
+ -ENOMEM
;
}
//</smpl>
This function may also return -1 after calling mpp2_prs_tcam_port_map_get.
So that the function consistently returns meaningful error values on
failure, the -1 is changed to -EINVAL.
Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
drivers/net/ethernet/marvell/mvpp2.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index d9884fd..3208787 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -3061,7 +3061,7 @@ static int mvpp2_prs_mac_da_accept(struct mvpp2 *priv, int port,
pe = kzalloc(sizeof(*pe), GFP_KERNEL);
if (!pe)
- return -1;
+ return -ENOMEM;
mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_MAC);
pe->index = tid;
@@ -3077,7 +3077,7 @@ static int mvpp2_prs_mac_da_accept(struct mvpp2 *priv, int port,
if (pmap == 0) {
if (add) {
kfree(pe);
- return -1;
+ return -EINVAL;
}
mvpp2_prs_hw_inv(priv, pe->index);
priv->prs_shadow[pe->index].valid = false;
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 3/3] net: mvpp2: Return correct error codes
2016-02-04 13:55 [PATCH 3/3] net: mvpp2: Return correct error codes Amitoj Kaur Chawla
@ 2016-02-13 10:58 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-02-13 10:58 UTC (permalink / raw)
To: amitoj1606; +Cc: netdev, linux-kernel, julia.lawall
From: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Date: Thu, 4 Feb 2016 19:25:26 +0530
> The return value of kzalloc on failure of allocation of memory should
> be -ENOMEM and not -1.
>
> Found using Coccinelle. A simplified version of the semantic patch
> used is:
...
> This function may also return -1 after calling mpp2_prs_tcam_port_map_get.
> So that the function consistently returns meaningful error values on
> failure, the -1 is changed to -EINVAL.
>
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-13 10:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-04 13:55 [PATCH 3/3] net: mvpp2: Return correct error codes Amitoj Kaur Chawla
2016-02-13 10:58 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox