A lot of distributions are emitting warnings when using egrep and fgrep
since these are deprecated.
Update occurrences of egrep to 'grep -E' keeping the same functionality
and making the code more portable without emitting warnings.
Smatch[1][2] is a pluggable static analysis for C. It may help us find
out the potential problem of the example code.
Doing with smatch, if set the --file-output flag, it will generate the
{}.c.smatch report for each c file. This will make a little bit
complicated to collect all the report messages. So, here we stay at the
default setting, stdout for the smatch messages.
For more information, see:
- https://lwn.net/Articles/696624/
- https://elinux.org/images/d/d3/Bargmann.pdf
Also, fix the warning from Smatch:
Smatch failed: 1 warning(s), 1 error(s)
lkmpg/examples/procfs2.c:57 procfile_write() error: buffer overflow 'procfs_buffer' 1024 <= 1024
lkmpg/examples/kbleds.c:58 kbleds_init() warn: argument 5 to %lx specifier is cast from pointer
Furthermore, the effect of the write operation in procfs2.c is too
implied. So after writing, print the buffer every time.
Close#122
[1] https://github.com/error27/smatch
[2] https://repo.or.cz/w/smatch.git
Cppcheck[1] is integrated into CI pipeline for running static analysis.
However, Cppcheck is known to report false-positive, and we have to
suppress some warnings in advance.
[1] https://cppcheck.sourceforge.io/