Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How checkpatch.pl work and what exactly we can get by running it on a patch?

Tags:

git

linux

I am very new to Linux and Git. I want to know what exactly checkpatch.pl script does. I know there is a source code available on the Internet but it's a Perl script and I don't know Perl.

So, can anyone here explain me here what exactly does it do?

like image 315
Amit Sharma Avatar asked Nov 06 '14 13:11

Amit Sharma


People also ask

What is checkpatch in Linux?

Checkpatch (scripts/checkpatch.pl) is a perl script which checks for trivial style violations in patches and optionally corrects them. Checkpatch can also be run on file contexts and without the kernel tree.

How do I run a check patch from the command line?

$ chmod +c checkpatch.pl $ ./checkpatch.pl --no-tree -f sample_module.c –no-tree : By default checkpatch must be run from the top-level dir. of a kernel tree. This option overrides the default behaviour.

How to check a file instead of a patch in Linux?

By default checkpatch utility checks if a patch is well formated and conforms to Linux Kernel Coding Style Rules. If you want to check a file instead of a patch, you need to use -f option. If your file is not located in a regular kernel tree, you need --no-tree option. So./checkpatch.pl -f --no-tree mychardriver.c should do the job.

What does -F do in checkpatch?

-f : By default checkpatch verifies kernel patches. This option instructs it to treat the file as a regular source file.


2 Answers

It is a tool to check your coding style match Linux coding style or not. You can use -help to see what options you can use. After it check your file, the tool prints a result like compile result. The result show you which line has coding style errors and warnings, and reminds you how to modify your code. And also you can modify the script tool to match your own coding style.

like image 133
sunnyleevip Avatar answered Oct 07 '22 22:10

sunnyleevip


checkpatch.pl is a script in the kernel tree that facilitates better kernel code, and can be used to check many coding style rules. This script applies on patch files by default, but can also process complete source files using the -f or --file option.

See:

scripts/checkpatch.pl -h # running from kernel source root

or

checkpatch.pl -h --no-tree # when pwd ≠ root of the kernel source
like image 43
Skynet Avatar answered Oct 07 '22 22:10

Skynet