Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c81aafa authored by Julia Lawall's avatar Julia Lawall Committed by Greg Kroah-Hartman
Browse files

USB: gadget: 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: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent d187abb9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1609,6 +1609,7 @@ static int __init m66592_probe(struct platform_device *pdev)
	/* initialize ucd */
	m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL);
	if (m66592 == NULL) {
		ret = -ENOMEM;
		pr_err("kzalloc error\n");
		goto clean_up;
	}