Re: [PATCH] leds: Avoid needless strlen() for attributes

From: Sven Wegener
Date: Fri Aug 01 2008 - 16:55:42 EST


On Fri, 1 Aug 2008, Ray Lee wrote:

> On Fri, Aug 1, 2008 at 1:30 PM, Sven Wegener <sven.wegener@xxxxxxxxxxx> wrote:
> > There's no need for the additional call to strlen(), we can directly return the
> > value returned by sprintf(). We now return a length value that doesn't include
> > the final '\0', but user space shouldn't bother about it anyway.
>
> Why not just add 1 to the return value of sprintf, and guarantee that
> userspace sees the same thing before and after? It's simple enough to
> do, and avoids guessing about what userspace may or may not be doing.

I thought about it, but all other places I looked at just do the return
sprintf(...); thing, so we are consistent with what the other drivers do.
And user space should be really ignoring the final '\0' currently. I know
that this can be considered some user space API change, but I think it is
in the range of what the API allows us. If noone has strong objections
against leaving the -1 out, I would keep it that way. But it's OK for me,
if someone really wants it there, but I don't think it's necessary.

Sven
--
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/