
Pull Kbuild updates from Masahiro Yamada: - remove headers_{install,check}_all targets - remove unreasonable 'depends on !UML' from CONFIG_SAMPLES - re-implement 'make headers_install' more cleanly - add new header-test-y syntax to compile-test headers - compile-test exported headers to ensure they are compilable in user-space - compile-test headers under include/ to ensure they are self-contained - remove -Waggregate-return, -Wno-uninitialized, -Wno-unused-value flags - add -Werror=unknown-warning-option for Clang - add 128-bit built-in types support to genksyms - fix missed rebuild of modules.builtin - propagate 'No space left on device' error in fixdep to Make - allow Clang to use its integrated assembler - improve some coccinelle scripts - add a new flag KBUILD_ABS_SRCTREE to request Kbuild to use absolute path for $(srctree). - do not ignore errors when compression utility is missing - misc cleanups * tag 'kbuild-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (49 commits) kbuild: use -- separater intead of $(filter-out ...) for cc-cross-prefix kbuild: Inform user to pass ARCH= for make mrproper kbuild: fix compression errors getting ignored kbuild: add a flag to force absolute path for srctree kbuild: replace KBUILD_SRCTREE with boolean building_out_of_srctree kbuild: remove src and obj from the top Makefile scripts/tags.sh: remove unused environment variables from comments scripts/tags.sh: drop SUBARCH support for ARM kbuild: compile-test kernel headers to ensure they are self-contained kheaders: include only headers into kheaders_data.tar.xz kheaders: remove meaningless -R option of 'ls' kbuild: support header-test-pattern-y kbuild: do not create wrappers for header-test-y kbuild: compile-test exported headers to ensure they are self-contained init/Kconfig: add CONFIG_CC_CAN_LINK kallsyms: exclude kasan local symbols on s390 kbuild: add more hints about SUBDIRS replacement coccinelle: api/stream_open: treat all wait_.*() calls as blocking coccinelle: put_device: Add a cast to an expression for an assignment coccinelle: put_device: Adjust a message construction ...
106 lines
2.4 KiB
Plaintext
106 lines
2.4 KiB
Plaintext
// SPDX-License-Identifier: GPL-2.0-only
|
|
/// Use kstrdup rather than duplicating its implementation
|
|
///
|
|
// Confidence: High
|
|
// Copyright: (C) 2010-2012 Nicolas Palix.
|
|
// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
|
|
// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
|
|
// URL: http://coccinelle.lip6.fr/
|
|
// Comments:
|
|
// Options: --no-includes --include-headers
|
|
|
|
virtual patch
|
|
virtual context
|
|
virtual org
|
|
virtual report
|
|
|
|
@depends on patch@
|
|
expression from,to;
|
|
expression flag,E1,E2;
|
|
statement S;
|
|
@@
|
|
|
|
- to = kmalloc(strlen(from) + 1,flag);
|
|
+ to = kstrdup(from, flag);
|
|
... when != \(from = E1 \| to = E1 \)
|
|
if (to==NULL || ...) S
|
|
... when != \(from = E2 \| to = E2 \)
|
|
- strcpy(to, from);
|
|
|
|
@depends on patch@
|
|
expression x,from,to;
|
|
expression flag,E1,E2,E3;
|
|
statement S;
|
|
@@
|
|
|
|
- x = strlen(from) + 1;
|
|
... when != \( x = E1 \| from = E1 \)
|
|
- to = \(kmalloc\|kzalloc\)(x,flag);
|
|
+ to = kstrdup(from, flag);
|
|
... when != \(x = E2 \| from = E2 \| to = E2 \)
|
|
if (to==NULL || ...) S
|
|
... when != \(x = E3 \| from = E3 \| to = E3 \)
|
|
- memcpy(to, from, x);
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
@r1 depends on !patch exists@
|
|
expression from,to;
|
|
expression flag,E1,E2;
|
|
statement S;
|
|
position p1,p2;
|
|
@@
|
|
|
|
* to = kmalloc@p1(strlen(from) + 1,flag);
|
|
... when != \(from = E1 \| to = E1 \)
|
|
if (to==NULL || ...) S
|
|
... when != \(from = E2 \| to = E2 \)
|
|
* strcpy@p2(to, from);
|
|
|
|
@r2 depends on !patch exists@
|
|
expression x,from,to;
|
|
expression flag,E1,E2,E3;
|
|
statement S;
|
|
position p1,p2;
|
|
@@
|
|
|
|
* x = strlen(from) + 1;
|
|
... when != \( x = E1 \| from = E1 \)
|
|
* to = \(kmalloc@p1\|kzalloc@p2\)(x,flag);
|
|
... when != \(x = E2 \| from = E2 \| to = E2 \)
|
|
if (to==NULL || ...) S
|
|
... when != \(x = E3 \| from = E3 \| to = E3 \)
|
|
* memcpy@p2(to, from, x);
|
|
|
|
@script:python depends on org@
|
|
p1 << r1.p1;
|
|
p2 << r1.p2;
|
|
@@
|
|
|
|
cocci.print_main("WARNING opportunity for kstrdup",p1)
|
|
cocci.print_secs("strcpy",p2)
|
|
|
|
@script:python depends on org@
|
|
p1 << r2.p1;
|
|
p2 << r2.p2;
|
|
@@
|
|
|
|
cocci.print_main("WARNING opportunity for kstrdup",p1)
|
|
cocci.print_secs("memcpy",p2)
|
|
|
|
@script:python depends on report@
|
|
p1 << r1.p1;
|
|
p2 << r1.p2;
|
|
@@
|
|
|
|
msg = "WARNING opportunity for kstrdup (strcpy on line %s)" % (p2[0].line)
|
|
coccilib.report.print_report(p1[0], msg)
|
|
|
|
@script:python depends on report@
|
|
p1 << r2.p1;
|
|
p2 << r2.p2;
|
|
@@
|
|
|
|
msg = "WARNING opportunity for kstrdup (memcpy on line %s)" % (p2[0].line)
|
|
coccilib.report.print_report(p1[0], msg)
|