Commit f137f15072411618e37b338aa13e5ae43583bcf2

Authored by Julia Lawall
Committed by Tyler Hicks
1 parent 76be97c1fc

fs/ecryptfs: Return -ENOMEM on memory allocation failure

In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.

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

// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@

ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>

Showing 1 changed file with 2 additions and 0 deletions Side-by-side Diff

fs/ecryptfs/keystore.c
... ... @@ -515,6 +515,7 @@
515 515 if (!s) {
516 516 printk(KERN_ERR "%s: Out of memory whilst trying to kmalloc "
517 517 "[%zd] bytes of kernel memory\n", __func__, sizeof(*s));
  518 + rc = -ENOMEM;
518 519 goto out;
519 520 }
520 521 s->desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
... ... @@ -806,6 +807,7 @@
806 807 if (!s) {
807 808 printk(KERN_ERR "%s: Out of memory whilst trying to kmalloc "
808 809 "[%zd] bytes of kernel memory\n", __func__, sizeof(*s));
  810 + rc = -ENOMEM;
809 811 goto out;
810 812 }
811 813 s->desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;