Size: 1175
Comment:
|
← Revision 14 as of 2017-12-30 01:30:00 ⇥
Size: 1584
Comment: converted to 1.6 markup
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
I wrote a few tools to do a multiline (git-)grep. You have to source [wiki:roelkluin/cvars cvars] to use it. Do the searches in your git Linux kernel directory. | I wrote a few tools to do a multiline (git) grep, see [[roelkluin/cvars_howto|cvars howto]]. To use these tools you first source [[roelkluin/cvars|cvars]] and then do the searches in your git directory. |
Line 9: | Line 9: |
see [wiki:roelkluin/cvars_howto gres howto] for more examples. | '''Search for conditions that execute the same code in the if and else branches''' {{{ gres -A40 "^ if \(" \ "if \(.8.\) (@branch) else \9" | less }}} '''Search for switch cases that execute the same code.''' {{{ gres -A40 "^ case@S[^:]*: $" \ "case@S[^:\n]*: \n (([^\n]*[^:{[:space:]] \n|\{.8.\}){2,}) (case@S[^:\n]*: ([^\n]*[^:{[:space:]] \n|\{.8.\})*)* case@S[^:\n]*: \1 (case|default)@S[^:\n]*:" | less }}} |
Roel Kluin
Email: roel.kluin@gmail.com)
I wrote a few tools to do a multiline (git) grep, see cvars howto. To use these tools you first source cvars and then do the searches in your git directory.
Search for conditions that execute the same code in the if and else branches
gres -A40 "^ if \(" \ "if \(.8.\) (@branch) else \9" | less
Search for switch cases that execute the same code.
gres -A40 "^ case@S[^:]*: $" \ "case@S[^:\n]*: \n (([^\n]*[^:{[:space:]] \n|\{.8.\}){2,}) (case@S[^:\n]*: ([^\n]*[^:{[:space:]] \n|\{.8.\})*)* case@S[^:\n]*: \1 (case|default)@S[^:\n]*:" | less
Some functions' return codes should be audited, the scripts below searches for code sections where this lacks.
Z="request_region kmalloc vmalloc kzalloc scsi_register create_proc_entry" for z in $Z; do echo "---[ $z ]---" gres -B1 -A20 "^((.* (@w) =)? (\( @V \** \) )*)? $z \(" \ "@Q2(\**@w) = (\**@w = )*(\( @V \** \) )* $z \(...\) ;.* (return|[&|(]) (\1 [=\!]= NULL|\!? \1|NULL [=\!]= \1) [&|)?;]" \ "@Q2(\**@w = )+(\( @V \** \) )* $z \(...\) ;" done | less Z="request_irq register_netdev misc_register create_proc_profile kernel_thread do_fork" for z in $Z; do echo "---[ $z ]---" gres -B1 -A20 "^((.* (@w) =)? (\( @V \** \) )*)? $z \(" \ "@Q2(\**@w) = (\**@w = )*(\( @V \** \) )* $z \(...\) ;.* (return|[&|(]) (\1 (<|[\!>=]=) 0|\!? \1|0 (>|[\!<=]=) \1) [)&|?;]" \ "@Q2(\**@w = )+(\( @V \** \) )* $z \(...\) ;" done | less