Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep and enable clang-format #118

Closed
wants to merge 5 commits into from
Closed

Conversation

evelikov
Copy link
Collaborator

@evelikov evelikov commented Sep 8, 2024

This series builds on the initial work in #91

  • reformat and clang-format off various blocks of existing code
  • imports the .clang-format from the kernel and tweaks it
  • runs ^^ and commits the changes in 4 patches, one per top-level folder - do we want the mass conversion?
  • adds CI action which runs on PRs - do we want one for pushes as well?

lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
Running this through clang-format results in a massacre. In some cases
we get function names starting at column 1, in others, every argument is
on separate line.

Just block the lot, so things are somewhat sane and consistent.

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
For some arrays, clang-format does far than ideal jobs reformatting. Do
so manually and ban clang-format from interfering.

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
For some arrays, clang-format does far than ideal jobs reformatting. Do
so manually and ban clang-format from interfering.

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
The .needspawn = false is the default so just remove them. Tall the
other tests don't set it, so remove the test-util.c instances.

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
Reformat a bunch of the args blocks and freeze them as-is. The remaining
instances clang-format handles correctly. The format is:

  progname,
  '--list', 'of', '--arguments',
  'modname',
  NULL

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
For some arrays, clang-format does far than ideal jobs reformatting. Do
so manually and ban clang-format from interfering.

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi added a commit that referenced this pull request Sep 9, 2024
Import .clang-format from Linux kernel as of v6.11-rc6.

Signed-off-by: Lucas De Marchi <[email protected]>
Link: #118
lucasdemarchi added a commit that referenced this pull request Sep 9, 2024
- Define our own foreach macros
- Add defines for attributes. This also needs the minimum clang-format
  version to be raised so it has the AttributeMacros setting.
- Redefine a few settings related to max number of columns and
  penalties for breaking lines

v2
 - [Emil] update attributes list

Signed-off-by: Lucas De Marchi <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
lucasdemarchi pushed a commit that referenced this pull request Sep 9, 2024
Ideally the config (and editors) will have hard and soft limit for the
line length. Until then, update the config so that clang-format does not
excessively reformat.

Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
@lucasdemarchi
Copy link
Contributor

Pushed up to the mass conversion commits. I'd like to postpone those for when we have the #85 fixed to avoid issues with backporting.

@lucasdemarchi
Copy link
Contributor

@evelikov can you regenerate the last commits?

@evelikov
Copy link
Collaborator Author

@lucasdemarchi all done

lucasdemarchi pushed a commit that referenced this pull request Sep 13, 2024
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
libkmod/libkmod-config.c Dismissed Show dismissed Hide dismissed
libkmod/libkmod-config.c Dismissed Show dismissed Hide dismissed
libkmod/libkmod-index.c Dismissed Show dismissed Hide dismissed
libkmod/libkmod-index.c Dismissed Show dismissed Hide dismissed
@@ -1540,12 +1505,12 @@
* loaded.
*/
snprintf(line, sizeof(line), "/sys/module/%s", mod->name);
dfd = open(line, O_RDONLY|O_CLOEXEC);
dfd = open(line, O_RDONLY | O_CLOEXEC);

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This argument to a file access function is derived from
user input (string read by fgets)
and then passed to open(__path).

bucket->used--;
hash->count--;

steps_used = bucket->used / hash->step;
steps_total = bucket->total / hash->step;
if (steps_used + 1 < steps_total) {
size_t size = (steps_used + 1) *
hash->step * sizeof(struct hash_entry);
size_t size = (steps_used + 1) * hash->step * sizeof(struct hash_entry);

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'.
testsuite/init_module.c Dismissed Show dismissed Hide dismissed
testsuite/testsuite.c Dismissed Show dismissed Hide dismissed
matches = sscanf(buf, "%s %s %c%u:%u", modname, devname,
&type, &maj, &min);
matches =
sscanf(buf, "%s %s %c%u:%u", modname, devname, &type, &maj, &min);

Check failure

Code scanning / CodeQL

Unbounded write Critical

This 'sscanf string argument' with input from
string read by fgets
may overflow the destination.
matches = sscanf(buf, "%s %s %c%u:%u", modname, devname,
&type, &maj, &min);
matches =
sscanf(buf, "%s %s %c%u:%u", modname, devname, &type, &maj, &min);

Check failure

Code scanning / CodeQL

Unbounded write Critical

This 'sscanf string argument' with input from
string read by fgets
may overflow the destination.
Signed-off-by: Emil Velikov <[email protected]>
Link: kmod-project#118
Signed-off-by: Lucas De Marchi <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Link: kmod-project#118
Signed-off-by: Lucas De Marchi <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Link: kmod-project#118
Signed-off-by: Lucas De Marchi <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Link: kmod-project#118
Signed-off-by: Lucas De Marchi <[email protected]>
To keep the style consistent.

Closes: kmod-project#88
Signed-off-by: Emil Velikov <[email protected]>
Link: kmod-project#118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 24, 2024
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 24, 2024
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 24, 2024
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 24, 2024
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
lucasdemarchi pushed a commit that referenced this pull request Sep 24, 2024
To keep the style consistent.

Closes: #88
Signed-off-by: Emil Velikov <[email protected]>
Link: #118
Signed-off-by: Lucas De Marchi <[email protected]>
@lucasdemarchi
Copy link
Contributor

Applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants