Skip to content

Commit

Permalink
net: cavium: liquidio: Return correct error code
Browse files Browse the repository at this point in the history
The return value of vmalloc 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;
identifier l1;
position p,q;
@@

e@q = vmalloc(...);
if@p (e == NULL) {
...
goto l1;
}
l1:
...
return -1
+ -ENOMEM
;
//</smpl

The single call site of the containing function checks whether the
returned value is -1, so this check is changed as well. The single call
site of this call site, however, only checks whether the value is not 0,
so no further change was required.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Amitoj Kaur Chawla authored and David S. Miller committed Feb 13, 2016
1 parent 21a75f0 commit 08a965e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/cavium/liquidio/lio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ static int octeon_setup_droq(struct octeon_device *oct, int q_no, int num_descs,
dev_dbg(&oct->pci_dev->dev, "Creating Droq: %d\n", q_no);
/* droq creation and local register settings. */
ret_val = octeon_create_droq(oct, q_no, num_descs, desc_size, app_ctx);
if (ret_val == -1)
if (ret_val < 0)
return ret_val;

if (ret_val == 1) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/cavium/liquidio/octeon_droq.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,5 +983,5 @@ int octeon_create_droq(struct octeon_device *oct,

create_droq_fail:
octeon_delete_droq(oct, q_no);
return -1;
return -ENOMEM;
}

0 comments on commit 08a965e

Please sign in to comment.