* [PATCH 0/20] fix misspelling of current function in string
@ 2014-12-07 19:20 Julia Lawall
2014-12-07 19:20 ` [PATCH 1/20] mtd: s3c2410: " Julia Lawall
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
To: linux-wireless
Cc: devel, linux-samsung-soc, linux-scsi, kernel-janitors, intel-gfx,
linux-usb, linux, linux-kernel, dri-devel, netdev, linux-mtd,
linux-pci, joe, linux-arm-kernel
These patches replace what appears to be a reference to the name of the
current function but is misspelled in some way by either the name of the
function itself, or by %s and then __func__ in an argument list.
// <smpl>
// sudo apt-get install python-pip
// sudo pip install python-Levenshtein
// spatch requires the argument --in-place
virtual after_start
@initialize:ocaml@
@@
let extensible_functions = ref ([] : string list)
let restarted = ref false
let restart _ =
restarted := true;
let it = new iteration() in
it#add_virtual_rule After_start;
Printf.eprintf "restarting\n";
it#register()
@initialize:python@
@@
import re
from Levenshtein import distance
mindist = 1 // 1 to find only misspellings
maxdist = 2
ignore_leading = True
// ---------------------------------------------------------------------
@r0@
constant char [] c;
identifier f;
@@
f(...,c,...)
@script:ocaml@
c << r0.c;
f << r0.f;
@@
(if not !restarted then restart());
match Str.split_delim (Str.regexp "%") c with
_::_::_ ->
if not (List.mem f !extensible_functions)
then extensible_functions := f :: !extensible_functions
| _ -> ()
// ---------------------------------------------------------------------
@r depends on after_start@
constant char [] c;
position p;
identifier f;
@@
f(...,c@p,...)
@script:python flt@
c << r.c;
p << r.p;
matched;
@@
func = p[0].current_element
wpattern = "[a-zA-Z_][a-zA-Z0-9_]*"
if ignore_leading:
func = func.strip("_")
wpattern = "[a-zA-Z][a-zA-Z0-9_]*"
lf = len(func)
cocci.include_match(False)
// ignore extremely short function names
if lf > 3:
words = [w for w in re.findall(wpattern, c) if abs(len(w) - lf) <= maxdist]
for w in words:
d = distance(w, func)
if mindist <= d and d <= maxdist:
coccinelle.matched = w
cocci.include_match(True)
//print "%s:%d:%s():%d: %s" % (p[0].file, int(p[0].line), func, d, c)
break
@script:ocaml r2@
c << r.c;
f << r.f;
matched << flt.matched;
fixed;
@@
let pieces = Str.split_delim (Str.regexp_string matched) c in
match pieces with
[before;after] ->
let preceeding =
List.length(Str.split (Str.regexp_string "%") before) > 1 in
if preceeding
then Coccilib.include_match false
else
if List.mem f !extensible_functions
then fixed := before ^ "%s" ^ after
else Coccilib.include_match false
| _ -> Coccilib.include_match false
@changed1@
constant char [] r.c;
identifier r2.fixed;
position r.p;
identifier r.f;
@@
f(...,
-c@p
+fixed,__func__
,...)
// -------------------------------------------------------------------
@s depends on after_start@
constant char [] c;
position p;
identifier f;
@@
f(...,c@p,...)
@script:python flt2@
c << s.c;
p << s.p;
matched;
@@
func = p[0].current_element
wpattern = "[a-zA-Z_][a-zA-Z0-9_]*"
if ignore_leading:
func = func.strip("_")
wpattern = "[a-zA-Z][a-zA-Z0-9_]*"
lf = len(func)
cocci.include_match(False)
// ignore extremely short function names
if lf > 3:
words = [w for w in re.findall(wpattern, c) if abs(len(w) - lf) <= maxdist]
for w in words:
d = distance(w, func)
if mindist <= d and d <= maxdist:
coccinelle.matched = w
cocci.include_match(True)
//print "%s:%d:%s():%d: %s" % (p[0].file, int(p[0].line), func, d, c)
break
@script:ocaml s2@
c << s.c;
f << s.f;
p << s.p;
matched << flt2.matched;
fixed;
@@
let ce = (List.hd p).current_element in
let pieces = Str.split_delim (Str.regexp_string matched) c in
match pieces with
[before;after] ->
let preceeding =
List.length(Str.split (Str.regexp_string "%") before) > 1 in
if preceeding
then Coccilib.include_match false
else
if List.mem f !extensible_functions
then Coccilib.include_match false
else fixed := before ^ ce ^ after
| _ -> Coccilib.include_match false
@changed2@
constant char [] s.c;
identifier s2.fixed;
position s.p;
identifier s.f;
@@
f(...,
-c@p
+fixed
,...)
// </smpl>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/20] mtd: s3c2410: fix misspelling of current function in string
2014-12-07 19:20 [PATCH 0/20] fix misspelling of current function in string Julia Lawall
@ 2014-12-07 19:20 ` Julia Lawall
2014-12-07 22:48 ` Richard Weinberger
2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
2014-12-08 3:55 ` Joe Perches
2 siblings, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
To: Kukjin Kim
Cc: linux-samsung-soc, kernel-janitors, linux, linux-kernel,
linux-mtd, joe, Brian Norris, David Woodhouse, linux-arm-kernel
Replace a misspelled function name by %s and then __func__.
s3c2410 is the name of the file, but using the exact function name should
make it easier to connect the error message to the code.
This was done using Coccinelle, including the use of Levenshtein distance,
as proposed by Rasmus Villemoes.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
---
The semantic patch is difficult to summarize, but is available in the cover
letter of this patch series.
drivers/mtd/nand/s3c2410.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 35aef5e..0a9c41f 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -948,7 +948,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
cpu_type = platform_get_device_id(pdev)->driver_data;
- pr_debug("s3c2410_nand_probe(%p)\n", pdev);
+ pr_debug("%s(%p)\n", __func__, pdev);
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
if (info == NULL) {
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/20] mtd: s3c2410: fix misspelling of current function in string
2014-12-07 19:20 ` [PATCH 1/20] mtd: s3c2410: " Julia Lawall
@ 2014-12-07 22:48 ` Richard Weinberger
2014-12-08 7:11 ` Julia Lawall
0 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2014-12-07 22:48 UTC (permalink / raw)
To: Julia Lawall
Cc: linux-samsung-soc, kernel-janitors@vger.kernel.org, linux, LKML,
Kukjin Kim, linux-mtd@lists.infradead.org, Joe Perches,
Brian Norris, David Woodhouse,
linux-arm-kernel@lists.infradead.org
On Sun, Dec 7, 2014 at 8:20 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> Replace a misspelled function name by %s and then __func__.
>
> s3c2410 is the name of the file, but using the exact function name should
> make it easier to connect the error message to the code.
>
> This was done using Coccinelle, including the use of Levenshtein distance,
> as proposed by Rasmus Villemoes.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
>
> ---
> The semantic patch is difficult to summarize, but is available in the cover
> letter of this patch series.
>
> drivers/mtd/nand/s3c2410.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
> index 35aef5e..0a9c41f 100644
> --- a/drivers/mtd/nand/s3c2410.c
> +++ b/drivers/mtd/nand/s3c2410.c
> @@ -948,7 +948,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
>
> cpu_type = platform_get_device_id(pdev)->driver_data;
>
> - pr_debug("s3c2410_nand_probe(%p)\n", pdev);
> + pr_debug("%s(%p)\n", __func__, pdev);
I think we can drop the line completely.
We have ftrace to trace function calls...
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/20] fix misspelling of current function in string
2014-12-07 19:20 [PATCH 0/20] fix misspelling of current function in string Julia Lawall
2014-12-07 19:20 ` [PATCH 1/20] mtd: s3c2410: " Julia Lawall
@ 2014-12-07 23:44 ` Julian Calaby
2014-12-08 6:43 ` Julia Lawall
2014-12-08 3:55 ` Joe Perches
2 siblings, 1 reply; 10+ messages in thread
From: Julian Calaby @ 2014-12-07 23:44 UTC (permalink / raw)
To: Julia Lawall
Cc: devel@driverdev.osuosl.org, linux-samsung-soc, linux-scsi,
linux-pci, linux-wireless, intel-gfx, linux-usb, kernel-janitors,
linux-kernel@vger.kernel.org, dri-devel, netdev, linux-mtd, linux,
Joe Perches, Mailing List, Arm
Hi Julia,
On Mon, Dec 8, 2014 at 6:20 AM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> These patches replace what appears to be a reference to the name of the
> current function but is misspelled in some way by either the name of the
> function itself, or by %s and then __func__ in an argument list.
Would there be any value in doing this for _all_ cases where the
function name is written in a format string?
Thanks,
--
Julian Calaby
Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/20] fix misspelling of current function in string
2014-12-07 19:20 [PATCH 0/20] fix misspelling of current function in string Julia Lawall
2014-12-07 19:20 ` [PATCH 1/20] mtd: s3c2410: " Julia Lawall
2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
@ 2014-12-08 3:55 ` Joe Perches
2 siblings, 0 replies; 10+ messages in thread
From: Joe Perches @ 2014-12-08 3:55 UTC (permalink / raw)
To: Julia Lawall
Cc: devel, linux-samsung-soc, linux-scsi, linux-pci, linux-wireless,
intel-gfx, linux-usb, kernel-janitors, linux-kernel, dri-devel,
netdev, linux-mtd, linux, linux-arm-kernel
On Sun, 2014-12-07 at 20:20 +0100, Julia Lawall wrote:
> These patches replace what appears to be a reference to the name of the
> current function but is misspelled in some way by either the name of the
> function itself, or by %s and then __func__ in an argument list.
At least a few of these seem to be function tracing
style uses that might as well be deleted instead.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/20] fix misspelling of current function in string
2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
@ 2014-12-08 6:43 ` Julia Lawall
2014-12-10 2:56 ` Julian Calaby
0 siblings, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2014-12-08 6:43 UTC (permalink / raw)
To: Julian Calaby
Cc: devel@driverdev.osuosl.org, linux-samsung-soc, linux-scsi, linux,
linux-wireless, intel-gfx, linux-usb, kernel-janitors,
linux-kernel@vger.kernel.org, dri-devel, Julia Lawall, netdev,
linux-mtd, linux-pci, Joe Perches, Mailing List, Arm
On Mon, 8 Dec 2014, Julian Calaby wrote:
> Hi Julia,
>
> On Mon, Dec 8, 2014 at 6:20 AM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> > These patches replace what appears to be a reference to the name of the
> > current function but is misspelled in some way by either the name of the
> > function itself, or by %s and then __func__ in an argument list.
>
> Would there be any value in doing this for _all_ cases where the
> function name is written in a format string?
Probably. But there are a lot of them. Even for the misspellings, I have
only don about 1/3 of the cases.
On the other hand, the misspelling have to be checked carefully, because a
misspelling of one thing could be the correct spelling of the thing thst
was actually intended.
Joe, however, points out that a lot of these prints are just for function
tracing, and could be removed. I worked on another semantic patch that
tries to do that. It might be better to remove those prints completely,
rather than sending one patch to transform them and then one patch to
remove them after that. That is why for this series I did only the ones
where there was actually a problem.
julia
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/20] mtd: s3c2410: fix misspelling of current function in string
2014-12-07 22:48 ` Richard Weinberger
@ 2014-12-08 7:11 ` Julia Lawall
2014-12-08 9:16 ` Richard Weinberger
0 siblings, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2014-12-08 7:11 UTC (permalink / raw)
To: Richard Weinberger
Cc: linux-samsung-soc, linux, kernel-janitors@vger.kernel.org, LKML,
Julia Lawall, Kukjin Kim, linux-mtd@lists.infradead.org,
Joe Perches, Brian Norris, David Woodhouse,
linux-arm-kernel@lists.infradead.org
> > diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
> > index 35aef5e..0a9c41f 100644
> > --- a/drivers/mtd/nand/s3c2410.c
> > +++ b/drivers/mtd/nand/s3c2410.c
> > @@ -948,7 +948,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
> >
> > cpu_type = platform_get_device_id(pdev)->driver_data;
> >
> > - pr_debug("s3c2410_nand_probe(%p)\n", pdev);
> > + pr_debug("%s(%p)\n", __func__, pdev);
>
> I think we can drop the line completely.
> We have ftrace to trace function calls...
Should the "initialised ok" at the end of the function be remove as well?
Will it be confusing if this cleanup is done in this function, but not in
others where it may be useful? Perhaps s3c2410_nand_update_chip, for
example?
julia
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/20] mtd: s3c2410: fix misspelling of current function in string
2014-12-08 7:11 ` Julia Lawall
@ 2014-12-08 9:16 ` Richard Weinberger
2015-02-06 11:28 ` Brian Norris
0 siblings, 1 reply; 10+ messages in thread
From: Richard Weinberger @ 2014-12-08 9:16 UTC (permalink / raw)
To: Julia Lawall
Cc: linux-samsung-soc, kernel-janitors@vger.kernel.org, linux, LKML,
Kukjin Kim, linux-mtd@lists.infradead.org, Joe Perches,
Brian Norris, David Woodhouse,
linux-arm-kernel@lists.infradead.org
Am 08.12.2014 um 08:11 schrieb Julia Lawall:
>>> diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
>>> index 35aef5e..0a9c41f 100644
>>> --- a/drivers/mtd/nand/s3c2410.c
>>> +++ b/drivers/mtd/nand/s3c2410.c
>>> @@ -948,7 +948,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
>>>
>>> cpu_type = platform_get_device_id(pdev)->driver_data;
>>>
>>> - pr_debug("s3c2410_nand_probe(%p)\n", pdev);
>>> + pr_debug("%s(%p)\n", __func__, pdev);
>>
>> I think we can drop the line completely.
>> We have ftrace to trace function calls...
>
> Should the "initialised ok" at the end of the function be remove as well?
>
> Will it be confusing if this cleanup is done in this function, but not in
> others where it may be useful? Perhaps s3c2410_nand_update_chip, for
> example?
Hmm, this driver seems to have a lot of debugging printks().
IMHO we can remove them.
Let's see what Brain says.
Thanks,
//richard
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/20] fix misspelling of current function in string
2014-12-08 6:43 ` Julia Lawall
@ 2014-12-10 2:56 ` Julian Calaby
0 siblings, 0 replies; 10+ messages in thread
From: Julian Calaby @ 2014-12-10 2:56 UTC (permalink / raw)
To: Julia Lawall
Cc: devel@driverdev.osuosl.org, linux-samsung-soc, linux-scsi,
linux-pci, linux-wireless, intel-gfx, linux-usb, kernel-janitors,
linux-kernel@vger.kernel.org, dri-devel, netdev, linux-mtd, linux,
Joe Perches, Mailing List, Arm
Hi Julia,
On Mon, Dec 8, 2014 at 5:43 PM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> On Mon, 8 Dec 2014, Julian Calaby wrote:
>
>> Hi Julia,
>>
>> On Mon, Dec 8, 2014 at 6:20 AM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>> > These patches replace what appears to be a reference to the name of the
>> > current function but is misspelled in some way by either the name of the
>> > function itself, or by %s and then __func__ in an argument list.
>>
>> Would there be any value in doing this for _all_ cases where the
>> function name is written in a format string?
>
> Probably. But there are a lot of them. Even for the misspellings, I have
> only don about 1/3 of the cases.
>
> On the other hand, the misspelling have to be checked carefully, because a
> misspelling of one thing could be the correct spelling of the thing thst
> was actually intended.
>
> Joe, however, points out that a lot of these prints are just for function
> tracing, and could be removed. I worked on another semantic patch that
> tries to do that. It might be better to remove those prints completely,
> rather than sending one patch to transform them and then one patch to
> remove them after that. That is why for this series I did only the ones
> where there was actually a problem.
Ok, that makes sense.
Either way though, this is a really interesting application of the
semantic patching. Nice work!
Thanks,
--
Julian Calaby
Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/20] mtd: s3c2410: fix misspelling of current function in string
2014-12-08 9:16 ` Richard Weinberger
@ 2015-02-06 11:28 ` Brian Norris
0 siblings, 0 replies; 10+ messages in thread
From: Brian Norris @ 2015-02-06 11:28 UTC (permalink / raw)
To: Richard Weinberger
Cc: linux-samsung-soc, linux, kernel-janitors@vger.kernel.org, LKML,
Julia Lawall, Kukjin Kim, linux-mtd@lists.infradead.org,
Joe Perches, David Woodhouse,
linux-arm-kernel@lists.infradead.org
On Mon, Dec 08, 2014 at 10:16:37AM +0100, Richard Weinberger wrote:
> Am 08.12.2014 um 08:11 schrieb Julia Lawall:
> >>> diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
> >>> index 35aef5e..0a9c41f 100644
> >>> --- a/drivers/mtd/nand/s3c2410.c
> >>> +++ b/drivers/mtd/nand/s3c2410.c
> >>> @@ -948,7 +948,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
> >>>
> >>> cpu_type = platform_get_device_id(pdev)->driver_data;
> >>>
> >>> - pr_debug("s3c2410_nand_probe(%p)\n", pdev);
> >>> + pr_debug("%s(%p)\n", __func__, pdev);
> >>
> >> I think we can drop the line completely.
> >> We have ftrace to trace function calls...
> >
> > Should the "initialised ok" at the end of the function be remove as well?
> >
> > Will it be confusing if this cleanup is done in this function, but not in
> > others where it may be useful? Perhaps s3c2410_nand_update_chip, for
> > example?
>
> Hmm, this driver seems to have a lot of debugging printks().
> IMHO we can remove them.
> Let's see what Brain says.
I'm a little late for this one, but I can apply this instead:
From: Brian Norris <computersforpeace@gmail.com>
Date: Fri, 6 Feb 2015 03:25:28 -0800
Subject: [PATCH] mtd: s3c2410: drop useless / misspelled debug prints
s3c2410_nand_probe is not the name of the function.
These prints have little utility, so let's just kill them.
Reported-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
drivers/mtd/nand/s3c2410.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 35aef5edb588..0e02be47ce1d 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -948,8 +948,6 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
cpu_type = platform_get_device_id(pdev)->driver_data;
- pr_debug("s3c2410_nand_probe(%p)\n", pdev);
-
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
if (info == NULL) {
err = -ENOMEM;
@@ -1045,7 +1043,6 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
}
- pr_debug("initialised ok\n");
return 0;
exit_error:
--
2.3.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-02-06 11:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-07 19:20 [PATCH 0/20] fix misspelling of current function in string Julia Lawall
2014-12-07 19:20 ` [PATCH 1/20] mtd: s3c2410: " Julia Lawall
2014-12-07 22:48 ` Richard Weinberger
2014-12-08 7:11 ` Julia Lawall
2014-12-08 9:16 ` Richard Weinberger
2015-02-06 11:28 ` Brian Norris
2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
2014-12-08 6:43 ` Julia Lawall
2014-12-10 2:56 ` Julian Calaby
2014-12-08 3:55 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).