Commit 42dc45e8 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull coccinelle updates from Julia Lawall.

* 'for-5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux:
  scripts: coccicheck: Correct usage of make coccicheck
  coccinelle: update expiring email addresses
  coccinnelle: Remove ptr_ret script
  kbuild: do not use scripts/ld-version.sh for checking spatch version
  remove boolinit.cocci
parents 11cc92eb d8f6e5c6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4355,8 +4355,8 @@ T: git git://linuxtv.org/media_tree.git
F:	drivers/media/pci/cobalt/
COCCINELLE/Semantic Patches (SmPL)
M:	Julia Lawall <Julia.Lawall@lip6.fr>
M:	Gilles Muller <Gilles.Muller@lip6.fr>
M:	Julia Lawall <Julia.Lawall@inria.fr>
M:	Gilles Muller <Gilles.Muller@inria.fr>
M:	Nicolas Palix <nicolas.palix@imag.fr>
M:	Michal Marek <michal.lkml@markovi.net>
L:	cocci@systeme.lip6.fr (moderated for non-subscribers)
+17 −9
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ if [ ! -x "$SPATCH" ]; then
fi

SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
SPATCH_VERSION_NUM=$(echo $SPATCH_VERSION | ${DIR}/scripts/ld-version.sh)

USE_JOBS="no"
$SPATCH --help | grep "\-\-jobs" > /dev/null && USE_JOBS="yes"
@@ -61,6 +60,18 @@ COCCIINCLUDE=${COCCIINCLUDE// -include/ --include}
if [ "$C" = "1" -o "$C" = "2" ]; then
    ONLINE=1

    if [[ $# -le 0 ]]; then
	    echo ''
	    echo 'Specifying both the variable "C" and rule "coccicheck" in the make
command results in a shift count error.'
	    echo ''
	    echo 'Try specifying "scripts/coccicheck" as a value for the CHECK variable instead.'
	    echo ''
	    echo 'Example:	make C=2 CHECK=scripts/coccicheck drivers/net/ethernet/ethoc.o'
	    echo ''
	    exit 1
    fi

    # Take only the last argument, which is the C file to test
    shift $(( $# - 1 ))
    OPTIONS="$COCCIINCLUDE $1"
@@ -186,15 +197,12 @@ coccinelle () {

    OPT=`grep "Options:" $COCCI | cut -d':' -f2`
    REQ=`grep "Requires:" $COCCI | cut -d':' -f2 | sed "s| ||"`
    REQ_NUM=$(echo $REQ | ${DIR}/scripts/ld-version.sh)
    if [ "$REQ_NUM" != "0" ] ; then
	    if [ "$SPATCH_VERSION_NUM" -lt "$REQ_NUM" ] ; then
    if [ -n "$REQ" ] && ! { echo "$REQ"; echo "$SPATCH_VERSION"; } | sort -CV ; then
	    echo "Skipping coccinelle SmPL patch: $COCCI"
	    echo "You have coccinelle:           $SPATCH_VERSION"
	    echo "This SmPL patch requires:      $REQ"
	    return
    fi
    fi

#   The option '--parse-cocci' can be used to syntactically check the SmPL files.
#
+0 −97
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
///
/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
///
// Confidence: High
// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
// URL: http://coccinelle.lip6.fr/
// Options: --no-includes --include-headers
//
// Keywords: ERR_PTR, PTR_ERR, PTR_ERR_OR_ZERO
// Version min: 2.6.39
//

virtual context
virtual patch
virtual org
virtual report

@depends on patch@
expression ptr;
@@

- if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
+ return PTR_ERR_OR_ZERO(ptr);

@depends on patch@
expression ptr;
@@

- if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
+ return PTR_ERR_OR_ZERO(ptr);

@depends on patch@
expression ptr;
@@

- (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
+ PTR_ERR_OR_ZERO(ptr)

@r1 depends on !patch@
expression ptr;
position p1;
@@

* if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;

@r2 depends on !patch@
expression ptr;
position p2;
@@

* if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;

@r3 depends on !patch@
expression ptr;
position p3;
@@

* IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0

@script:python depends on org@
p << r1.p1;
@@

coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")


@script:python depends on org@
p << r2.p2;
@@

coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")

@script:python depends on org@
p << r3.p3;
@@

coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")

@script:python depends on report@
p << r1.p1;
@@

coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")

@script:python depends on report@
p << r2.p2;
@@

coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")

@script:python depends on report@
p << r3.p3;
@@

coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used")
+0 −195
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/// Bool initializations should use true and false.  Bool tests don't need
/// comparisons.  Based on contributions from Joe Perches, Rusty Russell
/// and Bruce W Allan.
///
// Confidence: High
// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
// URL: http://coccinelle.lip6.fr/
// Options: --include-headers

virtual patch
virtual context
virtual org
virtual report

@boolok@
symbol true,false;
@@
(
true
|
false
)

@depends on patch@
bool t;
@@

(
- t == true
+ t
|
- true == t
+ t
|
- t != true
+ !t
|
- true != t
+ !t
|
- t == false
+ !t
|
- false == t
+ !t
|
- t != false
+ t
|
- false != t
+ t
)

@depends on patch disable is_zero, isnt_zero@
bool t;
@@

(
- t == 1
+ t
|
- t != 1
+ !t
|
- t == 0
+ !t
|
- t != 0
+ t
)

@depends on patch && boolok@
bool b;
@@
(
 b =
- 0
+ false
|
 b =
- 1
+ true
)

// ---------------------------------------------------------------------

@r1 depends on !patch@
bool t;
position p;
@@

(
* t@p == true
|
* true == t@p
|
* t@p != true
|
* true != t@p
|
* t@p == false
|
* false == t@p
|
* t@p != false
|
* false != t@p
)

@r2 depends on !patch disable is_zero, isnt_zero@
bool t;
position p;
@@

(
* t@p == 1
|
* t@p != 1
|
* t@p == 0
|
* t@p != 0
)

@r3 depends on !patch && boolok@
bool b;
position p1;
@@
(
*b@p1 = 0
|
*b@p1 = 1
)

@r4 depends on !patch@
bool b;
position p2;
identifier i;
constant c != {0,1};
@@
(
 b = i
|
*b@p2 = c
)

@script:python depends on org@
p << r1.p;
@@

cocci.print_main("WARNING: Comparison to bool",p)

@script:python depends on org@
p << r2.p;
@@

cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p)

@script:python depends on org@
p1 << r3.p1;
@@

cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1)

@script:python depends on org@
p2 << r4.p2;
@@

cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2)

@script:python depends on report@
p << r1.p;
@@

coccilib.report.print_report(p[0],"WARNING: Comparison to bool")

@script:python depends on report@
p << r2.p;
@@

coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable")

@script:python depends on report@
p1 << r3.p1;
@@

coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable")

@script:python depends on report@
p2 << r4.p2;
@@

coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable")
+1 −3
Original line number Diff line number Diff line
@@ -12,11 +12,9 @@ if [ ! -x "$SPATCH" ]; then
	exit 1
fi

SPATCH_REQ_VERSION_NUM=$(echo $SPATCH_REQ_VERSION | ${DIR}/scripts/ld-version.sh)
SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
SPATCH_VERSION_NUM=$(echo $SPATCH_VERSION | ${DIR}/scripts/ld-version.sh)

if [ "$SPATCH_VERSION_NUM" -lt "$SPATCH_REQ_VERSION_NUM" ] ; then
if ! { echo "$SPATCH_REQ_VERSION"; echo "$SPATCH_VERSION"; } | sort -CV ; then
	echo "spatch needs to be version $SPATCH_REQ_VERSION or higher"
	exit 1
fi