From: Yonghong Song <yhs@fb.com>
To: liqiong <liqiong@nfschina.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, hukun@nfschina.com,
qixu@nfschina.com, yuzhe@nfschina.com, renyu@nfschina.com
Subject: Re: [PATCH 1/2] kernel/bpf: change "char *" string form to "char []"
Date: Thu, 12 May 2022 08:16:21 -0700 [thread overview]
Message-ID: <bd3d4379-e4aa-79c7-85b8-cc930a04f267@fb.com> (raw)
In-Reply-To: <20220512142814.26705-1-liqiong@nfschina.com>
On 5/12/22 7:28 AM, liqiong wrote:
> The string form of "char []" declares a single variable. It is better
> than "char *" which creates two variables.
Could you explain in details about why it is better in generated codes?
It is not clear to me why your patch is better than the original code.
>
> Signed-off-by: liqiong <liqiong@nfschina.com>
> ---
> kernel/bpf/btf.c | 4 ++--
> kernel/bpf/verifier.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 0918a39279f6..218a8ac73644 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -894,10 +894,10 @@ static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf,
> static const char *btf_show_name(struct btf_show *show)
> {
> /* BTF_MAX_ITER array suffixes "[]" */
> - const char *array_suffixes = "[][][][][][][][][][]";
> + static const char array_suffixes[] = "[][][][][][][][][][]";
> const char *array_suffix = &array_suffixes[strlen(array_suffixes)];
> /* BTF_MAX_ITER pointer suffixes "*" */
> - const char *ptr_suffixes = "**********";
> + static const char ptr_suffixes[] = "**********";
> const char *ptr_suffix = &ptr_suffixes[strlen(ptr_suffixes)];
> const char *name = NULL, *prefix = "", *parens = "";
> const struct btf_member *m = show->state.member;
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index d175b70067b3..78a090fcbc72 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -7346,7 +7346,7 @@ static int sanitize_err(struct bpf_verifier_env *env,
> const struct bpf_reg_state *off_reg,
> const struct bpf_reg_state *dst_reg)
> {
> - static const char *err = "pointer arithmetic with it prohibited for !root";
> + static const char err[] = "pointer arithmetic with it prohibited for !root";
> const char *op = BPF_OP(insn->code) == BPF_ADD ? "add" : "sub";
> u32 dst = insn->dst_reg, src = insn->src_reg;
>
next prev parent reply other threads:[~2022-05-12 15:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 14:28 [PATCH 1/2] kernel/bpf: change "char *" string form to "char []" liqiong
2022-05-12 15:16 ` Yonghong Song [this message]
2022-05-12 17:08 ` liqiong
2022-05-12 20:59 ` Daniel Borkmann
2022-05-13 2:04 ` liqiong
2022-05-13 11:14 ` David Laight
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=bd3d4379-e4aa-79c7-85b8-cc930a04f267@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=hukun@nfschina.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liqiong@nfschina.com \
--cc=netdev@vger.kernel.org \
--cc=qixu@nfschina.com \
--cc=renyu@nfschina.com \
--cc=songliubraving@fb.com \
--cc=yuzhe@nfschina.com \
/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