wrong count argument to erase()

Giorgio giorgio.nicole at arcor.de
Sat Apr 16 12:15:04 PDT 2016


Hi,

I'm using barebox on an embedded system with an imx6 cpu, a nor and
a nand flash.

I recently updated the barebox to v2016.04.0 and noticed that the
command 'saveenv' was surprisingly quick and actually didn't work.

After a bit of debugging I could track the problem down to a call to the
function erase() within 'common/environment.c':

int envfs_save(const char *filename, const char *dirname, unsigned flags)
{
...
	ret = erase(envfd, ~0, 0);

	/* ENOSYS and EOPNOTSUPP aren't errors here, many devices don't need it */
	if (ret && errno != ENOSYS && errno != EOPNOTSUPP) {
		printf("could not erase %s: %s\n", filename, errno_str());
		goto out;
	}
...

The function prototype is:

int erase(int fd, loff_t count, loff_t offset)

in particular the second argument, count, is a signed long long.

Now when calling erase() with a count of ~0 the function will cast it
to -1 instead of to a 'very big' number and actually never erase
anything.

I think in these cases it is better to use cpp macros like LLONG_MAX
or change the type of count to a size_t.

giorgio

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 246 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20160416/cd59440d/attachment.sig>


More information about the barebox mailing list