LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] bpf: btf: silence uninitialize variable warnings
@ 2018-04-27 14:04 Dan Carpenter
2018-04-27 17:18 ` Martin KaFai Lau
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-04-27 14:04 UTC (permalink / raw)
To: Alexei Starovoitov, Martin KaFai Lau
Cc: Daniel Borkmann, netdev, linux-kernel, kernel-janitors
Smatch complains that size can be uninitialized if btf_type_id_size()
returns NULL. It seems reasonable enough to check for that.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This goes to the BPF tree (linux-next).
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 22e1046a1a86..e631b6fd60d3 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -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++) {
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/2] bpf: btf: silence uninitialize variable warnings
2018-04-27 14:04 [PATCH 1/2] bpf: btf: silence uninitialize variable warnings Dan Carpenter
@ 2018-04-27 17:18 ` Martin KaFai Lau
0 siblings, 0 replies; 2+ messages in thread
From: Martin KaFai Lau @ 2018-04-27 17:18 UTC (permalink / raw)
To: Dan Carpenter
Cc: Alexei Starovoitov, Daniel Borkmann, netdev, linux-kernel,
kernel-janitors
On Fri, Apr 27, 2018 at 05:04:09PM +0300, Dan Carpenter wrote:
> Smatch complains that size can be uninitialized if btf_type_id_size()
> returns NULL. It seems reasonable enough to check for that.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This goes to the BPF tree (linux-next).
>
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 22e1046a1a86..e631b6fd60d3 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -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.
> 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..
> elem_ops = btf_type_ops(elem_type);
> seq_puts(m, "[");
> for (i = 0; i < array->nelems; i++) {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-27 17:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 14:04 [PATCH 1/2] bpf: btf: silence uninitialize variable warnings Dan Carpenter
2018-04-27 17:18 ` Martin KaFai Lau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).