Re: [Cocci] cocci script to convert linux-kernel allocs with BITS_TO_LONGS to bitmap_alloc

2021-07-13 Thread Joe Perches
On Tue, 2021-07-13 at 23:33 +0200, Julia Lawall wrote:
> > > On Fri, 9 Jul 2021, Joe Perches wrote:
> > > > Here is a cocci script to convert various types of bitmap allocations
> > > > that use BITS_TO_LONGS to the more typical bitmap_alloc functions.
> 
> I see that there is also a bitmap_free.  Maybe the rule should be
> introducing that as well?

Yes, but as far as I know, it's difficult for coccinelle to convert
the kfree() calls of any previous bitmap_alloc to bitmap_free as
most frequently the kfree() call is in a separate function.

Please do it if you know how, you're probably the best in the world
at coccinelle.  I don't know how...

cheers, Joe

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


Re: [Cocci] cocci script to convert linux-kernel allocs with BITS_TO_LONGS to bitmap_alloc

2021-07-13 Thread Julia Lawall



On Sat, 10 Jul 2021, Joe Perches wrote:

> On Sat, 2021-07-10 at 21:50 +0200, Julia Lawall wrote:
> > On Fri, 9 Jul 2021, Joe Perches wrote:
> >
> > > Here is a cocci script to convert various types of bitmap allocations
> > > that use BITS_TO_LONGS to the more typical bitmap_alloc functions.

I see that there is also a bitmap_free.  Maybe the rule should be
introducing that as well?

julia

> > >
> > > Perhaps something like it could be added to scripts/coccinelle.
> > > The diff produced by the script is also below.
> > >
> > > $ cat bitmap_allocs.cocci
> > > // typical uses of bitmap allocations
> []
> > > @@
> > > expression val;
> > > expression e1;
> > > expression e2;
> > > @@
> > >
> > > - val = kcalloc(BITS_TO_LONGS(e1), sizeof(*val), e2)
> > > + val = bitmap_zalloc(e1, e2)
> >
> > Is there something that guarantees that val has a type that has a size that
> > is the same as a long?
>
> no, but afaict, all do.
>
>
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH V2 2/2] docs: manual: Add option description in spatch_options

2021-07-13 Thread Sumera Priyadarsini
Add documentation for the "use-patch-diff" option introduced in
the first patch of this patchset. This option allows for
applying a semantic patch to only those files in a directory
where code additions have been made.

Signed-off-by: Sumera Priyadarsini 
---
Changes in V2:
- Change "use-patchdiff" to "use-patch-diff" (Julia)
---
 docs/manual/spatch_options.tex | 5 +
 1 file changed, 5 insertions(+)

diff --git a/docs/manual/spatch_options.tex b/docs/manual/spatch_options.tex
index a372aaf8a..393d254e3 100644
--- a/docs/manual/spatch_options.tex
+++ b/docs/manual/spatch_options.tex
@@ -220,6 +220,11 @@ intereted relative to the target directory.  If the 
filename is an absolute
 path name, beginning with /, it is used as is.
 }
 
+\normal{-{}-use-patch-diff}{ This option allows for applying a semantic patch
+  to only the files that have been modified in a directory. The directory needs
+  to be specified by the user. Note that an absolute path needs to be used if
+  spatch is called from outside the target project directory. }
+
 \normal{-{}-use-coccigrep}{ Use a version of grep implemented in Coccinelle
   to check that selected files are relevant to the semantic patch.  This
   option is only relevant to the case of working on a complete directory,
-- 
2.32.0

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


[Cocci] [PATCH V2 1/2] parsing_cocci: Add feature to check only modified files

2021-07-13 Thread Sumera Priyadarsini
This patch adds an option "use-patch-diff" to allow for
applying a semantic patch to only those files in a directory
where code additions have been made.

Usage: spatch -D  --sp-file  --use-patch-diff 

Example: spatch -D report --sp-file for_each_child.cocci --use-patch-diff 
drivers/gpu

Signed-off-by: Sumera Priyadarsini 
---
Changes in V2:
- Change "use-patchdiff" to "use-patch-diff" (Julia)
---
 Makefile|   2 +-
 enter.ml|  17 +++--
 globals/flag.ml |   2 +-
 globals/flag.mli|   2 +-
 ocaml/coccilib.mli  |   1 +
 parsing_cocci/get_constants2.ml |   1 +
 parsing_cocci/patch_diff.ml | 118 
 parsing_cocci/patch_diff.mli|   9 +++
 8 files changed, 143 insertions(+), 9 deletions(-)
 create mode 100755 parsing_cocci/patch_diff.ml
 create mode 100644 parsing_cocci/patch_diff.mli

diff --git a/Makefile b/Makefile
index f8d3424c0..455e92395 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ SOURCES_parsing_cocci := \
parse_printf.ml parse_aux.ml cleanup_rules.ml disjdistr.ml \
parser_cocci_menhir.mly lexer_cocci.mll \
lexer_cli.mll lexer_script.mll \
-   cocci_grep.ml dpll.ml get_constants2.ml id_utils.ml git_grep.ml \
+   cocci_grep.ml dpll.ml get_constants2.ml id_utils.ml git_grep.ml 
patch_diff.ml \
adjacency.ml commas_on_lists.ml re_constraints.ml parse_cocci.ml \
command_line.ml cocci_args.ml
 SOURCES_parsing_c := \
diff --git a/enter.ml b/enter.ml
index 77e1540fd..1219c027d 100644
--- a/enter.ml
+++ b/enter.ml
@@ -18,9 +18,7 @@ module Inc = Includes
  * globals/config.ml, mainly a standard.h and standard.iso file *)
 
 let cocci_file = ref ""
-
 let opt_c_files = ref []
-
 let output_file = ref "" (* resulting code *)
 let tmp_dir = ref "" (* temporary files for parallelism *)
 let aux_file_suffix =
@@ -283,7 +281,6 @@ let print_version () =
 let short_options = [
   "--sp-file",  Arg.Set_string cocci_file,
   "  the semantic patch file";
-
   "--opt-c",
   Arg.String (fun filename ->
 if Sys.file_exists filename
@@ -370,6 +367,9 @@ let short_options = [
   "--use-coccigrep",
   Arg.Unit (function _ -> Flag.scanner := Flag.CocciGrep),
   "find relevant files using cocci grep";
+  "--use-patch-diff",
+  Arg.Unit (function _ -> Flag.scanner := Flag.PatchDiff),
+  "process files in the diff for a directory";
   "--patch",
 Arg.String (function s -> Flag.patch := Some (Cocci.normalize_path s)),
   (" path name with respect to which a patch should be created\n"^
@@ -940,13 +940,18 @@ let idutils_filter (_,_,_,query) dir =
   Some
(files +>
 List.filter
-  (fun file -> List.mem (Common.filesuffix file) suffixes))
+ (fun file -> List.mem (Common.filesuffix file) suffixes))
+
+let patchdiff_filter _ dir =
+  let struc = Patch_diff.getpatchdiff dir in
+  Some (List.map (function x -> x.Patch_diff.file_name) struc)
 
 let scanner_to_interpreter = function
 Flag.Glimpse -> glimpse_filter
   | Flag.IdUtils -> idutils_filter
   | Flag.CocciGrep -> coccigrep_filter
   | Flag.GitGrep -> gitgrep_filter
+  | Flag.PatchDiff -> patchdiff_filter
   | _ -> failwith "impossible"
 
 (*)
@@ -1079,7 +1084,7 @@ let rec main_action xs =
 " or multiple files")
   | _, false, _, _, _ -> [List.map (fun x -> (x,None)) (x::xs)]
  | _, true, "",
- (Flag.Glimpse|Flag.IdUtils|Flag.CocciGrep|Flag.GitGrep),
+ 
(Flag.Glimpse|Flag.IdUtils|Flag.CocciGrep|Flag.GitGrep|Flag.PatchDiff),
  [] ->
let interpreter = scanner_to_interpreter !Flag.scanner in
let files =
@@ -1088,7 +1093,7 @@ let rec main_action xs =
  | Some files -> files in
 files +> List.map (fun x -> [(x,None)])
   | _, true, s,
- (Flag.Glimpse|Flag.IdUtils|Flag.CocciGrep|Flag.GitGrep), _
+ 
(Flag.Glimpse|Flag.IdUtils|Flag.CocciGrep|Flag.GitGrep|Flag.PatchDiff), _
when s <> "" ->
   failwith "--use-xxx filters do not work with --kbuild"
   (* normal *)
diff --git a/globals/flag.ml b/globals/flag.ml
index e1d01cb4c..dffe6cd80 100644
--- a/globals/flag.ml
+++ b/globals/flag.ml
@@ -16,7 +16,7 @@ let track_iso_usage = ref false
 
 let worth_trying_opt = ref true
 
-type scanner = IdUtils | Glimpse | CocciGrep | GitGrep | NoScanner
+type scanner = IdUtils | Glimpse | CocciGrep | GitGrep | PatchDiff | NoScanner
 let scanner = ref NoScanner
 
 let pyoutput = ref "coccilib.output.Console"
diff --git a/globals/flag.mli b/globals/flag.mli
index dadc7b6fc..0e8a3b063 100644
--- a/globals/flag.mli
+++ b/globals/flag.mli
@@ -4,7 +4,7 @@ val show_transinfo : bool ref
 val show_trying : bool ref
 val track_iso_usage : bool ref
 

[Cocci] [PATCH V2 0/2] Add "use-patch-diff" option

2021-07-13 Thread Sumera Priyadarsini
This patchset adds a feature to enable Coccinelle
to only check all those files in a directory which were
modified. It parses all the files obtained from the
output of "git diff" and checks them against the specified
cocci script.

An example for passing the "use-patchdiff" option is:

spatch -D report --sp-file for_each_child.cocci --use-patchdiff 
drivers/gpu

One thing to note while using the command is that while it can be
invoked outside the target project directory, an absolute path
to the target folder should be specified in such cases.

Sumera Priyadarsini (2):
  parsing_cocci: Add feature to check only modified files
  docs: manual: Add option description in spatch_options

 Makefile|   2 +-
 docs/manual/spatch_options.tex  |   5 ++
 enter.ml|  17 +++--
 globals/flag.ml |   2 +-
 globals/flag.mli|   2 +-
 ocaml/coccilib.mli  |   1 +
 parsing_cocci/get_constants2.ml |   1 +
 parsing_cocci/patch_diff.ml | 118 
 parsing_cocci/patch_diff.mli|   9 +++
 9 files changed, 148 insertions(+), 9 deletions(-)
 create mode 100755 parsing_cocci/patch_diff.ml
 create mode 100644 parsing_cocci/patch_diff.mli

-- 
2.32.0

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