Skip to contentSkip to conversation

bpf: bpf_struct_ops: Remove unnecessary ‘0’ values from err

PATCH In review Li kunyu 2 participants 2 messages Aug 2, 2023 – Aug 3, 2023

Subsystems (3)
lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH 1/1 bpf: bpf_struct_ops: Remove unnecessary ‘0’ values from err

err is assigned first, so it does not need to initialize the assignment.

---
 kernel/bpf/bpf_struct_ops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/bpf_struct_ops.c +2 -2
index d3f0a4825fa6..5b591fda5d62 100644
@@ -376,7 +376,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
 	const struct btf_type *t = st_ops->type;
 	struct bpf_tramp_links *tlinks = NULL;
 	void *udata, *kdata;
-	int prog_fd, err = 0;
+	int prog_fd, err;
 	void *image, *image_end;
 	u32 i;
 
@@ -818,7 +818,7 @@ static int bpf_struct_ops_map_link_update(struct bpf_link *link, struct bpf_map
 	struct bpf_struct_ops_map *st_map, *old_st_map;
 	struct bpf_map *old_map;
 	struct bpf_struct_ops_link *st_link;
-	int err = 0;
+	int err;
 
 	st_link = container_of(link, struct bpf_struct_ops_link, link);
 	st_map = container_of(new_map, struct bpf_struct_ops_map, map);
Signature · 1 line
2.18.2
#1 lore raw
Quoted 12 lines · Li kunyu

err is assigned first, so it does not need to initialize the assignment.

---
  kernel/bpf/bpf_struct_ops.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/bpf_struct_ops.c +0 -0
index d3f0a4825fa6..5b591fda5d62 100644

kernel/bpf/bpf_struct_ops.c static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, · line 379

Quoted 5 lines
kernel/bpf/bpf_struct_ops.c +1 -1
@@ -376,7 +376,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
  	const struct btf_type *t = st_ops->type;
  	struct bpf_tramp_links *tlinks = NULL;
  	void *udata, *kdata;
-	int prog_fd, err = 0;
+	int prog_fd, err;

The "tlinks" init in two lines above is also not needed. While at the same function, please take this chance to remove it together.

Please tag the subject with "bpf-next v2" in the next respin.

Quoted 12 lines
kernel/bpf/bpf_struct_ops.c +1 -1
  	void *image, *image_end;
  	u32 i;
 
@@ -818,7 +818,7 @@ static int bpf_struct_ops_map_link_update(struct bpf_link *link, struct bpf_map
  	struct bpf_struct_ops_map *st_map, *old_st_map;
  	struct bpf_map *old_map;
  	struct bpf_struct_ops_link *st_link;
-	int err = 0;
+	int err;
 
  	st_link = container_of(link, struct bpf_struct_ops_link, link);
  	st_map = container_of(new_map, struct bpf_struct_ops_map, map);