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>
Replace a misspelled function name by %s and then __func__.
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.
The message is sort of ambiguous, but I assume that it is intended to refer to the function in which the problem is detected.
drivers/gpu/drm/i915/i915_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index d2ba315..fa21d1c 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4335,7 +4335,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data, }
if (obj->pin_filp != file) { - DRM_DEBUG("Not pinned by caller in i915_gem_pin_ioctl(): %d\n", + DRM_DEBUG("Not pinned by caller in %s(): %d\n", __func__, args->handle); ret = -EINVAL; goto out;
On Sun, 07 Dec 2014, Julia Lawall Julia.Lawall@lip6.fr wrote:
Replace a misspelled function name by %s and then __func__.
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.
The message is sort of ambiguous, but I assume that it is intended to refer to the function in which the problem is detected.
Hmm, DRM_DEBUG prints __func__ too.
Jani.
drivers/gpu/drm/i915/i915_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index d2ba315..fa21d1c 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4335,7 +4335,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data, }
if (obj->pin_filp != file) {
DRM_DEBUG("Not pinned by caller in i915_gem_pin_ioctl(): %d\n",
ret = -EINVAL; goto out;DRM_DEBUG("Not pinned by caller in %s(): %d\n", __func__, args->handle);
On Mon, Dec 08, 2014 at 12:24:27PM +0200, Jani Nikula wrote:
On Sun, 07 Dec 2014, Julia Lawall Julia.Lawall@lip6.fr wrote:
Replace a misspelled function name by %s and then __func__.
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.
The message is sort of ambiguous, but I assume that it is intended to refer to the function in which the problem is detected.
Hmm, DRM_DEBUG prints __func__ too.
We've killed the pin ioctl for 3.20 hence didn't even bother to come up with an opinion ;-) -Daniel
Replace a misspelled function name by %s and then __func__.
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/gpu/drm/i2c/tda998x_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c index d476279..14acac8 100644 --- a/drivers/gpu/drm/i2c/tda998x_drv.c +++ b/drivers/gpu/drm/i2c/tda998x_drv.c @@ -385,7 +385,7 @@ set_page(struct tda998x_priv *priv, uint16_t reg) }; int ret = i2c_master_send(client, buf, sizeof(buf)); if (ret < 0) { - dev_err(&client->dev, "setpage %04x err %d\n", + dev_err(&client->dev, "%s %04x err %d\n", __func__, reg, ret); return ret; }
Replace a misspelled function name by %s and then __func__.
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/gpu/drm/radeon/cik.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c index 6dcde37..24d5e43 100644 --- a/drivers/gpu/drm/radeon/cik.c +++ b/drivers/gpu/drm/radeon/cik.c @@ -7367,34 +7367,38 @@ int cik_irq_set(struct radeon_device *rdev) } if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) { struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]; - DRM_DEBUG("si_irq_set: sw int cp1\n"); + DRM_DEBUG("%s: sw int cp1\n", __func__); if (ring->me == 1) { switch (ring->pipe) { case 0: cp_m1p0 |= TIME_STAMP_INT_ENABLE; break; default: - DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe); + DRM_DEBUG("%s: sw int cp1 invalid pipe %d\n", + __func__, ring->pipe); break; } } else { - DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me); + DRM_DEBUG("%s: sw int cp1 invalid me %d\n", __func__, + ring->me); } } if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) { struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]; - DRM_DEBUG("si_irq_set: sw int cp2\n"); + DRM_DEBUG("%s: sw int cp2\n", __func__); if (ring->me == 1) { switch (ring->pipe) { case 0: cp_m1p0 |= TIME_STAMP_INT_ENABLE; break; default: - DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe); + DRM_DEBUG("%s: sw int cp2 invalid pipe %d\n", + __func__, ring->pipe); break; } } else { - DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me); + DRM_DEBUG("%s: sw int cp2 invalid me %d\n", __func__, + ring->me); } }
On Sun, Dec 7, 2014 at 2:21 PM, Julia Lawall Julia.Lawall@lip6.fr wrote:
Replace a misspelled function name by %s and then __func__.
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
Looks fine to me. For consistency, any chance you'd want to fix up the other places that use function names directly with this style patch?
Alex
The semantic patch is difficult to summarize, but is available in the cover letter of this patch series.
drivers/gpu/drm/radeon/cik.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c index 6dcde37..24d5e43 100644 --- a/drivers/gpu/drm/radeon/cik.c +++ b/drivers/gpu/drm/radeon/cik.c @@ -7367,34 +7367,38 @@ int cik_irq_set(struct radeon_device *rdev) } if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) { struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
DRM_DEBUG("si_irq_set: sw int cp1\n");
DRM_DEBUG("%s: sw int cp1\n", __func__); if (ring->me == 1) { switch (ring->pipe) { case 0: cp_m1p0 |= TIME_STAMP_INT_ENABLE; break; default:
DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
DRM_DEBUG("%s: sw int cp1 invalid pipe %d\n",
__func__, ring->pipe); break; } } else {
DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
DRM_DEBUG("%s: sw int cp1 invalid me %d\n", __func__,
ring->me); } } if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) { struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
DRM_DEBUG("si_irq_set: sw int cp2\n");
DRM_DEBUG("%s: sw int cp2\n", __func__); if (ring->me == 1) { switch (ring->pipe) { case 0: cp_m1p0 |= TIME_STAMP_INT_ENABLE; break; default:
DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
DRM_DEBUG("%s: sw int cp2 invalid pipe %d\n",
__func__, ring->pipe); break; } } else {
DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
DRM_DEBUG("%s: sw int cp2 invalid me %d\n", __func__,
ring->me); } }
dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel
On Mon, 8 Dec 2014, Alex Deucher wrote:
On Sun, Dec 7, 2014 at 2:21 PM, Julia Lawall Julia.Lawall@lip6.fr wrote:
Replace a misspelled function name by %s and then __func__.
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
Looks fine to me. For consistency, any chance you'd want to fix up the other places that use function names directly with this style patch?
I will try to do that soon.
julia
Alex
The semantic patch is difficult to summarize, but is available in the cover letter of this patch series.
drivers/gpu/drm/radeon/cik.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c index 6dcde37..24d5e43 100644 --- a/drivers/gpu/drm/radeon/cik.c +++ b/drivers/gpu/drm/radeon/cik.c @@ -7367,34 +7367,38 @@ int cik_irq_set(struct radeon_device *rdev) } if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) { struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
DRM_DEBUG("si_irq_set: sw int cp1\n");
DRM_DEBUG("%s: sw int cp1\n", __func__); if (ring->me == 1) { switch (ring->pipe) { case 0: cp_m1p0 |= TIME_STAMP_INT_ENABLE; break; default:
DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
DRM_DEBUG("%s: sw int cp1 invalid pipe %d\n",
__func__, ring->pipe); break; } } else {
DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
DRM_DEBUG("%s: sw int cp1 invalid me %d\n", __func__,
ring->me); } } if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) { struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
DRM_DEBUG("si_irq_set: sw int cp2\n");
DRM_DEBUG("%s: sw int cp2\n", __func__); if (ring->me == 1) { switch (ring->pipe) { case 0: cp_m1p0 |= TIME_STAMP_INT_ENABLE; break; default:
DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
DRM_DEBUG("%s: sw int cp2 invalid pipe %d\n",
__func__, ring->pipe); break; } } else {
DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
DRM_DEBUG("%s: sw int cp2 invalid me %d\n", __func__,
ring->me); } }
dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel
-- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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,
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
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,
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.
dri-devel@lists.freedesktop.org