[PATCH] bpf: fix checkpatch POINTER_LOCATION, SPACING, ASSIGN_IN_IF error

From: Rui Li
Date: Mon Oct 10 2022 - 10:43:41 EST


This commit cleans up checkpatch errors as follows:
ERROR:POINTER_LOCATION: "foo* bar" should be "foo *bar"
ERROR:ASSIGN_IN_IF: do not use assignment in if condition
ERROR:SPACING: space required after that ',' (ctx:VxV)

There still are some false positive errors like spaces required.

Signed-off-by: Rui Li <me@xxxxxxxxx>
---
kernel/bpf/arraymap.c | 10 ++++++----
kernel/bpf/btf.c | 2 +-
kernel/bpf/core.c | 8 +++++---
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 832b2659e96e..271af4b934d4 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -154,7 +154,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
return &array->map;
}

-static void *array_map_elem_ptr(struct bpf_array* array, u32 index)
+static void *array_map_elem_ptr(struct bpf_array *array, u32 index)
{
return array->value + (u64)array->elem_size * index;
}
@@ -814,9 +814,11 @@ int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value)

rcu_read_lock();
elem = array_map_lookup_elem(map, key);
- if (elem && (ptr = READ_ONCE(*elem)))
- *value = map->ops->map_fd_sys_lookup_elem(ptr);
- else
+ if (elem) {
+ ptr = READ_ONCE(*elem);
+ if (ptr)
+ *value = map->ops->map_fd_sys_lookup_elem(ptr);
+ } else
ret = -ENOENT;
rcu_read_unlock();

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index eba603cec2c5..a31e31951d60 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5482,7 +5482,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,

if (ctx_arg_info->offset == off) {
if (!ctx_arg_info->btf_id) {
- bpf_log(log,"invalid btf_id for context argument offset %u\n", off);
+ bpf_log(log, "invalid btf_id for context argument offset %u\n", off);
return false;
}

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 711fd293b6de..3a63787598c5 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -467,9 +467,11 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
* We need to probe here before we do any reallocation where
* we afterwards may not fail anymore.
*/
- if (insn_adj_cnt > cnt_max &&
- (err = bpf_adj_branches(prog, off, off + 1, off + len, true)))
- return ERR_PTR(err);
+ if (insn_adj_cnt > cnt_max) {
+ err = bpf_adj_branches(prog, off, off + 1, off + len, true);
+ if (err)
+ return ERR_PTR(err);
+ }

/* Several new instructions need to be inserted. Make room
* for them. Likely, there's no need for a new allocation as
--
2.30.2