public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Evgeniy Baskov <baskov@ispras.ru>
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: Wed, 9 Nov 2022 23:54:06 +0100	[thread overview]
Message-ID: <Y2wvjmpwpOWsc5WT@zn.tnic> (raw)
In-Reply-To: <603dc95beb44340aa1787328589ff2e073b251e1.1664886978.git.baskov@ispras.ru>

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?

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2022-11-09 22:54 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 [this message]
2022-11-10  8:59     ` Evgeniy Baskov
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=Y2wvjmpwpOWsc5WT@zn.tnic \
    --to=bp@alien8.de \
    --cc=baskov@ispras.ru \
    --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