]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
UBI: fix leak in ubi_scan_erase_peb
authorFlorin Malita <fmalita@gmail.com>
Thu, 19 Jul 2007 19:22:41 +0000 (15:22 -0400)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sun, 14 Oct 2007 10:10:20 +0000 (13:10 +0300)
Coverity (1769) found the following problem: if the erase counter
overflow check triggers, ec_hdr is leaked.

Moving the allocation after the overflow check should take care of it.

Signed-off-by: Florin Malita <fmalita@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
drivers/mtd/ubi/scan.c

index 94ee549344118987e2e2a73ded2c13fc00a1f2f0..80c73d88c83f9e2ca7e717312e1165921ad3d037 100644 (file)
@@ -673,10 +673,6 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
        int err;
        struct ubi_ec_hdr *ec_hdr;
 
-       ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
-       if (!ec_hdr)
-               return -ENOMEM;
-
        if ((long long)ec >= UBI_MAX_ERASECOUNTER) {
                /*
                 * Erase counter overflow. Upgrade UBI and use 64-bit
@@ -686,6 +682,10 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi,
                return -EINVAL;
        }
 
+       ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
+       if (!ec_hdr)
+               return -ENOMEM;
+
        ec_hdr->ec = cpu_to_be64(ec);
 
        err = ubi_io_sync_erase(ubi, pnum, 0);