Messages in this thread | | | From | Rasmus Villemoes <> | Subject | Re: [PATCH 1/2] regmap: debugfs: remove bogus check | Date | Wed, 30 Sep 2015 09:27:38 +0200 |
| |
On Tue, Sep 29 2015, Mark Brown <broonie@kernel.org> wrote:
> On Tue, Sep 29, 2015 at 12:29:01AM +0200, Rasmus Villemoes wrote: >> snprintf cannot return a negative value (unless map->dev->driver->name >> happens to be over 2G long). So remove the bogus check. > >> ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name); >> - if (ret < 0) { >> - kfree(buf); >> - return ret; >> - } > > It's hard to see a great value in removing error checking, even error > checking that's currently unlikely to ever trigger...
I agree, but only on the word 'great'. There is value in removing such bogosities (or rather, their presence provides negative value). It makes the code harder to read ("why is this instance checked, but not any of the other snprintfs?"); people may think that it's trying to check for truncation, but it does no such thing; and it contributes a few worthless bytes to .text (and the source).
If you're worried about map->dev->driver->name actually ever being > 2G, returning some almost totally random negative number isn't really helpful (the function is supposed to return a -errno). And what makes you think that in some hypothetical universe where the kernel's snprintf explicit returns a negative value that it wouldn't just return -1 (aka -EPERM)?
BTW, if it's the truncation thing this was supposed to check for and there was any non-zero chance map->dev->driver->name would be longer than around PAGE_SIZE, this would be an excellent info leak: ret is some fine positive number somewhat larger than PAGE_SIZE, and we go on to use that to determine how much to copy to the user.
Rasmus
| |