[Cocci] [PATCH v4] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Sumera Priyadarsini
Modify coccinelle documentation to further clarify
the usage of the makefile C variable by coccicheck.

Signed-off-by: Sumera Priyadarsini 

---
Changes in v4:
- Modify commit message to clarify C is a variable
---
 Documentation/dev-tools/coccinelle.rst | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Documentation/dev-tools/coccinelle.rst 
b/Documentation/dev-tools/coccinelle.rst
index 6c791af1c859..74c5e6aeeff5 100644
--- a/Documentation/dev-tools/coccinelle.rst
+++ b/Documentation/dev-tools/coccinelle.rst
@@ -175,13 +175,20 @@ For example, to check drivers/net/wireless/ one may 
write::
 make coccicheck M=drivers/net/wireless/
 
 To apply Coccinelle on a file basis, instead of a directory basis, the
-following command may be used::
+C variable is used by the makefile to select which files to work with.
+This variable can be used to run scripts for the entire kernel, a
+specific directory, or for a single file.
 
-make C=1 CHECK="scripts/coccicheck"
+For example, to check drivers/bluetooth/bfusb.c, the value 1 is
+passed to the C variable to check files that make considers
+need to be compiled.::
 
-To check only newly edited code, use the value 2 for the C flag, i.e.::
+make C=1 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
 
-make C=2 CHECK="scripts/coccicheck"
+The value 2 is passed to the C variable to check files regardless of
+whether they need to be compiled or not.::
+
+make C=2 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
 
 In these modes, which work on a file basis, there is no information
 about semantic patches displayed, and no commit message proposed.
-- 
2.17.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v3] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Julia Lawall


On Mon, 10 Aug 2020, Markus Elfring wrote:

> > the usage of the makefile C variable flag by coccicheck.
>
> * Can it be confusing to denote an item as a variable and a flag?
>
> * Would you really like to stress here that a flag can be variable?

This is not part of the documentation, so it doesn't really matter.

Nevertheless, Sumera, there is stail an occurrence of flag in the proposed
change to the documentation, so you could indeed change that one to
variable.

>
>
> > +This variable can be used to run scripts for …
>
> Can the scope for a make command be selected also without such a variable?

If you know something that is different than what is in the documentation,
then please say what it is.  Don't just ask questions.

> Will clarification requests for previously mentioned background information
> influence the proposed descriptions any further?

The point is to document the use of make coccicheck, not the C variables.
So the point about KBUILD_CHECK, while interesting, does not seem
appropriate for this documentation.

julia___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v3] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Markus Elfring
> the usage of the makefile C variable flag by coccicheck.

* Can it be confusing to denote an item as a variable and a flag?

* Would you really like to stress here that a flag can be variable?


> +This variable can be used to run scripts for …

Can the scope for a make command be selected also without such a variable?


Will clarification requests for previously mentioned background information
influence the proposed descriptions any further?

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v3] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Julia Lawall



On Mon, 10 Aug 2020, Sumera Priyadarsini wrote:

> Modify coccinelle documentation to further clarify
> the usage of the makefile C variable flag by coccicheck.
>
> Signed-off-by: Sumera Priyadarsini 

Thanks.

Acked-by: Julia Lawall 



>
> ---
> Changes in v3:
> - Remove quotes as suggested by Markus Elfring
>   - Change in wording, and punctuation, as suggested by Julia Lawall
> ---
>  Documentation/dev-tools/coccinelle.rst | 15 +++
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/dev-tools/coccinelle.rst 
> b/Documentation/dev-tools/coccinelle.rst
> index 6c791af1c859..74c5e6aeeff5 100644
> --- a/Documentation/dev-tools/coccinelle.rst
> +++ b/Documentation/dev-tools/coccinelle.rst
> @@ -175,13 +175,20 @@ For example, to check drivers/net/wireless/ one may 
> write::
>  make coccicheck M=drivers/net/wireless/
>
>  To apply Coccinelle on a file basis, instead of a directory basis, the
> -following command may be used::
> +C variable is used by the makefile to select which files to work with.
> +This variable can be used to run scripts for the entire kernel, a
> +specific directory, or for a single file.
>
> -make C=1 CHECK="scripts/coccicheck"
> +For example, to check drivers/bluetooth/bfusb.c, the value 1 is
> +passed to the C variable to check files that make considers
> +need to be compiled.::
>
> -To check only newly edited code, use the value 2 for the C flag, i.e.::
> +make C=1 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
>
> -make C=2 CHECK="scripts/coccicheck"
> +The value 2 is passed to the C variable to check files regardless of
> +whether they need to be compiled or not.::
> +
> +make C=2 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
>
>  In these modes, which work on a file basis, there is no information
>  about semantic patches displayed, and no commit message proposed.
> --
> 2.17.1
>
> ___
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH v3] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Sumera Priyadarsini
Modify coccinelle documentation to further clarify
the usage of the makefile C variable flag by coccicheck.

Signed-off-by: Sumera Priyadarsini 

---
Changes in v3:
- Remove quotes as suggested by Markus Elfring
- Change in wording, and punctuation, as suggested by Julia Lawall
---
 Documentation/dev-tools/coccinelle.rst | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Documentation/dev-tools/coccinelle.rst 
b/Documentation/dev-tools/coccinelle.rst
index 6c791af1c859..74c5e6aeeff5 100644
--- a/Documentation/dev-tools/coccinelle.rst
+++ b/Documentation/dev-tools/coccinelle.rst
@@ -175,13 +175,20 @@ For example, to check drivers/net/wireless/ one may 
write::
 make coccicheck M=drivers/net/wireless/
 
 To apply Coccinelle on a file basis, instead of a directory basis, the
-following command may be used::
+C variable is used by the makefile to select which files to work with.
+This variable can be used to run scripts for the entire kernel, a
+specific directory, or for a single file.
 
-make C=1 CHECK="scripts/coccicheck"
+For example, to check drivers/bluetooth/bfusb.c, the value 1 is
+passed to the C variable to check files that make considers
+need to be compiled.::
 
-To check only newly edited code, use the value 2 for the C flag, i.e.::
+make C=1 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
 
-make C=2 CHECK="scripts/coccicheck"
+The value 2 is passed to the C variable to check files regardless of
+whether they need to be compiled or not.::
+
+make C=2 CHECK=scripts/coccicheck drivers/bluetooth/bfusb.o
 
 In these modes, which work on a file basis, there is no information
 about semantic patches displayed, and no commit message proposed.
-- 
2.17.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 5.4 23/67] scripts: add dummy report mode to add_namespace.cocci

2020-08-10 Thread Greg Kroah-Hartman
From: Matthias Maennich 

commit 55c7549819e438f40a3ef1d8ac5c38b73390bcb7 upstream.

When running `make coccicheck` in report mode using the
add_namespace.cocci file, it will fail for files that contain
MODULE_LICENSE. Those match the replacement precondition, but spatch
errors out as virtual.ns is not set.

In order to fix that, add the virtual rule nsdeps and only do search and
replace if that rule has been explicitly requested.

In order to make spatch happy in report mode, we also need a dummy rule,
as otherwise it errors out with "No rules apply". Using a script:python
rule appears unrelated and odd, but this is the shortest I could come up
with.

Adjust scripts/nsdeps accordingly to set the nsdeps rule when run trough
`make nsdeps`.

Suggested-by: Julia Lawall 
Fixes: c7c4e29fb5a4 ("scripts: add_namespace: Fix coccicheck failed")
Cc: YueHaibing 
Cc: j...@kernel.org
Cc: cocci@systeme.lip6.fr
Cc: sta...@vger.kernel.org
Signed-off-by: Matthias Maennich 
Reported-by: Shuah Khan 
Acked-by: Julia Lawall 
Link: https://lore.kernel.org/r/20200604164145.173925-1-maenn...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/coccinelle/misc/add_namespace.cocci |8 +++-
 scripts/nsdeps  |2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

--- a/scripts/coccinelle/misc/add_namespace.cocci
+++ b/scripts/coccinelle/misc/add_namespace.cocci
@@ -6,6 +6,7 @@
 /// add a missing namespace tag to a module source file.
 ///
 
+virtual nsdeps
 virtual report
 
 @has_ns_import@
@@ -16,10 +17,15 @@ MODULE_IMPORT_NS(ns);
 
 // Add missing imports, but only adjacent to a MODULE_LICENSE statement.
 // That ensures we are adding it only to the main module source file.
-@do_import depends on !has_ns_import@
+@do_import depends on !has_ns_import && nsdeps@
 declarer name MODULE_LICENSE;
 expression license;
 identifier virtual.ns;
 @@
 MODULE_LICENSE(license);
 + MODULE_IMPORT_NS(ns);
+
+// Dummy rule for report mode that would otherwise be empty and make spatch
+// fail ("No rules apply.")
+@script:python depends on report@
+@@
--- a/scripts/nsdeps
+++ b/scripts/nsdeps
@@ -23,7 +23,7 @@ fi
 
 generate_deps_for_ns() {
$SPATCH --very-quiet --in-place --sp-file \
-   $srctree/scripts/coccinelle/misc/add_namespace.cocci -D ns=$1 $2
+   $srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps 
-D ns=$1 $2
 }
 
 generate_deps() {


___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 5.7 21/79] scripts: add dummy report mode to add_namespace.cocci

2020-08-10 Thread Greg Kroah-Hartman
From: Matthias Maennich 

commit 55c7549819e438f40a3ef1d8ac5c38b73390bcb7 upstream.

When running `make coccicheck` in report mode using the
add_namespace.cocci file, it will fail for files that contain
MODULE_LICENSE. Those match the replacement precondition, but spatch
errors out as virtual.ns is not set.

In order to fix that, add the virtual rule nsdeps and only do search and
replace if that rule has been explicitly requested.

In order to make spatch happy in report mode, we also need a dummy rule,
as otherwise it errors out with "No rules apply". Using a script:python
rule appears unrelated and odd, but this is the shortest I could come up
with.

Adjust scripts/nsdeps accordingly to set the nsdeps rule when run trough
`make nsdeps`.

Suggested-by: Julia Lawall 
Fixes: c7c4e29fb5a4 ("scripts: add_namespace: Fix coccicheck failed")
Cc: YueHaibing 
Cc: j...@kernel.org
Cc: cocci@systeme.lip6.fr
Cc: sta...@vger.kernel.org
Signed-off-by: Matthias Maennich 
Reported-by: Shuah Khan 
Acked-by: Julia Lawall 
Link: https://lore.kernel.org/r/20200604164145.173925-1-maenn...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/coccinelle/misc/add_namespace.cocci |8 +++-
 scripts/nsdeps  |2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

--- a/scripts/coccinelle/misc/add_namespace.cocci
+++ b/scripts/coccinelle/misc/add_namespace.cocci
@@ -6,6 +6,7 @@
 /// add a missing namespace tag to a module source file.
 ///
 
+virtual nsdeps
 virtual report
 
 @has_ns_import@
@@ -16,10 +17,15 @@ MODULE_IMPORT_NS(ns);
 
 // Add missing imports, but only adjacent to a MODULE_LICENSE statement.
 // That ensures we are adding it only to the main module source file.
-@do_import depends on !has_ns_import@
+@do_import depends on !has_ns_import && nsdeps@
 declarer name MODULE_LICENSE;
 expression license;
 identifier virtual.ns;
 @@
 MODULE_LICENSE(license);
 + MODULE_IMPORT_NS(ns);
+
+// Dummy rule for report mode that would otherwise be empty and make spatch
+// fail ("No rules apply.")
+@script:python depends on report@
+@@
--- a/scripts/nsdeps
+++ b/scripts/nsdeps
@@ -29,7 +29,7 @@ fi
 
 generate_deps_for_ns() {
$SPATCH --very-quiet --in-place --sp-file \
-   $srctree/scripts/coccinelle/misc/add_namespace.cocci -D ns=$1 $2
+   $srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps 
-D ns=$1 $2
 }
 
 generate_deps() {


___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 5.8 21/38] scripts: add dummy report mode to add_namespace.cocci

2020-08-10 Thread Greg Kroah-Hartman
From: Matthias Maennich 

commit 55c7549819e438f40a3ef1d8ac5c38b73390bcb7 upstream.

When running `make coccicheck` in report mode using the
add_namespace.cocci file, it will fail for files that contain
MODULE_LICENSE. Those match the replacement precondition, but spatch
errors out as virtual.ns is not set.

In order to fix that, add the virtual rule nsdeps and only do search and
replace if that rule has been explicitly requested.

In order to make spatch happy in report mode, we also need a dummy rule,
as otherwise it errors out with "No rules apply". Using a script:python
rule appears unrelated and odd, but this is the shortest I could come up
with.

Adjust scripts/nsdeps accordingly to set the nsdeps rule when run trough
`make nsdeps`.

Suggested-by: Julia Lawall 
Fixes: c7c4e29fb5a4 ("scripts: add_namespace: Fix coccicheck failed")
Cc: YueHaibing 
Cc: j...@kernel.org
Cc: cocci@systeme.lip6.fr
Cc: sta...@vger.kernel.org
Signed-off-by: Matthias Maennich 
Reported-by: Shuah Khan 
Acked-by: Julia Lawall 
Link: https://lore.kernel.org/r/20200604164145.173925-1-maenn...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/coccinelle/misc/add_namespace.cocci |8 +++-
 scripts/nsdeps  |2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

--- a/scripts/coccinelle/misc/add_namespace.cocci
+++ b/scripts/coccinelle/misc/add_namespace.cocci
@@ -6,6 +6,7 @@
 /// add a missing namespace tag to a module source file.
 ///
 
+virtual nsdeps
 virtual report
 
 @has_ns_import@
@@ -16,10 +17,15 @@ MODULE_IMPORT_NS(ns);
 
 // Add missing imports, but only adjacent to a MODULE_LICENSE statement.
 // That ensures we are adding it only to the main module source file.
-@do_import depends on !has_ns_import@
+@do_import depends on !has_ns_import && nsdeps@
 declarer name MODULE_LICENSE;
 expression license;
 identifier virtual.ns;
 @@
 MODULE_LICENSE(license);
 + MODULE_IMPORT_NS(ns);
+
+// Dummy rule for report mode that would otherwise be empty and make spatch
+// fail ("No rules apply.")
+@script:python depends on report@
+@@
--- a/scripts/nsdeps
+++ b/scripts/nsdeps
@@ -29,7 +29,7 @@ fi
 
 generate_deps_for_ns() {
$SPATCH --very-quiet --in-place --sp-file \
-   $srctree/scripts/coccinelle/misc/add_namespace.cocci -D ns=$1 $2
+   $srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps 
-D ns=$1 $2
 }
 
 generate_deps() {


___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v2] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Julia Lawall


On Mon, 10 Aug 2020, Jonathan Corbet wrote:

> On Mon, 10 Aug 2020 09:30:18 +0200
> Markus Elfring  wrote:
>
> > > Modify coccinelle documentation to further clarify
> > > the usage of the makefile C variable flag by coccicheck.
> >
> > How do you think about a wording variant like the following
> > for the change description?
> >
> >Clarify the usage of the make variable “C” for coccicheck.
> >
> >
> > > +C flag is used. The C flag is a variable used by the makefile
> >
> > Can such a wording approach trigger understanding difficulties?
> > [...]
>
> Markus, please don't harass our contributors.  This patch is an
> improvement and, unless Julia disagrees, I am happy to apply it.

There will be a V3.  Thanks.

julia___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH] Coccinelle: Reduce duplicate code for patch rules of memdup_user.cocci

2020-08-10 Thread Markus Elfring
From: Markus Elfring 
Date: Sun, 9 Aug 2020 11:11:20 +0200

Another patch rule was added. A bit of code was copied from a previous
SmPL rule for this change specification.

* Thus reduce duplicate code by using another SmPL disjunction.

* Increase the precision a bit for desired source code adjustments.

Fixes: 9c568dbd677bcfc975220d3157c89c48669a23e3 ("coccinelle: api: extend 
memdup_user rule with vmemdup_user()")
Signed-off-by: Markus Elfring 
---
 scripts/coccinelle/api/memdup_user.cocci | 44 +---
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/scripts/coccinelle/api/memdup_user.cocci 
b/scripts/coccinelle/api/memdup_user.cocci
index e01e95108405..7cf698b4e925 100644
--- a/scripts/coccinelle/api/memdup_user.cocci
+++ b/scripts/coccinelle/api/memdup_user.cocci
@@ -27,34 +27,22 @@ expression from,to,size;
 identifier l1,l2;
 position p : script:python() { relevant(p) };
 @@
-
--  to = \(kmalloc@p\|kzalloc@p\)
--  (size,\(GFP_KERNEL\|GFP_USER\|
--\(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN\));
-+  to = memdup_user(from,size);
-   if (
--  to==NULL
-+  IS_ERR(to)
- || ...) {
-   <+... when != goto l1;
--  -ENOMEM
-+  PTR_ERR(to)
-   ...+>
-   }
--  if (copy_from_user(to, from, size) != 0) {
--<+... when != goto l2;
---EFAULT
--...+>
--  }
-
-@depends on patch@
-expression from,to,size;
-identifier l1,l2;
-position p : script:python() { relevant(p) };
-@@
-
--  to = \(kvmalloc@p\|kvzalloc@p\)(size,\(GFP_KERNEL\|GFP_USER\));
-+  to = vmemdup_user(from,size);
+ to =
+(
+- \(kmalloc@p\|kzalloc@p\)
++ memdup_user
+  (
+-  size, \( \(GFP_KERNEL\|GFP_USER\) \| 
\(GFP_KERNEL\|GFP_USER\)|__GFP_NOWARN \)
++  from, size
+  )
+|
+- \(kvmalloc@p\|kvzalloc@p\)
++ vmemdup_user
+  (
+-  size, \(GFP_KERNEL\|GFP_USER\)
++  from, size
+  )
+);
if (
 -  to==NULL
 +  IS_ERR(to)
--
2.28.0

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v2] documentation: coccinelle: Improve command example for make C={1, 2}

2020-08-10 Thread Markus Elfring
> Modify coccinelle documentation to further clarify
> the usage of the makefile C variable flag by coccicheck.

How do you think about a wording variant like the following
for the change description?

   Clarify the usage of the make variable “C” for coccicheck.


> +C flag is used. The C flag is a variable used by the makefile

Can such a wording approach trigger understanding difficulties?


> +This flag can be used to
> +run scripts for …

I find this description improvable.


> +The value 1 is passed to the C flag to check for files that make considers
> +need to be recompiled.::

Would you like to distinguish consequences between “compilation” and 
“recompilation”?

The mentioned parameter is assigned to the macro “KBUILD_CHECKSRC”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?id=fc80c51fd4b23ec007e88d4c688f2cac1b8648e7#n198

The macro “KBUILD_CHECKSRC” is eventually checked for the setting of a few 
additional macros.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.build?id=fc80c51fd4b23ec007e88d4c688f2cac1b8648e7#n97

Would you like to determine where these macros are actually applied?

Do you find the commit 0c33f125732d0d33392ba6774d85469d565d3496 ("kbuild:
run the checker after the compiler") from 2020-07-07 interesting for
the discussed documentation adjustment?
https://lore.kernel.org/patchwork/patch/1260832/
https://lore.kernel.org/lkml/20200622154512.82758-1-luc.vanoostenr...@gmail.com/


> +make C=1 CHECK="scripts/coccicheck" "drivers/bluetooth/bfusb.o"

* Can double quotes be omitted here?

* How do you think about to enclose any data by apostrophes?

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci