162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/// The various basic memory allocation functions don't return ERR_PTR 362306a36Sopenharmony_ci/// 462306a36Sopenharmony_ci// Confidence: High 562306a36Sopenharmony_ci// Copyright: (C) 2010-2012 Nicolas Palix. 662306a36Sopenharmony_ci// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. 762306a36Sopenharmony_ci// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. 862306a36Sopenharmony_ci// URL: https://coccinelle.gitlabpages.inria.fr/website 962306a36Sopenharmony_ci// Comments: 1062306a36Sopenharmony_ci// Options: --no-includes --include-headers 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_civirtual patch 1362306a36Sopenharmony_civirtual context 1462306a36Sopenharmony_civirtual org 1562306a36Sopenharmony_civirtual report 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci@depends on patch@ 1862306a36Sopenharmony_ciexpression x,E; 1962306a36Sopenharmony_ci@@ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_cix = \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...) 2262306a36Sopenharmony_ci... when != x = E 2362306a36Sopenharmony_ci- IS_ERR(x) 2462306a36Sopenharmony_ci+ !x 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci@r depends on !patch exists@ 2762306a36Sopenharmony_ciexpression x,E; 2862306a36Sopenharmony_ciposition p1,p2; 2962306a36Sopenharmony_ci@@ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_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\)(...) 3262306a36Sopenharmony_ci... when != x = E 3362306a36Sopenharmony_ci* IS_ERR@p2(x) 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci@script:python depends on org@ 3662306a36Sopenharmony_cip1 << r.p1; 3762306a36Sopenharmony_cip2 << r.p2; 3862306a36Sopenharmony_ci@@ 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cicocci.print_main("alloc call",p1) 4162306a36Sopenharmony_cicocci.print_secs("IS_ERR that should be NULL tests",p2) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci@script:python depends on report@ 4462306a36Sopenharmony_cip1 << r.p1; 4562306a36Sopenharmony_cip2 << r.p2; 4662306a36Sopenharmony_ci@@ 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cimsg = "ERROR: allocation function on line %s returns NULL not ERR_PTR on failure" % (p1[0].line) 4962306a36Sopenharmony_cicoccilib.report.print_report(p2[0], msg) 50