From: Rusty Russell <rusty@rustcorp.com.au>
To: Pawel Moll <pawel.moll@arm.com>
Cc: "linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"virtualization\@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>
Subject: Re: [PATCH] virtio-mmio: Devices parameter parsing
Date: Mon, 28 Nov 2011 11:01:30 +1030 [thread overview]
Message-ID: <87zkfht7dp.fsf@rustcorp.com.au> (raw)
In-Reply-To: <1322071732.3093.491.camel@hornet.cambridge.arm.com>
On Wed, 23 Nov 2011 18:08:52 +0000, Pawel Moll <pawel.moll@arm.com> wrote:
> On Tue, 2011-11-22 at 00:44 +0000, Rusty Russell wrote:
> > Or would it be simpler to enhance sscanf() with some weird format option
> > for suffixing? I haven't looked for similar cases, but I'd suspect a
> > big win in general.
> >
> > This would be neater than anything else we've got:
> > if (sscanf(device, "%llu@%llu[KMG]:%u", ...) != 3
> > && sscanf(device, "%llu@%llu[KMG]:%u:%u", ...) != 4)
> > return -EINVAL;
>
> sscanf was a good hint! Thanks, why haven't I thought of it myself? ;-)
>
> That's what I came up with:
>
> static int vm_cmdline_set(const char *device,
> const struct kernel_param *kp)
> {
> struct resource resources[2] = {};
> char *str;
> long long int base;
> int processed, consumed = 0;
> struct platform_device *pdev;
>
> resources[0].flags = IORESOURCE_MEM;
> resources[1].flags = IORESOURCE_IRQ;
>
> resources[0].end = memparse(device, &str) - 1;
>
> processed = sscanf(str, "@%lli:%u%n:%d%n",
> &base, &resources[1].start, &consumed,
> &vm_cmdline_id, &consumed);
>
> if (processed < 2 || processed > 3 || str[consumed])
> return -EINVAL;
>
> resources[0].start = base;
> resources[0].end += base;
> resources[1].end = resources[1].start;
>
> The only bit missing from sscanf() would be some sort of "%m" format,
> which behaved like memparse and also processed unsigned number with "0
> base" (hard to believe but the only "universal" - as in octal, dec and
> hex - format is %i, which is signed). But still, looks quite neat
> already :-)
Yeah, something like %pK for kernel pointers in printk; you need a
suffix so that gcc won't get upset. The "[KMG]" suffix hack was my
poor suggestion...
> I'll try to have a look at the "late parameters" idea tomorrow. Any
> early warnings?
Off the top of my head, this makes me think of the way initcalls are
ordered. We could put a parameter parsing initcall at the start of each
initcall level in include/asm-generic/vmlinux.lds.h's INITCALLS macro.
Then we steal four bits from struct kernel_param's flags to indicate the
level of the initcall (-1 == existing ones, otherwise N == before level
N initcalls).
Good luck!
Rusty.
next prev parent reply other threads:[~2011-11-28 3:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-15 13:53 Pawel Moll
2011-11-16 0:42 ` Rusty Russell
2011-11-16 18:13 ` Pawel Moll
2011-11-17 12:42 ` [PATCH v2] " Pawel Moll
2011-11-21 3:32 ` [PATCH] " Rusty Russell
2011-11-21 14:44 ` Pawel Moll
2011-11-21 17:56 ` Pawel Moll
2011-11-22 0:53 ` Rusty Russell
2011-11-23 18:08 ` Pawel Moll
2011-11-28 0:31 ` Rusty Russell [this message]
2011-11-29 17:36 ` Pawel Moll
2011-12-01 2:06 ` Rusty Russell
2011-12-12 17:53 ` Pawel Moll
2011-12-12 17:57 ` [PATCH 1/2] params: <level>_initcall-like kernel parameters Pawel Moll
2011-12-12 17:57 ` [PATCH 2/2] virtio-mmio: Devices parameter parsing Pawel Moll
2012-04-09 16:32 ` Sasha Levin
2012-04-10 12:53 ` Pawel Moll
2011-12-15 3:51 ` [PATCH 1/2] params: <level>_initcall-like kernel parameters Rusty Russell
2011-12-15 9:38 ` Pawel Moll
2011-11-22 0:44 ` [PATCH] virtio-mmio: Devices parameter parsing Rusty Russell
2012-05-09 17:30 Pawel Moll
2012-05-10 0:44 ` Rusty Russell
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=87zkfht7dp.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=pawel.moll@arm.com \
--cc=virtualization@lists.linux-foundation.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
Powered by JetHome