* [bug reportish] UBI_MAX_ERASECOUNTER not used consistently
@ 2012-10-05 6:57 Dan Carpenter
2012-10-11 14:33 ` Artem Bityutskiy
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-10-05 6:57 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [bug reportish] UBI_MAX_ERASECOUNTER not used consistently
2012-10-05 6:57 [bug reportish] UBI_MAX_ERASECOUNTER not used consistently Dan Carpenter
@ 2012-10-11 14:33 ` Artem Bityutskiy
0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2012-10-11 14:33 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 981 bytes --]
On Fri, 2012-10-05 at 09:57 +0300, Dan Carpenter wrote:
> 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.
Yes, the cast is bogus. I can fix it by removing the cast, but would
like to give you a chance to send the patch so that you get the credit
being the author in the git history. Let me know what you prefer.
Thanks!
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-11 14:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-05 6:57 [bug reportish] UBI_MAX_ERASECOUNTER not used consistently Dan Carpenter
2012-10-11 14:33 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox