linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/20] fix misspelling of current function in string
@ 2014-12-07 19:20 Julia Lawall
  2014-12-07 19:20 ` [PATCH 13/20] zd1211rw: " Julia Lawall
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
  To: linux-wireless
  Cc: kernel-janitors, linux, joe, devel, linux-scsi, dri-devel,
	intel-gfx, linux-mtd, linux-samsung-soc, linux-arm-kernel,
	linux-kernel, linux-pci, netdev, linux-usb

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] 8+ messages in thread

* [PATCH 13/20] zd1211rw: 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 19:20 ` [PATCH 15/20] hostap_cs: " Julia Lawall
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
  To: Daniel Drake
  Cc: kernel-janitors, linux, joe, Ulrich Kunitz, John W. Linville,
	linux-wireless, netdev, linux-kernel

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/net/wireless/zd1211rw/zd_chip.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/zd1211rw/zd_chip.c b/drivers/net/wireless/zd1211rw/zd_chip.c
index 73a49b8..07b94ed 100644
--- a/drivers/net/wireless/zd1211rw/zd_chip.c
+++ b/drivers/net/wireless/zd1211rw/zd_chip.c
@@ -129,7 +129,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
 	r = zd_ioread16v_locked(chip, v16, a16, count16);
 	if (r) {
 		dev_dbg_f(zd_chip_dev(chip),
-			  "error: zd_ioread16v_locked. Error number %d\n", r);
+			  "error: %s. Error number %d\n", __func__, r);
 		return r;
 	}
 
@@ -256,8 +256,8 @@ int zd_iowrite32a_locked(struct zd_chip *chip,
 		if (r) {
 			zd_usb_iowrite16v_async_end(&chip->usb, 0);
 			dev_dbg_f(zd_chip_dev(chip),
-				"error _zd_iowrite32v_locked."
-				" Error number %d\n", r);
+				"error _%s. Error number %d\n", __func__,
+				r);
 			return r;
 		}
 	}


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 15/20] hostap_cs: 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 13/20] zd1211rw: " Julia Lawall
@ 2014-12-07 19:20 ` Julia Lawall
  2014-12-07 19:20 ` [PATCH 16/20] rtlwifi: rtl8821ae: " Julia Lawall
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
  To: Jouni Malinen
  Cc: kernel-janitors, linux, joe, John W. Linville, linux-wireless,
	netdev, linux-kernel

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/net/wireless/hostap/hostap_cs.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index b6ec519..50033aa 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -381,18 +381,15 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
 
 	res = pcmcia_read_config_byte(hw_priv->link, CISREG_COR, &old_cor);
 	if (res != 0) {
-		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
-		       "(%d)\n", res);
+		printk(KERN_DEBUG "%s failed 1 (%d)\n", __func__, res);
 		return;
 	}
-	printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n",
-		old_cor);
+	printk(KERN_DEBUG "%s: original COR %02x\n", __func__, old_cor);
 
 	res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR,
 				old_cor | COR_SOFT_RESET);
 	if (res != 0) {
-		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
-		       "(%d)\n", res);
+		printk(KERN_DEBUG "%s failed 2 (%d)\n", __func__, res);
 		return;
 	}
 
@@ -401,8 +398,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
 	/* Setup Genesis mode */
 	res = pcmcia_write_config_byte(hw_priv->link, CISREG_CCSR, hcr);
 	if (res != 0) {
-		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
-		       "(%d)\n", res);
+		printk(KERN_DEBUG "%s failed 3 (%d)\n", __func__, res);
 		return;
 	}
 	mdelay(10);
@@ -410,8 +406,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
 	res = pcmcia_write_config_byte(hw_priv->link, CISREG_COR,
 				old_cor & ~COR_SOFT_RESET);
 	if (res != 0) {
-		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
-		       "(%d)\n", res);
+		printk(KERN_DEBUG "%s failed 4 (%d)\n", __func__, res);
 		return;
 	}
 


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 16/20] rtlwifi: rtl8821ae: 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 13/20] zd1211rw: " Julia Lawall
  2014-12-07 19:20 ` [PATCH 15/20] hostap_cs: " Julia Lawall
@ 2014-12-07 19:20 ` Julia Lawall
  2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
  2014-12-08  3:55 ` Joe Perches
  4 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2014-12-07 19:20 UTC (permalink / raw)
  To: Larry Finger
  Cc: kernel-janitors, linux, joe, Chaoming Li, John W. Linville,
	linux-wireless, netdev, linux-kernel

Replace a misspelled function name by %s and then __func__.

8821 was written as 8812.

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/net/wireless/rtlwifi/rtl8821ae/dm.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/rtlwifi/rtl8821ae/dm.c b/drivers/net/wireless/rtlwifi/rtl8821ae/dm.c
index 9be1061..ba30b0d 100644
--- a/drivers/net/wireless/rtlwifi/rtl8821ae/dm.c
+++ b/drivers/net/wireless/rtlwifi/rtl8821ae/dm.c
@@ -2078,8 +2078,7 @@ void rtl8821ae_dm_txpwr_track_set_pwr(struct ieee80211_hw *hw,
 	if (rtldm->tx_rate != 0xFF)
 		tx_rate = rtl8821ae_hw_rate_to_mrate(hw, rtldm->tx_rate);
 
-	RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
-		 "===>rtl8812ae_dm_txpwr_track_set_pwr\n");
+	RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "===>%s\n", __func__);
 
 	if (tx_rate != 0xFF) { /* Mimic Modify High Rate BBSwing Limit.*/
 		/*CCK*/
@@ -2128,7 +2127,7 @@ void rtl8821ae_dm_txpwr_track_set_pwr(struct ieee80211_hw *hw,
 
 	if (method == BBSWING) {
 		RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
-			 "===>rtl8812ae_dm_txpwr_track_set_pwr\n");
+			 "===>%s\n", __func__);
 		if (rf_path == RF90_PATH_A) {
 			final_swing_idx[RF90_PATH_A] =
 				(rtldm->ofdm_index[RF90_PATH_A] >
@@ -2260,7 +2259,8 @@ void rtl8821ae_dm_txpower_tracking_callback_thermalmeter(
 	rtldm->txpower_trackinginit = true;
 
 	RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
-		 "===>rtl8812ae_dm_txpower_tracking_callback_thermalmeter,\n pDM_Odm->BbSwingIdxCckBase: %d,pDM_Odm->BbSwingIdxOfdmBase[A]:%d, pDM_Odm->DefaultOfdmIndex: %d\n",
+		 "===>%s,\n pDM_Odm->BbSwingIdxCckBase: %d,pDM_Odm->BbSwingIdxOfdmBase[A]:%d, pDM_Odm->DefaultOfdmIndex: %d\n",
+		 __func__,
 		 rtldm->swing_idx_cck_base,
 		 rtldm->swing_idx_ofdm_base[RF90_PATH_A],
 		 rtldm->default_ofdm_index);
@@ -2539,8 +2539,7 @@ void rtl8821ae_dm_txpower_tracking_callback_thermalmeter(
 		}
 	}
 
-	RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
-		 "<===rtl8812ae_dm_txpower_tracking_callback_thermalmeter\n");
+	RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "<===%s\n", __func__);
 }
 
 void rtl8821ae_dm_check_txpower_tracking_thermalmeter(struct ieee80211_hw *hw)

^ permalink raw reply related	[flat|nested] 8+ 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
                   ` (2 preceding siblings ...)
  2014-12-07 19:20 ` [PATCH 16/20] rtlwifi: rtl8821ae: " Julia Lawall
@ 2014-12-07 23:44 ` Julian Calaby
  2014-12-08  6:43   ` Julia Lawall
  2014-12-08  3:55 ` Joe Perches
  4 siblings, 1 reply; 8+ messages in thread
From: Julian Calaby @ 2014-12-07 23:44 UTC (permalink / raw)
  To: Julia Lawall
  Cc: linux-wireless, kernel-janitors, linux, Joe Perches,
	devel@driverdev.osuosl.org, linux-scsi, dri-devel, intel-gfx,
	linux-mtd, linux-samsung-soc, Mailing List, Arm,
	linux-kernel@vger.kernel.org, linux-pci, netdev, linux-usb

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] 8+ 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
                   ` (3 preceding siblings ...)
  2014-12-07 23:44 ` [PATCH 0/20] " Julian Calaby
@ 2014-12-08  3:55 ` Joe Perches
  4 siblings, 0 replies; 8+ messages in thread
From: Joe Perches @ 2014-12-08  3:55 UTC (permalink / raw)
  To: Julia Lawall
  Cc: linux-wireless, kernel-janitors, linux, devel, linux-scsi,
	dri-devel, intel-gfx, linux-mtd, linux-samsung-soc,
	linux-arm-kernel, linux-kernel, linux-pci, netdev, linux-usb

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] 8+ 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; 8+ messages in thread
From: Julia Lawall @ 2014-12-08  6:43 UTC (permalink / raw)
  To: Julian Calaby
  Cc: Julia Lawall, linux-wireless, kernel-janitors, linux, Joe Perches,
	devel@driverdev.osuosl.org, linux-scsi, dri-devel, intel-gfx,
	linux-mtd, linux-samsung-soc, Mailing List, Arm,
	linux-kernel@vger.kernel.org, linux-pci, netdev, linux-usb

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] 8+ 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; 8+ messages in thread
From: Julian Calaby @ 2014-12-10  2:56 UTC (permalink / raw)
  To: Julia Lawall
  Cc: linux-wireless, kernel-janitors, linux, Joe Perches,
	devel@driverdev.osuosl.org, linux-scsi, dri-devel, intel-gfx,
	linux-mtd, linux-samsung-soc, Mailing List, Arm,
	linux-kernel@vger.kernel.org, linux-pci, netdev, linux-usb

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] 8+ messages in thread

end of thread, other threads:[~2014-12-10  2:56 UTC | newest]

Thread overview: 8+ 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 13/20] zd1211rw: " Julia Lawall
2014-12-07 19:20 ` [PATCH 15/20] hostap_cs: " Julia Lawall
2014-12-07 19:20 ` [PATCH 16/20] rtlwifi: rtl8821ae: " Julia Lawall
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).