[PATCH] mtd-utils: lib: mtd_read: Take the buffer offset into account when reading

Marcus Prebble marcus.prebble at axis.com
Fri Nov 13 02:07:12 PST 2015


Hi Brian,

Thanks for looking at the patch!


On Thu, 2015-11-12 at 11:09 -0800, Brian Norris wrote:
> Hi Marcus,
> 
> On Tue, Oct 06, 2015 at 02:13:23PM +0200, Marcus Prebble wrote:
> > Hi mtd-list,

> ...the current implementation will overwrite the data already
> > read in buf which doesn't seem correct.
> 
> In addition, this means we might not actually fill up the entire buffer,
> since 2 or more short read()'s might get us to exit the loop with a
> cumulative value in 'rd', but only a partially-filled buffer. That could
> cause a user to try and handle garbage/uninitialized data.

Yes, that is definitely possible and not nice for the user.

> Patch looks OK. Did you test it? Have you seen MTD drivers that will
> return short reads?

I only noticed in passing, not because I was hit by the error. I smoke
tested it, but did not hack a driver to return less than len.
If I had to guess, I would say that in nearly all cases the drivers do
not return short reads otherwise this would probably have been picked up
by now. 

> 
> Brian



More information about the linux-mtd mailing list