1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Use memdup_user rather than duplicating its implementation
3 /// This is a little bit restricted to reduce false positives
6 // Copyright: (C) 2010-2012 Nicolas Palix.
7 // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
8 // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
9 // URL: http://coccinelle.lip6.fr/
11 // Options: --no-includes --include-headers
19 expression from,to,size;
23 - to = \(kmalloc\|kzalloc\)(size,GFP_KERNEL);
24 + to = memdup_user(from,size);
29 <+... when != goto l1;
34 - if (copy_from_user(to, from, size) != 0) {
35 - <+... when != goto l2;
41 expression from,to,size;
46 * to = \(kmalloc@p\|kzalloc@p\)(size,GFP_KERNEL);
47 if (to==NULL || ...) S1
48 if (copy_from_user(to, from, size) != 0)
51 @script:python depends on org@
55 coccilib.org.print_todo(p[0], "WARNING opportunity for memdup_user")
57 @script:python depends on report@
61 coccilib.report.print_report(p[0], "WARNING opportunity for memdup_user")