tools: reject bare negative errno returns
This commit is contained in:
parent
622ec19c14
commit
7aaea3a4d3
@ -90,4 +90,6 @@
|
||||
`-EINVAL`、`-ENOMEM`、`-ENOENT`、`-EBUSY`、`-EEXIST`、`-ETIMEDOUT`。
|
||||
- 不要用裸 `-1` 表达多个失败原因;调用者需要能区分输入错误、资源耗尽、
|
||||
对象已存在和超时。
|
||||
- 不要直接返回 `-22` 这类负数字面量;使用 `-EINVAL` 这类符号化 errno,
|
||||
结构检查会拒绝裸负数返回。
|
||||
- errno 常量放在 `include/tianole/errno.h`,只增加当前内核实际使用的值。
|
||||
|
||||
@ -109,6 +109,21 @@ def check_no_relative_parent_includes(root: Path, files: list[Path]) -> list[str
|
||||
return errors
|
||||
|
||||
|
||||
def check_no_bare_negative_errno(root: Path, files: list[Path]) -> list[str]:
|
||||
errors = []
|
||||
return_re = re.compile(r"\breturn\s+-[0-9]+\s*;")
|
||||
|
||||
for path in files:
|
||||
for line_no, line in enumerate(read_text(root, path).splitlines(), 1):
|
||||
if return_re.search(line):
|
||||
errors.append(
|
||||
f"{path}:{line_no}: return a symbolic negative errno "
|
||||
"such as -EINVAL instead of a bare negative number"
|
||||
)
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
def is_function_declaration_start(line: str) -> bool:
|
||||
stripped = line.strip()
|
||||
|
||||
@ -408,6 +423,7 @@ def main() -> int:
|
||||
|
||||
errors = []
|
||||
errors.extend(check_no_relative_parent_includes(root, source_files(files)))
|
||||
errors.extend(check_no_bare_negative_errno(root, source_files(files)))
|
||||
errors.extend(check_public_header_docs(root, public_headers(files)))
|
||||
errors.extend(check_selftests_are_centralized(c_files(files)))
|
||||
errors.extend(check_makefile_source_lists(root, files, all_mode))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user