18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/// The various basic memory allocation functions don't return ERR_PTR
38c2ecf20Sopenharmony_ci///
48c2ecf20Sopenharmony_ci// Confidence: High
58c2ecf20Sopenharmony_ci// Copyright: (C) 2010-2012 Nicolas Palix.
68c2ecf20Sopenharmony_ci// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
78c2ecf20Sopenharmony_ci// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
88c2ecf20Sopenharmony_ci// URL: http://coccinelle.lip6.fr/
98c2ecf20Sopenharmony_ci// Comments:
108c2ecf20Sopenharmony_ci// Options: --no-includes --include-headers
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_civirtual patch
138c2ecf20Sopenharmony_civirtual context
148c2ecf20Sopenharmony_civirtual org
158c2ecf20Sopenharmony_civirtual report
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci@depends on patch@
188c2ecf20Sopenharmony_ciexpression x,E;
198c2ecf20Sopenharmony_ci@@
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cix = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)
228c2ecf20Sopenharmony_ci... when != x = E
238c2ecf20Sopenharmony_ci- IS_ERR(x)
248c2ecf20Sopenharmony_ci+ !x
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci@r depends on !patch exists@
278c2ecf20Sopenharmony_ciexpression x,E;
288c2ecf20Sopenharmony_ciposition p1,p2;
298c2ecf20Sopenharmony_ci@@
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci*x = \(kmalloc@p1\|kzalloc@p1\|kcalloc@p1\|kmem_cache_alloc@p1\|kmem_cache_zalloc@p1\|kmem_cache_alloc_node@p1\|kmalloc_node@p1\|kzalloc_node@p1\)(...)
328c2ecf20Sopenharmony_ci... when != x = E
338c2ecf20Sopenharmony_ci* IS_ERR@p2(x)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci@script:python depends on org@
368c2ecf20Sopenharmony_cip1 << r.p1;
378c2ecf20Sopenharmony_cip2 << r.p2;
388c2ecf20Sopenharmony_ci@@
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cicocci.print_main("alloc call",p1)
418c2ecf20Sopenharmony_cicocci.print_secs("IS_ERR that should be NULL tests",p2)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci@script:python depends on report@
448c2ecf20Sopenharmony_cip1 << r.p1;
458c2ecf20Sopenharmony_cip2 << r.p2;
468c2ecf20Sopenharmony_ci@@
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cimsg = "ERROR: allocation function on line %s returns NULL not ERR_PTR on failure" % (p1[0].line)
498c2ecf20Sopenharmony_cicoccilib.report.print_report(p2[0], msg)
50