KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents
Revision 13 as of 2010-01-20 01:31:31
KernelNewbies:
  • roelkluin

Roel Kluin

Email: roel.kluin@gmail.com)

I wrote a few tools to do a multiline (git) grep, see [wiki:roelkluin/cvars_howto cvars howto]. To use these tools you first source [wiki:roelkluin/cvars 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
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01