[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87ipmdx9y5.fsf@rustcorp.com.au>
Date: Tue, 22 Nov 2011 11:14:18 +1030
From: Rusty Russell <rusty@...tcorp.com.au>
To: Pawel Moll <pawel.moll@....com>
Cc: "linux-kernel\@vger.kernel.org" <linux-kernel@...r.kernel.org>,
"virtualization\@lists.linux-foundation.org"
<virtualization@...ts.linux-foundation.org>,
Sasha Levin <levinsasha928@...il.com>,
Peter Maydell <peter.maydell@...aro.org>
Subject: Re: [PATCH] virtio-mmio: Devices parameter parsing
On Mon, 21 Nov 2011 14:44:48 +0000, Pawel Moll <pawel.moll@....com> wrote:
> On Mon, 2011-11-21 at 03:32 +0000, Rusty Russell wrote:
> > 2) Doesn't leak mem on error paths.
>
> Em, I don't think my code was leaking memory in any error case? (no
> offence meant or taken ;-)
You're right, I'm wrong. In your original version, your innovative use
of free() then strdup() worked as intended.
> > 3) Handles error from platform_device_register_resndata().
>
> As my code was ignoring wrong descriptions (all the continues) I ignored
> this result as well (the implementation complains on its own anyway),
> but I get your point.
I was referring to this:
return platform_device_register_resndata(&virtio_mmio_cmdline_parent,
"virtio-mmio", virtio_mmio_cmdline_id++,
resources, ARRAY_SIZE(resources), NULL, 0) != NULL;
The set function returns 0 or a -ve errno, not true/false.
> > 4) Uses shorter names for static functions/variables.
>
> Ah, I get the hint :-) I'm trying to keep the naming convention in
> static symbols as well, as it makes cscope/ctags/grep usage easier...
> I'll just use the abbreviated "vm_" prefixes then.
>
> > See what you think...
>
> Funnily enough when I proposed some string parser few years ago (totally
> different story) I was flamed for using strchr() instead of strsep() ;-)
> But ok, I don't mind getting back to basics.
>
> > +static int set_cmdline_device(const char *device, const struct kernel_param *kp)
> [...]
> > + delim = strchr(device, '@');
> [...]
> > + *delim = '\0';
>
> Ah. I forgot that strchr() takes const char * but returns "non-const"
> char *... Cheating, that's what it is ;-), but will work. Probably what
> we really want is something like
> kstrtoull_delim(device, 0, &val, "@\0")
> I'll have a look and may try to propose something of that sort, but
> that's another story. Maybe I should just use simple_strtol() for the
> time being?
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@...u[KMG]:%u", ...) != 3
&& sscanf(device, "%llu@...u[KMG]:%u:%u", ...) != 4)
return -EINVAL;
Cheers,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists