2019-06-04 11:11:38 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-08-24 19:39:06 +04:00
|
|
|
/// Use kmemdup rather than duplicating its implementation
|
|
|
|
///
|
|
|
|
// Confidence: High
|
2019-06-04 11:11:38 +03:00
|
|
|
// Copyright: (C) 2010-2012 Nicolas Palix.
|
|
|
|
// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
|
|
|
|
// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
|
2022-08-07 19:19:54 +03:00
|
|
|
// URL: https://coccinelle.gitlabpages.inria.fr/website
|
2010-08-24 19:39:06 +04:00
|
|
|
// Comments:
|
2013-06-20 15:10:56 +04:00
|
|
|
// Options: --no-includes --include-headers
|
2010-08-24 19:39:06 +04:00
|
|
|
|
|
|
|
virtual patch
|
2012-01-15 02:41:54 +04:00
|
|
|
virtual context
|
|
|
|
virtual org
|
|
|
|
virtual report
|
2010-08-24 19:39:06 +04:00
|
|
|
|
|
|
|
@r1@
|
|
|
|
expression from,to;
|
|
|
|
expression flag;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
to = \(kmalloc@p\|kzalloc@p\)(strlen(from) + 1,flag);
|
|
|
|
|
|
|
|
@r2@
|
|
|
|
expression x,from,to;
|
|
|
|
expression flag,E1;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
x = strlen(from) + 1;
|
|
|
|
... when != \( x = E1 \| from = E1 \)
|
|
|
|
to = \(kmalloc@p\|kzalloc@p\)(x,flag);
|
|
|
|
|
2012-01-15 02:41:54 +04:00
|
|
|
@depends on patch@
|
2010-08-24 19:39:06 +04:00
|
|
|
expression from,to,size,flag;
|
|
|
|
position p != {r1.p,r2.p};
|
|
|
|
statement S;
|
|
|
|
@@
|
|
|
|
|
|
|
|
- to = \(kmalloc@p\|kzalloc@p\)(size,flag);
|
|
|
|
+ to = kmemdup(from,size,flag);
|
|
|
|
if (to==NULL || ...) S
|
|
|
|
- memcpy(to, from, size);
|
2012-01-15 02:41:54 +04:00
|
|
|
|
|
|
|
@r depends on !patch@
|
|
|
|
expression from,to,size,flag;
|
|
|
|
position p != {r1.p,r2.p};
|
|
|
|
statement S;
|
|
|
|
@@
|
|
|
|
|
|
|
|
* to = \(kmalloc@p\|kzalloc@p\)(size,flag);
|
|
|
|
if (to==NULL || ...) S
|
|
|
|
* memcpy(to, from, size);
|
|
|
|
|
|
|
|
@script:python depends on org@
|
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
2018-03-01 11:57:21 +03:00
|
|
|
coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdup")
|
2012-01-15 02:41:54 +04:00
|
|
|
|
|
|
|
@script:python depends on report@
|
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
2018-03-01 11:57:21 +03:00
|
|
|
coccilib.report.print_report(p[0], "WARNING opportunity for kmemdup")
|