Re: [PATCH] bootconfig: do not put quotes on cmdline items unless necessary

From: Andrew Morton
Date: Wed Mar 06 2024 - 15:42:19 EST


On Wed, 6 Mar 2024 13:24:52 +0100 Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx> wrote:

> When trying to migrate to using bootconfig to embed the kernel's and
> PID1's command line with the kernel image itself, and so allowing
> changing that without modifying the bootloader, I noticed that
> /proc/cmdline changed from e.g.
>
> console=ttymxc0,115200n8 cma=128M quiet -- --log-level=notice
>
> to
>
> console="ttymxc0,115200n8" cma="128M" quiet -- --log-level="notice"
>
> The kernel parameters are parsed just fine, and the quotes are indeed
> stripped from the actual argv[] given to PID1. However, the quoting
> doesn't really serve any purpose and looks excessive, and might
> confuse some (naive) userspace tool trying to parse /proc/cmdline. So
> do not quote the value unless it contains whitespace.
>
> ...
>
> --- a/init/main.c
> +++ b/init/main.c
> @@ -319,12 +319,20 @@ static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata;
>
> #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0)
>
> +static int has_space(const char *v)
> +{
> + for (; *v; v++)
> + if (isspace(*v))
> + return 1;
> + return 0;
> +}

Do we already have something which does this?

Could do strchr(' ')||strchr('\t')

Do we really support tab separation here? I doubt if that gets used or
tested much.

This function could be __init.