public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [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

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