Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1443588 > unrolled thread

[PATCH] Coccinelle: Script to use roundup and DIV_ROUND_UP

Started byAmitoj Kaur Chawla <amitoj1606@gmail.com>
First post2016-07-14 18:50 +0200
Last post2016-07-14 19:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] Coccinelle: Script to use roundup and DIV_ROUND_UP Amitoj Kaur Chawla <amitoj1606@gmail.com> - 2016-07-14 18:50 +0200
    Re: [PATCH] Coccinelle: Script to use roundup and DIV_ROUND_UP Julia Lawall <julia.lawall@lip6.fr> - 2016-07-14 19:10 +0200

#1443588 — [PATCH] Coccinelle: Script to use roundup and DIV_ROUND_UP

FromAmitoj Kaur Chawla <amitoj1606@gmail.com>
Date2016-07-14 18:50 +0200
Subject[PATCH] Coccinelle: Script to use roundup and DIV_ROUND_UP
Message-ID<rURZL-3En-9@gated-at.bofh.it>
This script replaces manual calculations by using the predefined
macros in kernel.h, DIV_ROUND_UP and roundup for readability purposes.

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 scripts/coccinelle/api/roundup.cocci | 215 +++++++++++++++++++++++++++++++++++
 1 file changed, 215 insertions(+)
 create mode 100644 scripts/coccinelle/api/roundup.cocci

diff --git a/scripts/coccinelle/api/roundup.cocci b/scripts/coccinelle/api/roundup.cocci
new file mode 100644
index 0000000..af97cd2
--- /dev/null
+++ b/scripts/coccinelle/api/roundup.cocci
@@ -0,0 +1,215 @@
+/// Use DIV_ROUND_UP and roundup to improve readability
+///
+// Confidence: High
+// Copyright: (C) 2016 Amitoj Kaur Chawla
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@haskernel@
+@@
+
+#include <linux/kernel.h>
+
+@round1 depends on haskernel && patch && !context && !org && !report@
+expression x, y;
+@@
+
+(
+- (((x + (y - 1)) / y) * y)
++ roundup(x, y)
+|
+- (((x + y - 1) / y) * y)
++ roundup(x, y)
+)
+
+@round2 depends on haskernel && patch && !context && !org && !report
+ disable paren@
+expression x, y;
+@@
+
+- roundup((x), y)
++ roundup(x, y)
+
+@round3 depends on haskernel && patch && !context && !org && !report
+ disable paren@
+expression x, y;
+@@
+
+- roundup(x, (y))
++ roundup(x, y)
+
+@round4 depends on haskernel && patch && !context && !org && !report@
+expression n,d;
+@@
+
+(
+- ((n + d - 1) / d)
++ DIV_ROUND_UP(n,d)
+|
+- ((n + (d - 1)) / d)
++ DIV_ROUND_UP(n,d)
+)
+
+@round5 depends on haskernel && patch && !context && !org && !report
+ disable paren@
+expression n,d;
+@@
+
+- DIV_ROUND_UP((n),d)
++ DIV_ROUND_UP(n,d)
+
+@round6 depends on haskernel && patch && !context && !org && !report
+ disable paren@
+expression n,d;
+@@
+
+- DIV_ROUND_UP(n,(d))
++ DIV_ROUND_UP(n,d)
+
+// ----------------------------------------------------------------------------
+
+@round1_context depends on haskernel && !patch && (context || org || report)@
+expression e, x, y;
+position j,j0;
+@@
+
+(
+*  (((x@j + (y - 1)) / y) *@e@j0 y)
+|
+*  (((x@j + y - 1) / y) *@e@j0 y)
+)
+
+@round2_context depends on haskernel && !patch && (context || org || report)
+ disable paren@
+expression x, y;
+position j0;
+@@
+
+*  roundup@j0((x), y)
+
+@round3_context depends on haskernel && !patch && (context || org || report)
+ disable paren@
+expression x, y;
+position j0;
+@@
+
+*  roundup@j0(x, (y))
+
+@round4_context depends on haskernel && !patch && (context || org || report)@
+expression e, d, n;
+position j!=round1_context.j;
+position j0;
+@@
+
+(
+*  ((n@j + d - 1) /@e@j0 d)
+|
+*  ((n@j + (d - 1)) /@e@j0 d)
+)
+
+@round5_context depends on haskernel && !patch && (context || org || report)
+ disable paren@
+expression d, n;
+position j0;
+@@
+
+*  DIV_ROUND_UP@j0((n),d)
+
+@round6_context depends on haskernel && !patch && (context || org || report)
+ disable paren@
+expression d, n;
+position j0;
+@@
+
+*  DIV_ROUND_UP@j0(n,(d))
+
+// ----------------------------------------------------------------------------
+
+@script:python round1_org depends on org@
+j0 << round1_context.j0;
+@@
+
+msg = "WARNING: Replace with roundup."
+coccilib.org.print_todo(j0[0], msg)
+
+@script:python round2_org depends on org@
+j0 << round2_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the first argument of roundup."
+coccilib.org.print_todo(j0[0], msg)
+
+@script:python round3_org depends on org@
+j0 << round3_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the second argument of roundup."
+coccilib.org.print_todo(j0[0], msg)
+
+@script:python round4_org depends on org@
+j0 << round4_context.j0;
+@@
+
+msg = "WARNING: Replace with DIV_ROUND_UP."
+coccilib.org.print_todo(j0[0], msg)
+
+@script:python round5_org depends on org@
+j0 << round5_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the first argument of DIV_ROUND_UP."
+coccilib.org.print_todo(j0[0], msg)
+
+@script:python round6_org depends on org@
+j0 << round6_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the second argument of DIV_ROUND_UP."
+coccilib.org.print_todo(j0[0], msg)
+
+// ----------------------------------------------------------------------------
+
+@script:python round1_report depends on report@
+j0 << round1_context.j0;
+@@
+
+msg = "WARNING: Replace with roundup."
+coccilib.report.print_report(j0[0], msg)
+
+@script:python round2_report depends on report@
+j0 << round2_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the first argument of roundup."
+coccilib.report.print_report(j0[0], msg)
+
+@script:python round3_report depends on report@
+j0 << round3_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the second argument of roundup."
+coccilib.report.print_report(j0[0], msg)
+
+@script:python round4_report depends on report@
+j0 << round4_context.j0;
+@@
+
+msg = "WARNING: Replace with DIV_ROUND_UP."
+coccilib.report.print_report(j0[0], msg)
+
+@script:python round5_report depends on report@
+j0 << round5_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the first argument of DIV_ROUND_UP."
+coccilib.report.print_report(j0[0], msg)
+
+@script:python round6_report depends on report@
+j0 << round6_context.j0;
+@@
+
+msg = "WARNING: Unneeded parentheses in the second argument of DIV_ROUND_UP."
+coccilib.report.print_report(j0[0], msg)
-- 
1.9.1

[toc] | [next] | [standalone]


#1443606

FromJulia Lawall <julia.lawall@lip6.fr>
Date2016-07-14 19:10 +0200
Message-ID<rUSj8-41y-19@gated-at.bofh.it>
In reply to#1443588

On Thu, 14 Jul 2016, Amitoj Kaur Chawla wrote:

> This script replaces manual calculations by using the predefined
> macros in kernel.h, DIV_ROUND_UP and roundup for readability purposes.
>
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>

Acked-by: Julia Lawall <julia.lawall@lip6.fr>


> ---
>  scripts/coccinelle/api/roundup.cocci | 215 +++++++++++++++++++++++++++++++++++
>  1 file changed, 215 insertions(+)
>  create mode 100644 scripts/coccinelle/api/roundup.cocci
>
> diff --git a/scripts/coccinelle/api/roundup.cocci b/scripts/coccinelle/api/roundup.cocci
> new file mode 100644
> index 0000000..af97cd2
> --- /dev/null
> +++ b/scripts/coccinelle/api/roundup.cocci
> @@ -0,0 +1,215 @@
> +/// Use DIV_ROUND_UP and roundup to improve readability
> +///
> +// Confidence: High
> +// Copyright: (C) 2016 Amitoj Kaur Chawla
> +
> +virtual patch
> +virtual context
> +virtual org
> +virtual report
> +
> +@haskernel@
> +@@
> +
> +#include <linux/kernel.h>
> +
> +@round1 depends on haskernel && patch && !context && !org && !report@
> +expression x, y;
> +@@
> +
> +(
> +- (((x + (y - 1)) / y) * y)
> ++ roundup(x, y)
> +|
> +- (((x + y - 1) / y) * y)
> ++ roundup(x, y)
> +)
> +
> +@round2 depends on haskernel && patch && !context && !org && !report
> + disable paren@
> +expression x, y;
> +@@
> +
> +- roundup((x), y)
> ++ roundup(x, y)
> +
> +@round3 depends on haskernel && patch && !context && !org && !report
> + disable paren@
> +expression x, y;
> +@@
> +
> +- roundup(x, (y))
> ++ roundup(x, y)
> +
> +@round4 depends on haskernel && patch && !context && !org && !report@
> +expression n,d;
> +@@
> +
> +(
> +- ((n + d - 1) / d)
> ++ DIV_ROUND_UP(n,d)
> +|
> +- ((n + (d - 1)) / d)
> ++ DIV_ROUND_UP(n,d)
> +)
> +
> +@round5 depends on haskernel && patch && !context && !org && !report
> + disable paren@
> +expression n,d;
> +@@
> +
> +- DIV_ROUND_UP((n),d)
> ++ DIV_ROUND_UP(n,d)
> +
> +@round6 depends on haskernel && patch && !context && !org && !report
> + disable paren@
> +expression n,d;
> +@@
> +
> +- DIV_ROUND_UP(n,(d))
> ++ DIV_ROUND_UP(n,d)
> +
> +// ----------------------------------------------------------------------------
> +
> +@round1_context depends on haskernel && !patch && (context || org || report)@
> +expression e, x, y;
> +position j,j0;
> +@@
> +
> +(
> +*  (((x@j + (y - 1)) / y) *@e@j0 y)
> +|
> +*  (((x@j + y - 1) / y) *@e@j0 y)
> +)
> +
> +@round2_context depends on haskernel && !patch && (context || org || report)
> + disable paren@
> +expression x, y;
> +position j0;
> +@@
> +
> +*  roundup@j0((x), y)
> +
> +@round3_context depends on haskernel && !patch && (context || org || report)
> + disable paren@
> +expression x, y;
> +position j0;
> +@@
> +
> +*  roundup@j0(x, (y))
> +
> +@round4_context depends on haskernel && !patch && (context || org || report)@
> +expression e, d, n;
> +position j!=round1_context.j;
> +position j0;
> +@@
> +
> +(
> +*  ((n@j + d - 1) /@e@j0 d)
> +|
> +*  ((n@j + (d - 1)) /@e@j0 d)
> +)
> +
> +@round5_context depends on haskernel && !patch && (context || org || report)
> + disable paren@
> +expression d, n;
> +position j0;
> +@@
> +
> +*  DIV_ROUND_UP@j0((n),d)
> +
> +@round6_context depends on haskernel && !patch && (context || org || report)
> + disable paren@
> +expression d, n;
> +position j0;
> +@@
> +
> +*  DIV_ROUND_UP@j0(n,(d))
> +
> +// ----------------------------------------------------------------------------
> +
> +@script:python round1_org depends on org@
> +j0 << round1_context.j0;
> +@@
> +
> +msg = "WARNING: Replace with roundup."
> +coccilib.org.print_todo(j0[0], msg)
> +
> +@script:python round2_org depends on org@
> +j0 << round2_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the first argument of roundup."
> +coccilib.org.print_todo(j0[0], msg)
> +
> +@script:python round3_org depends on org@
> +j0 << round3_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the second argument of roundup."
> +coccilib.org.print_todo(j0[0], msg)
> +
> +@script:python round4_org depends on org@
> +j0 << round4_context.j0;
> +@@
> +
> +msg = "WARNING: Replace with DIV_ROUND_UP."
> +coccilib.org.print_todo(j0[0], msg)
> +
> +@script:python round5_org depends on org@
> +j0 << round5_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the first argument of DIV_ROUND_UP."
> +coccilib.org.print_todo(j0[0], msg)
> +
> +@script:python round6_org depends on org@
> +j0 << round6_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the second argument of DIV_ROUND_UP."
> +coccilib.org.print_todo(j0[0], msg)
> +
> +// ----------------------------------------------------------------------------
> +
> +@script:python round1_report depends on report@
> +j0 << round1_context.j0;
> +@@
> +
> +msg = "WARNING: Replace with roundup."
> +coccilib.report.print_report(j0[0], msg)
> +
> +@script:python round2_report depends on report@
> +j0 << round2_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the first argument of roundup."
> +coccilib.report.print_report(j0[0], msg)
> +
> +@script:python round3_report depends on report@
> +j0 << round3_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the second argument of roundup."
> +coccilib.report.print_report(j0[0], msg)
> +
> +@script:python round4_report depends on report@
> +j0 << round4_context.j0;
> +@@
> +
> +msg = "WARNING: Replace with DIV_ROUND_UP."
> +coccilib.report.print_report(j0[0], msg)
> +
> +@script:python round5_report depends on report@
> +j0 << round5_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the first argument of DIV_ROUND_UP."
> +coccilib.report.print_report(j0[0], msg)
> +
> +@script:python round6_report depends on report@
> +j0 << round6_context.j0;
> +@@
> +
> +msg = "WARNING: Unneeded parentheses in the second argument of DIV_ROUND_UP."
> +coccilib.report.print_report(j0[0], msg)
> --
> 1.9.1
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web