mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Giorgio <giorgio.nicole@arcor.de>
To: barebox@lists.infradead.org
Subject: wrong count argument to erase()
Date: Sat, 16 Apr 2016 21:15:04 +0200	[thread overview]
Message-ID: <76f44565-7af7-107a-5b0e-acda33ac5321@arcor.de> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 1110 bytes --]

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


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 246 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2016-04-16 19:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-16 19:15 Giorgio [this message]
2016-04-18 10:21 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76f44565-7af7-107a-5b0e-acda33ac5321@arcor.de \
    --to=giorgio.nicole@arcor.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox