Linux内核代码格式审查
前言
Linux内核代码有一套自己的代码格式规范,相关的规范说明在内核代码树目录:Documentation/CodingStyle或Documentation/process/coding-style.rst。
具体细节大家可以自己去看,这里就不贴了。

以前提交内核补丁,一直用scripts/checkpatch.pl来过一遍代码格式,没怎么去研究。
最近刚好检查格式报了个错,以前没怎么遇到,于是就去看了下。

报错信息:

SHELL
ERROR: do not set execute permissions for source files
从提示上看很明显是源码文件权限问题。

Checkpatch 介绍
内核官方与它相关的文档:https://www.kernel.org/doc/html/latest/dev-tools/checkpatch.html
下面是它的介绍(保持原汁原味):

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.

Checkpatch is not always right. Your judgement takes precedence over checkpatch messages. If your code looks better with the violations, then its probably best left alone.

重点:Checkpatch不仅可以检查格式,也可以修正格式。它检查和修正不一定总是对的!只能作为参考,以自己的判断为准!

Checkpatch 使用方式

.......


作者: Shell