puzzled about some invocations of __setup()

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

 



  among countless invocations of __setup() that define boot-time
parms, you find examples like this (from init/initramfs.c):

=====

static int __initdata do_retain_initrd;

static int __init retain_initrd_param(char *str)
{
        if (*str)
                return 0;
        do_retain_initrd = 1;
        return 1;
}
__setup("retain_initrd", retain_initrd_param);

=====

  i'm confused ... typically, the char* argument passed to the setup
routine is used to extract the value of the parameter, as in:

   ... myparmname=fred ...
                  ^^^^

but many of those parms *don't* take a value, you just say
"retain_initrd" and that's it.  and that's how the parm above is
explained in Documentation/kernel-parameters.txt:

  retain_initrd   [RAM] Keep initrd memory after extraction

so what's with the check of:

        if (*str)
                return 0;

if i'm reading this correctly, this is checking if a value has been
supplied and, if so, this variable will be set to false, no?  but
doesn't that mean that if someone does something (mistakenly) like:

   ... retain_initrd=yes

they'll get exactly the opposite effect of what they're after?  why
should that setup routine be checking the value of "str" at all?
shouldn't you instead be doing something like:

=====

static int __init retain_initrd_param(char *__unused)
{
        do_retain_initrd = 1;
        return 1;
}
__setup("retain_initrd", retain_initrd_param);

=====

  granted, as long as you always correctly use just "retain_initrd",
you'll be fine.  but if someone erroneously adds a value, that's
probably going to cause a problem.  or is there something else
happening here that i'm missing?  thanks.

rday
--

========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
========================================================================

--
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