Skip to contentSkip to conversation

bpf: btf: silence uninitialize variable warnings

PATCH In review Dan Carpenter 2 participants 2 messages Apr 27, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bpf: btf: silence uninitialize variable warnings

Smatch complains that size can be uninitialized if btf_type_id_size() returns NULL. It seems reasonable enough to check for that.

---
This goes to the BPF tree (linux-next).

kernel/bpf/btf.c +4 -1
index 22e1046a1a86..e631b6fd60d3 100644
@@ -1229,7 +1229,8 @@ static int btf_array_check_member(struct btf_verifier_env *env,
 	}
 
 	array_type_id = member->type;
-	btf_type_id_size(btf, &array_type_id, &array_size);
+	if (!btf_type_id_size(btf, &array_type_id, &array_size))
+		return -EINVAL;
 	struct_size = struct_type->size;
 	bytes_offset = BITS_ROUNDDOWN_BYTES(struct_bits_off);
 	if (struct_size - bytes_offset < array_size) {
@@ -1351,6 +1352,8 @@ static void btf_array_seq_show(const struct btf *btf, const struct btf_type *t,
 
 	elem_type_id = array->type;
 	elem_type = btf_type_id_size(btf, &elem_type_id, &elem_size);
+	if (!elem_type)
+		return;
 	elem_ops = btf_type_ops(elem_type);
 	seq_puts(m, "[");
 	for (i = 0; i < array->nelems; i++) {
#1 lore raw
Quoted 12 lines · Dan Carpenter

Smatch complains that size can be uninitialized if btf_type_id_size() returns NULL. It seems reasonable enough to check for that.

---
This goes to the BPF tree (linux-next).

kernel/bpf/btf.c +0 -0
index 22e1046a1a86..e631b6fd60d3 100644

kernel/bpf/btf.c static int btf_array_check_member(struct btf_verifier_env *env, · line 1233

Quoted 6 lines
kernel/bpf/btf.c +2 -1
@@ -1229,7 +1229,8 @@ static int btf_array_check_member(struct btf_verifier_env *env,
 	}
 
 	array_type_id = member->type;
-	btf_type_id_size(btf, &array_type_id, &array_size);
+	if (!btf_type_id_size(btf, &array_type_id, &array_size))
+		return -EINVAL;

This check is not needed. It does not happen for array.

kernel/bpf/btf.c static void btf_array_seq_show(const struct btf *btf, const struct btf_type *t, · line 1356

Quoted 9 lines
kernel/bpf/btf.c +2 -0
 	struct_size = struct_type->size;
 	bytes_offset = BITS_ROUNDDOWN_BYTES(struct_bits_off);
 	if (struct_size - bytes_offset < array_size) {
@@ -1351,6 +1352,8 @@ static void btf_array_seq_show(const struct btf *btf, const struct btf_type *t,
 
 	elem_type_id = array->type;
 	elem_type = btf_type_id_size(btf, &elem_type_id, &elem_size);
+	if (!elem_type)
+		return;

This case has already been checked in verification phase. No need to recheck everything again..

Quoted 3 lines
kernel/bpf/btf.c +0 -0
 	elem_ops = btf_type_ops(elem_type);
 	seq_puts(m, "[");
 	for (i = 0; i < array->nelems; i++) {