Re: [RFC] [Patch 2/8] statistics infrastructure - prerequisite:parser enhancement

From: Martin Peschke
Date: Wed May 17 2006 - 08:54:10 EST


On Tue, 2006-05-16 at 11:11 -0700, Andrew Morton wrote:
> Your email client does space-stuffing, so this won't apply (ok, it might
> apply if my email client knew how to space-unstuff, but it doesn't).

Okay, I got rid of my email client's space-stuffing (and of my former
email client, for that matter). I will resend my patches.

> > diff -Nurp a/lib/parser.c b/lib/parser.c
> > --- a/lib/parser.c 2006-03-20 06:53:29.000000000 +0100
> > +++ b/lib/parser.c 2006-05-15 17:56:25.000000000 +0200
> > @@ -140,6 +140,64 @@ static int match_number(substring_t *s,
> > }
> >
> > /**
> > + * match_u64: scan a number in the given base from a substring_t
> > + * @s: substring to be scanned
> > + * @result: resulting integer on success
> > + * @base: base to use when converting string
> > + *
> > + * Description: Given a &substring_t and a base, attempts to parse the substring
> > + * as a number in that base. On success, sets @result to the u64 represented
> > + * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
> > + */
> > +int match_u64(substring_t *s, u64 *result, int base)
> > +{
> > + char *endp;
> > + char *buf;
> > + int ret;
> > +
> > + buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
> > + if (!buf)
> > + return -ENOMEM;
> > + memcpy(buf, s->from, s->to - s->from);
> > + buf[s->to - s->from] = '\0';
> > + *result = simple_strtoull(buf, &endp, base);
> > + ret = 0;
> > + if (endp == buf)
> > + ret = -EINVAL;
> > + kfree(buf);
> > + return ret;
> > +}
> > +
> > +/**
> > + * match_s64: scan a number in the given base from a substring_t
> > + * @s: substring to be scanned
> > + * @result: resulting integer on success
> > + * @base: base to use when converting string
> > + *
> > + * Description: Given a &substring_t and a base, attempts to parse the substring
> > + * as a number in that base. On success, sets @result to the s64 represented
> > + * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
> > + */
> > +int match_s64(substring_t *s, s64 *result, int base)
> > +{
> > + char *endp;
> > + char *buf;
> > + int ret;
> > +
> > + buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
> > + if (!buf)
> > + return -ENOMEM;
> > + memcpy(buf, s->from, s->to - s->from);
> > + buf[s->to - s->from] = '\0';
> > + *result = simple_strtoll(buf, &endp, base);
> > + ret = 0;
> > + if (endp == buf)
> > + ret = -EINVAL;
> > + kfree(buf);
> > + return ret;
> > +}
>
> These are identical. If we _really_ need one for signed and one for
> unsigned then we could at least do

I am going to remove match_u64. My code doesn't use it anymore.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/