"parse_early_param()" and why "tmp_cmdline" must be static?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  just for the entertainment value, i'm figuring out how the kernel
boot-time parameters are processed, and i'm curious about one step in
the process.  i've followed the logic all the way down to the routine
parse_early_param() in init/main.c:

=====
/* Arch code calls this early on, or if not, just before other parsing. */
void __init parse_early_param(void)
{
        static __initdata int done = 0;
        static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];

        if (done)
                return;

        /* All fall through to do_early_param. */
        strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
        parse_args("early options", tmp_cmdline, NULL, 0, do_early_param);
        done = 1;
}
=====

  upon entry, the global variable "boot_command_line" already contains
the full character string of kernel parameters, and it will allegedly
remain absolutely untouched -- anyone who wants to mess with that line
must make a copy of it first.

  also, different architectures call that routine at different times,
so it contains a simple static "done" flag to keep track of whether
it's already been called.  so far, so good.

  but (and, admittedly, i haven't finished following this all the way
thru to the end), it's not clear why the temporary copy of that line,
"tmp_cmdline", needs to be static.  just from what you can see above,
it would appear that a single pass through that routine will do all
of the necessary cmdline processing of early parameters, and i already
know that the contents of tmp_cmdline will be mangled as this
processing is going on, but there's no evidence that that new line
needs to be retained after this routine returns.

  it's not being passed back and the "done" flag will ensure that this
processing will never happen twice so, just superficially, you'd think
that there's no reason for tmp_cmdline to be static.

  i'm still following the logic so it may be that there's a reason for
this -- perhaps bits and pieces of that line are retained to be
incorporated into other structures.  but if someone knows offhand
what's happening here, that would be nice.  thanks.

rday

p.s.  since tmp_cmdline is also declared as "__initdata", it's
definitely going to vanish once booting is done so, certainly, if it
*is* being retained for some other reason, that reason better be
temporary.

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux