[OPW,kernel] Coccinelle Script to automate replacement of strict_strtoul()
diff mbox

Message ID 20131015174758.GA30924@gmail.com
State Changes Requested
Headers show

Commit Message

Rashika Oct. 15, 2013, 5:47 p.m. UTC
The usage of strict_strtoul() is not preferred, because 
strict_strtoul() is obsolete. Thus, kstrtoul() should be used.
This Script helps in automating the process of replacement of
strict_strtoul() with kstrtoul().

Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com>
---
 scripts/coccinelle/api/kstrtoul.cocci |   53 +++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 scripts/coccinelle/api/kstrtoul.cocci

Comments

Josh Triplett Oct. 15, 2013, 5:56 p.m. UTC | #1
On Tue, Oct 15, 2013 at 11:17:58PM +0530, Rashika Kheria wrote:
> The usage of strict_strtoul() is not preferred, because 
> strict_strtoul() is obsolete. Thus, kstrtoul() should be used.
> This Script helps in automating the process of replacement of
> strict_strtoul() with kstrtoul().
> 
> Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com>

Given that in all cases you're just replacing the function name, and you
never need to change the semantics, does it not work to only include the
first expression without the semicolon?

If that works, please simplify to just that; if not, this is fine.

Either way:
Reviewed-by: Josh Triplett <josh@joshtriplett.org>

> ---
>  scripts/coccinelle/api/kstrtoul.cocci |   53 +++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>  create mode 100644 scripts/coccinelle/api/kstrtoul.cocci
> 
> diff --git a/scripts/coccinelle/api/kstrtoul.cocci b/scripts/coccinelle/api/kstrtoul.cocci
> new file mode 100644
> index 0000000..6ca7250
> --- /dev/null
> +++ b/scripts/coccinelle/api/kstrtoul.cocci
> @@ -0,0 +1,53 @@
> +@ kstrtoul @
> +expression E1,E2,E3,E4;
> +statement S;
> +position p;
> +@@
> +
> +(
> +- strict_strtoul@p(E1,E2,E3);
> ++ kstrtoul(E1,E2,E3);
> +|
> +- E4 = strict_strtoul@p(E1,E2,E3);
> ++ E4 = kstrtoul(E1,E2,E3);
> +|
> +if (... || 
> +- (strict_strtoul@p(E1,E2,E3))
> ++ (kstrtoul(E1,E2,E3))
> + || ...) S
> +|
> +if (
> +- (strict_strtoul@p(E1,E2,E3))
> ++ (kstrtoul(E1,E2,E3))
> +|| ...) S
> +|
> +- return strict_strtoul@p(E1,E2,E3);
> ++ return kstrtoul(E1,E2,E3);
> +|
> +if (... || 
> +- (strict_strtoul@p(E1,E2,E3) < 0)
> ++ (kstrtoul(E1,E2,E3) < 0)
> + || ...) S
> +|
> +if (
> +- (strict_strtoul@p(E1,E2,E3) < 0)
> ++ (kstrtoul(E1,E2,E3) < 0)
> +|| ...) S
> +|
> +if (... && 
> +- (strict_strtoul@p(E1,E2,E3) < 0)
> ++ (kstrtoul(E1,E2,E3) < 0)
> + && ...) S
> +|
> +if (
> +- (strict_strtoul@p(E1,E2,E3) < 0)
> ++ (kstrtoul(E1,E2,E3) < 0)
> + && ...) S
> +)
> +
> +@ script:python depends on report @
> +p << kstrtoul.p;
> +@@
> +for pos in p:
> +	msg = "%s %s: WARNING: Replacing strict_strtoul with kstrtoul" % (pos.file, pos.line)
> +	print(msg)
> -- 
> 1.7.9.5
> 
> -- 
> You received this message because you are subscribed to the Google Groups "opw-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to opw-kernel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Rashika Oct. 15, 2013, 6:03 p.m. UTC | #2
On Tue, Oct 15, 2013 at 11:26 PM, Josh Triplett <josh@joshtriplett.org>wrote:

> On Tue, Oct 15, 2013 at 11:17:58PM +0530, Rashika Kheria wrote:
>
> Given that in all cases you're just replacing the function name, and you
> never need to change the semantics, does it not work to only include the
> first expression without the semicolon?
>
> If that works, please simplify to just that; if not, this is fine.
>
> Either way:
> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
>
>
Thanks for reviewing it. Yes, it worked initially but some-how it threw
error with the python script for report i.e. why I included all the cases
(witnessed from the past patches).

Kindly suggest more enhancements in this script which I can work on.

Thanks,

Patch
diff mbox

diff --git a/scripts/coccinelle/api/kstrtoul.cocci b/scripts/coccinelle/api/kstrtoul.cocci
new file mode 100644
index 0000000..6ca7250
--- /dev/null
+++ b/scripts/coccinelle/api/kstrtoul.cocci
@@ -0,0 +1,53 @@ 
+@ kstrtoul @
+expression E1,E2,E3,E4;
+statement S;
+position p;
+@@
+
+(
+- strict_strtoul@p(E1,E2,E3);
++ kstrtoul(E1,E2,E3);
+|
+- E4 = strict_strtoul@p(E1,E2,E3);
++ E4 = kstrtoul(E1,E2,E3);
+|
+if (... || 
+- (strict_strtoul@p(E1,E2,E3))
++ (kstrtoul(E1,E2,E3))
+ || ...) S
+|
+if (
+- (strict_strtoul@p(E1,E2,E3))
++ (kstrtoul(E1,E2,E3))
+|| ...) S
+|
+- return strict_strtoul@p(E1,E2,E3);
++ return kstrtoul(E1,E2,E3);
+|
+if (... || 
+- (strict_strtoul@p(E1,E2,E3) < 0)
++ (kstrtoul(E1,E2,E3) < 0)
+ || ...) S
+|
+if (
+- (strict_strtoul@p(E1,E2,E3) < 0)
++ (kstrtoul(E1,E2,E3) < 0)
+|| ...) S
+|
+if (... && 
+- (strict_strtoul@p(E1,E2,E3) < 0)
++ (kstrtoul(E1,E2,E3) < 0)
+ && ...) S
+|
+if (
+- (strict_strtoul@p(E1,E2,E3) < 0)
++ (kstrtoul(E1,E2,E3) < 0)
+ && ...) S
+)
+
+@ script:python depends on report @
+p << kstrtoul.p;
+@@
+for pos in p:
+	msg = "%s %s: WARNING: Replacing strict_strtoul with kstrtoul" % (pos.file, pos.line)
+	print(msg)