On Mon, 21 Nov 2011 14:44:48 +0000, Pawel Moll <pawel.moll@xxxxxxx> 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@%llu[KMG]:%u", ...) != 3 && sscanf(device, "%llu@%llu[KMG]:%u:%u", ...) != 4) return -EINVAL; Cheers, Rusty. _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization