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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check code style with clang-format

on:
pull_request:
branches: [master]

permissions:
contents: read

jobs:
stylecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }}
- uses: yshui/git-clang-format-lint@a65b466f5903524aef27552f63c3906c0f73f184 # v1.16
with:
base: ${{ github.event.pull_request.base.sha }}
19 changes: 8 additions & 11 deletions libkmod/libkmod-builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ struct kmod_builtin_info {
char *buf;
};

static bool kmod_builtin_info_init(struct kmod_builtin_info *info,
struct kmod_ctx *ctx)
static bool kmod_builtin_info_init(struct kmod_builtin_info *info, struct kmod_ctx *ctx)
{
char path[PATH_MAX];
FILE *fp = NULL;
Expand Down Expand Up @@ -78,7 +77,7 @@ static ssize_t get_string(struct kmod_builtin_info *info)
}

static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
struct strbuf *buf)
struct strbuf *buf)
{
const size_t modlen = strlen(modname);
ssize_t count, n;
Expand All @@ -100,7 +99,7 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
if (dot == NULL) {
count = -EINVAL;
ERR(info->ctx, "get_strings: "
"unexpected string without modname prefix\n");
"unexpected string without modname prefix\n");
return count;
}
if (strncmp(line, modname, modlen) || line[modlen] != '.') {
Expand All @@ -113,11 +112,10 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
continue;
break;
}
if (!strbuf_pushchars(buf, dot + 1) ||
!strbuf_pushchar(buf, '\0')) {
if (!strbuf_pushchars(buf, dot + 1) || !strbuf_pushchar(buf, '\0')) {
count = -errno;
ERR(info->ctx, "get_strings: "
"failed to append modinfo string\n");
"failed to append modinfo string\n");
return count;
}
count++;
Expand All @@ -126,7 +124,7 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
if (count == INTPTR_MAX) {
count = -ENOMEM;
ERR(info->ctx, "get_strings: "
"too many modinfo strings encountered\n");
"too many modinfo strings encountered\n");
return count;
}

Expand All @@ -142,8 +140,7 @@ static char **strbuf_to_vector(struct strbuf *buf, size_t count)
size_t n;

/* make sure that vector and strings fit into memory constraints */
if (SIZE_MAX / sizeof(char *) - 1 < count ||
SIZE_MAX - buf->used < vecsz) {
if (SIZE_MAX / sizeof(char *) - 1 < count || SIZE_MAX - buf->used < vecsz) {
errno = ENOMEM;
return NULL;
}
Expand All @@ -166,7 +163,7 @@ static char **strbuf_to_vector(struct strbuf *buf, size_t count)

/* array will be allocated with strings in a single malloc, just free *array */
ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname,
char ***modinfo)
char ***modinfo)
{
struct kmod_builtin_info info;
struct strbuf buf;
Expand Down
Loading