[PATCH v6 2/5] x86: Add cmdline_prepare() helper

Evgeniy Baskov posted 5 patches 3 years, 7 months ago
There is a newer version of this series
[PATCH v6 2/5] x86: Add cmdline_prepare() helper
Posted by Evgeniy Baskov 3 years, 7 months ago
Command line needs to be combined in both compressed and uncompressed
kernel from built-in and boot command line strings, which requires
non-trivial logic depending on CONFIG_CMDLINE_BOOL and
CONFIG_CMDLINE_OVERRIDE.

Add a helper function to avoid code duplication.

Signed-off-by: Evgeniy Baskov <baskov@ispras.ru>
---
 arch/x86/include/asm/shared/cmdline.h | 37 +++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 arch/x86/include/asm/shared/cmdline.h

diff --git a/arch/x86/include/asm/shared/cmdline.h b/arch/x86/include/asm/shared/cmdline.h
new file mode 100644
index 000000000000..a440d0bd6840
--- /dev/null
+++ b/arch/x86/include/asm/shared/cmdline.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_X86_SETUP_CMDLINE_H
+#define _ASM_X86_SETUP_CMDLINE_H
+
+#define _SETUP
+#include <asm/setup.h> /* For COMMAND_LINE_SIZE */
+#undef _SETUP
+
+#include <linux/string.h>
+
+#ifdef CONFIG_CMDLINE_BOOL
+#define COMMAND_LINE_INIT CONFIG_CMDLINE
+#else
+#define COMMAND_LINE_INIT ""
+#endif
+
+/*
+ * command_line and boot_command_line are expected to be at most
+ * COMMAND_LINE_SIZE length. command_line needs to be initialized
+ * with COMMAND_LINE_INIT.
+ */
+static inline void cmdline_prepare(char *command_line,
+				   const char *boot_command_line)
+{
+#ifdef CONFIG_CMDLINE_BOOL
+	if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
+		/* Append boot loader cmdline to builtin */
+		strlcat(command_line, " ", COMMAND_LINE_SIZE);
+		strlcat(command_line, boot_command_line, COMMAND_LINE_SIZE);
+	}
+#else
+	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+#endif
+}
+
+#endif /* _ASM_X86_SETUP_CMDLINE_H */
-- 
2.37.2
Re: [PATCH v6 2/5] x86: Add cmdline_prepare() helper
Posted by Borislav Petkov 3 years, 6 months ago
On Sat, Aug 27, 2022 at 05:08:07AM +0300, Evgeniy Baskov wrote:
> +/*
> + * command_line and boot_command_line are expected to be at most
> + * COMMAND_LINE_SIZE length. command_line needs to be initialized
> + * with COMMAND_LINE_INIT.
> + */
> +static inline void cmdline_prepare(char *command_line,
> +				   const char *boot_command_line)
> +{
> +#ifdef CONFIG_CMDLINE_BOOL

Right, this is an ifdef...

> +	if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {

... but this is a IS_ENABLED().

Why?

I think we should stick to one.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Re: [PATCH v6 2/5] x86: Add cmdline_prepare() helper
Posted by Evgeniy Baskov 3 years, 6 months ago
On 2022-09-30 20:30, Borislav Petkov wrote:
> On Sat, Aug 27, 2022 at 05:08:07AM +0300, Evgeniy Baskov wrote:
>> +/*
>> + * command_line and boot_command_line are expected to be at most
>> + * COMMAND_LINE_SIZE length. command_line needs to be initialized
>> + * with COMMAND_LINE_INIT.
>> + */
>> +static inline void cmdline_prepare(char *command_line,
>> +				   const char *boot_command_line)
>> +{
>> +#ifdef CONFIG_CMDLINE_BOOL
> 
> Right, this is an ifdef...
> 
>> +	if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
> 
> ... but this is a IS_ENABLED().
> 
> Why?
> 
> I think we should stick to one.

Right, I'll change #ifdef to IS_ENABLED() and resubmit.
Originally it was like that because CONFIG_CMDLINE was used
in one of the #ifdef branches and it's no longer needed.

Thanks,
Evgeniy Baskov