BPF List
 help / color / mirror / Atom feed
From: thinker.li@gmail.com
To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev,
	song@kernel.org, kernel-team@meta.com, andrii@kernel.org,
	davemarchevsky@meta.com, dvernet@meta.com
Cc: sinquersw@gmail.com, kuifeng@meta.com,
	Kui-Feng Lee <thinker.li@gmail.com>
Subject: [RFC bpf-next v4 3/6] bpf: Remove an unnecessary check.
Date: Fri,  2 Feb 2024 14:05:13 -0800	[thread overview]
Message-ID: <20240202220516.1165466-4-thinker.li@gmail.com> (raw)
In-Reply-To: <20240202220516.1165466-1-thinker.li@gmail.com>

From: Kui-Feng Lee <thinker.li@gmail.com>

The "i" here is always equal to "btf_type_vlen(t)" since
the "for_each_member()" loop never breaks.

Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
---
 kernel/bpf/bpf_struct_ops.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index 0decd862dfe0..f98f580de77a 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -189,20 +189,17 @@ int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc,
 		}
 	}
 
-	if (i == btf_type_vlen(t)) {
-		if (st_ops->init(btf)) {
-			pr_warn("Error in init bpf_struct_ops %s\n",
-				st_ops->name);
-			return -EINVAL;
-		} else {
-			st_ops_desc->type_id = type_id;
-			st_ops_desc->type = t;
-			st_ops_desc->value_id = value_id;
-			st_ops_desc->value_type = btf_type_by_id(btf,
-								 value_id);
-		}
+	if (st_ops->init(btf)) {
+		pr_warn("Error in init bpf_struct_ops %s\n",
+			st_ops->name);
+		return -EINVAL;
 	}
 
+	st_ops_desc->type_id = type_id;
+	st_ops_desc->type = t;
+	st_ops_desc->value_id = value_id;
+	st_ops_desc->value_type = btf_type_by_id(btf, value_id);
+
 	return 0;
 }
 
-- 
2.34.1


  parent reply	other threads:[~2024-02-02 22:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 22:05 [RFC bpf-next v4 0/6] Support PTR_MAYBE_NULL for struct_ops arguments thinker.li
2024-02-02 22:05 ` [RFC bpf-next v4 1/6] bpf: Allow PTR_TO_BTF_ID even for pointers to int thinker.li
2024-02-02 22:05 ` [RFC bpf-next v4 2/6] bpf: Extend PTR_TO_BTF_ID to handle pointers to scalar and array types thinker.li
2024-02-03  0:52   ` Martin KaFai Lau
2024-02-03  1:03     ` Kui-Feng Lee
2024-02-02 22:05 ` thinker.li [this message]
2024-02-03  0:46   ` [RFC bpf-next v4 3/6] bpf: Remove an unnecessary check Martin KaFai Lau
2024-02-03  1:03     ` Kui-Feng Lee
2024-02-02 22:05 ` [RFC bpf-next v4 4/6] bpf: add btf pointer to struct bpf_ctx_arg_aux thinker.li
2024-02-02 22:05 ` [RFC bpf-next v4 5/6] bpf: Create argument information for nullable arguments thinker.li
2024-02-03  0:40   ` Martin KaFai Lau
2024-02-03  1:57     ` Kui-Feng Lee
2024-02-04  0:21       ` Kui-Feng Lee
2024-02-05  1:53     ` Kui-Feng Lee
2024-02-02 22:05 ` [RFC bpf-next v4 6/6] selftests/bpf: Test PTR_MAYBE_NULL arguments of struct_ops operators thinker.li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240202220516.1165466-4-thinker.li@gmail.com \
    --to=thinker.li@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=davemarchevsky@meta.com \
    --cc=dvernet@meta.com \
    --cc=kernel-team@meta.com \
    --cc=kuifeng@meta.com \
    --cc=martin.lau@linux.dev \
    --cc=sinquersw@gmail.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox