From: Evgeniy Baskov <baskov@ispras.ru>
To: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org, x86@kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>
Subject: Re: [PATCH v7 2/5] x86: Add cmdline_prepare() helper
Date: Thu, 10 Nov 2022 11:59:49 +0300 [thread overview]
Message-ID: <7e718c64442469cce6b68988c607a240@ispras.ru> (raw)
In-Reply-To: <Y2wvjmpwpOWsc5WT@zn.tnic>
On 2022-11-10 01:54, Borislav Petkov wrote:
> On Tue, Oct 04, 2022 at 03:48:21PM +0300, Evgeniy Baskov wrote:
>> +static inline void cmdline_prepare(char *command_line,
>> + const char *boot_command_line)
>> +{
>> + if (!IS_ENABLED(CONFIG_CMDLINE_BOOL)) {
>> + strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
>> + } else if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
>> + /* Append boot loader cmdline to builtin one. */
>> + strlcat(command_line, " ", COMMAND_LINE_SIZE);
>> + strlcat(command_line, boot_command_line, COMMAND_LINE_SIZE);
>> + }
>
> Why can't we make this plain and simple and understandable at a quick
> glance instead of putting parts of the string in some variable and then
> still doing copying outside of the function?
>
> IOW, simply put everything in a single function:
>
> static inline void cmdline_prepare(char *dst,
> const char *builtin_cmdline,
> const char *boot_command_line)
> {
> /* Depends on CONFIG_CMDLINE_BOOL, overwrite with builtin
> cmdline */
> if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
> strscpy(dst, builtin_cmdline, COMMAND_LINE_SIZE);
> else if (IS_ENABLED(CONFIG_CMDLINE_BOOL)) {
> if (builtin_cmdline[0]) {
> /* append boot loader cmdline to builtin */
> srtlcat(dst, builtin_cmdline,
> COMMAND_LINE_SIZE)
> strlcat(dst, " ", COMMAND_LINE_SIZE);
> strlcat(dst, boot_command_line,
> COMMAND_LINE_SIZE);
> } else {
> strscpy(dst, boot_command_line,
> COMMAND_LINE_SIZE);
> }
> }
> }
>
> which is then called like this:
>
> cmdline_prepare(command_line, builtin_cmdline, boot_command_line);
>
> and when it returns command_line is ready. And before it, command_line
> is the empty string:
>
> static char __initdata command_line[COMMAND_LINE_SIZE];
>
> And all the complexity is in one single function and that single
> function does each case in an obvious manner and you don't have to go
> look outside of the function body to understand what it does.
>
> Hmmm?
Well, my version takes one less copy... But clarity is more important
in the kernel, I guess. I'll send updated version soon.
Thanks,
Evgeniy Baskov
next prev parent reply other threads:[~2022-11-10 9:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-04 12:48 [PATCH v7 0/5] Parse CONFIG_CMDLINE in compressed kernel Evgeniy Baskov
2022-10-04 12:48 ` [PATCH v7 1/5] x86/boot: Add strlcat() and strscpy() to " Evgeniy Baskov
2022-10-04 12:48 ` [PATCH v7 2/5] x86: Add cmdline_prepare() helper Evgeniy Baskov
2022-11-09 22:54 ` Borislav Petkov
2022-11-10 8:59 ` Evgeniy Baskov [this message]
2022-11-10 10:02 ` Borislav Petkov
2022-10-04 12:48 ` [PATCH v7 3/5] x86/setup: Use cmdline_prepare() in setup.c Evgeniy Baskov
2022-10-04 12:48 ` [PATCH v7 4/5] x86/boot: Use cmdline_prapare() in compressed kernel Evgeniy Baskov
2022-10-04 12:48 ` [PATCH v7 5/5] x86/boot: Remove no longer needed includes Evgeniy Baskov
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=7e718c64442469cce6b68988c607a240@ispras.ru \
--to=baskov@ispras.ru \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=khoroshilov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@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
all inboxes | Powered by JetHome®