From: Dan Carpenter <dan.carpenter@oracle.com>
To: Artem Bityutskiy <dedekind1@gmail.com>
Cc: linux-mtd@lists.infradead.org
Subject: [bug reportish] UBI_MAX_ERASECOUNTER not used consistently
Date: Fri, 5 Oct 2012 09:57:04 +0300 [thread overview]
Message-ID: <20121005065704.GA26466@elgon.mountain> (raw)
Hi Artem,
I normally audit for underflows and I had a question about this code.
mtd/ubi/attach.c
665 static int early_erase_peb(struct ubi_device *ubi,
666 const struct ubi_attach_info *ai, int pnum, int ec)
667 {
668 int err;
669 struct ubi_ec_hdr *ec_hdr;
670
671 if ((long long)ec >= UBI_MAX_ERASECOUNTER) {
Casting to long long doesn't serve any purpose. We normally say that
"> UBI_MAX_ERASECOUNTER" is invalid but "== UBI_MAX_ERASECOUNTER" is Ok.
The "ec" variable is signed and negative values are missed on this
check.
672 /*
673 * Erase counter overflow. Upgrade UBI and use 64-bit
674 * erase counters internally.
675 */
676 ubi_err("erase counter overflow at PEB %d, EC %d", pnum, ec);
677 return -EINVAL;
678 }
679
680 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
regards,
dan carpenter
next reply other threads:[~2012-10-05 6:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-05 6:57 Dan Carpenter [this message]
2012-10-11 14:33 ` [bug reportish] UBI_MAX_ERASECOUNTER not used consistently Artem Bityutskiy
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=20121005065704.GA26466@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@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