From: Artem Bityutskiy <dedekind1@gmail.com>
To: h-fache@ti.com
Cc: joern@lazybastard.org, joern@logfs.org, linux-mtd@lists.infradead.org
Subject: Re: [PATCH] phram: make kernel boot command line arguments work
Date: Sat, 29 Oct 2011 23:09:46 +0300 [thread overview]
Message-ID: <1319918989.2126.13.camel@koala> (raw)
In-Reply-To: <1318866038-11781-1-git-send-email-h-fache@ti.com>
On Mon, 2011-10-17 at 17:40 +0200, h-fache@ti.com wrote:
> diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
> index 23423bd..6d58bf0 100644
> --- a/drivers/mtd/devices/phram.c
> +++ b/drivers/mtd/devices/phram.c
> @@ -233,7 +233,10 @@ static inline void kill_final_newline(char *str)
> return 1; \
> } while (0)
>
> -static int phram_setup(const char *val, struct kernel_param *kp)
> +static int phram_init_called;
You should not need this variable. I think it should work this way:
1. You declare the phram_setup param_call.
2. This function will be called before 'init_phram()' in both cases -
module and compiled-in.
3. pram_setup should parse the parameters and save them in a temporary
data structure marked as __initdata. In your case it is
'phram_paramline'.
4. The 'init_phram()' parses that temporary data structure for real.
> +static __initdata char phram_paramline[64+12+12];
Please, add comment about 64 and 12.
> +
> +static int phram_setup2(const char *val)
> {
> char buf[64+12+12], *str = buf;
> char *token[3];
> @@ -282,13 +285,41 @@ static int phram_setup(const char *val, struct kernel_param *kp)
> return ret;
> }
>
> +static int phram_setup(const char *val, struct kernel_param *kp)
> +{
> + /* If more parameters are later passed in via
> + /sys/module/phram/parameters/phram
> + and init_phram() has already been called,
> + we can parse the argument directly. */
> +
> + if (phram_init_called)
> + return phram_setup2(val);
This if should not be needed - I think this function is called before
'init_phram()' always. So this check should be always false.
> +
> + /* During early boot stage, we only save the parameters
> + here. We must parse them later: if the param passed
> + from kernel boot command line, phram_setup() is
> + called so early that it is not possible to resolve
> + the device (kmalloc() fails). Defer that work to
> + phram_setup2(), called by init_phram(). */
> +
> + strlcpy(phram_paramline, val, sizeof(phram_paramline));
No please, do not silently truncate possibly longer command line. Do
proper strlen here and if it is longer than you array - return an error.
> +
> + return 0;
> +}
> +
> module_param_call(phram, phram_setup, NULL, NULL, 000);
> MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>\"");
>
>
> static int __init init_phram(void)
> {
> - return 0;
> + int ret = 0;
> +
> + if (strlen(phram_paramline))
> + ret = phram_setup2(phram_paramline);
Well, matter of taste, but I think strlen is too much for this, I'd use
if (*phram_paramline) or if (phram_paramline[0]) ...
> + phram_init_called = 1;
> +
> + return ret;
> }
>
> static void __exit cleanup_phram(void)
prev parent reply other threads:[~2011-10-29 20:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-17 15:40 [PATCH] phram: make kernel boot command line arguments work h-fache
2011-10-18 0:32 ` Jörn Engel
2011-10-18 8:05 ` Fache, Herve
2011-10-20 16:34 ` Artem Bityutskiy
2011-10-20 16:16 ` Artem Bityutskiy
2011-10-21 8:51 ` Fache, Herve
2011-10-25 7:37 ` Artem Bityutskiy
2011-10-25 9:09 ` Fache, Herve
2011-10-25 19:58 ` Jörn Engel
2011-10-29 20:10 ` Artem Bityutskiy
2011-10-20 16:20 ` Artem Bityutskiy
2011-10-21 8:49 ` Fache, Herve
2011-10-25 7:32 ` Artem Bityutskiy
2011-10-25 9:07 ` Fache, Herve
2011-10-29 20:09 ` Artem Bityutskiy [this message]
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=1319918989.2126.13.camel@koala \
--to=dedekind1@gmail.com \
--cc=h-fache@ti.com \
--cc=joern@lazybastard.org \
--cc=joern@logfs.org \
--cc=linux-mtd@lists.infradead.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