linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: liqiong <liqiong@nfschina.com>
To: Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	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: Fri, 13 May 2022 10:04:30 +0800	[thread overview]
Message-ID: <6af0b0fe-daf3-5310-2f13-e411a80bdde8@nfschina.com> (raw)
In-Reply-To: <92cc4844-5815-c3b0-63be-2e54dc36e1d9@iogearbox.net>



在 2022年05月13日 04:59, Daniel Borkmann 写道:
> On 5/12/22 7:08 PM, liqiong wrote:
>> 在 2022年05月12日 23:16, Yonghong Song 写道:
>>>
>>> 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.
>>
>> The  string form of "char *" creates two variables in the final assembly output,
>> a static string, and a char pointer to the static string.  Use  "objdump -S -D  *.o",
>> can find out the static string  occurring  at "Contents of section .rodata".
>
> There are ~360 instances of this type in the tree from a quick grep, do you
> plan to convert all them ?

Hi daniel,

I have fixed all the string form in kernel tree, summited  two patches. 
Have searched the kernel tree by "grep  -nHre char.*\*.*=.*\"",  and checked all the "char *foo = "bar" "
string form,  only five  instances are needed to fix in bpf direcotry (2 files) and trace directory (2 files).
In most cases, need a char pointer anyway, just like this:

[const] char *foo = "bar";
if (xxx)
    foo = "blash";

In this situation, can't  change  "char *foo"  to  "char foo[]".

This work was published in "KernelJanitors/Todo".  So, I fixed.

Thanks.

>
> Thanks,
> Daniel


  reply	other threads:[~2022-05-13  2:04 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
2022-05-12 17:08   ` liqiong
2022-05-12 20:59     ` Daniel Borkmann
2022-05-13  2:04       ` liqiong [this message]
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=6af0b0fe-daf3-5310-2f13-e411a80bdde8@nfschina.com \
    --to=liqiong@nfschina.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=netdev@vger.kernel.org \
    --cc=qixu@nfschina.com \
    --cc=renyu@nfschina.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@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;
as well as URLs for NNTP newsgroup(s).