diff options
author | Florin Malita <fmalita@gmail.com> | 2007-07-19 15:22:41 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2007-10-14 06:10:20 -0400 |
commit | dcec4c3bdc4d5f4bd2d858ee1ce11e3424cbaed7 (patch) | |
tree | 350dc84ecd5069e2cc69595482c0fb1ce72ab1e8 /drivers/mtd | |
parent | bbf25010f1a6b761914430f5fca081ec8c7accd1 (diff) |
UBI: fix leak in ubi_scan_erase_peb
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>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/ubi/scan.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 94ee54934411..80c73d88c83f 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -673,10 +673,6 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi, | |||
673 | int err; | 673 | int err; |
674 | struct ubi_ec_hdr *ec_hdr; | 674 | struct ubi_ec_hdr *ec_hdr; |
675 | 675 | ||
676 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | ||
677 | if (!ec_hdr) | ||
678 | return -ENOMEM; | ||
679 | |||
680 | if ((long long)ec >= UBI_MAX_ERASECOUNTER) { | 676 | if ((long long)ec >= UBI_MAX_ERASECOUNTER) { |
681 | /* | 677 | /* |
682 | * Erase counter overflow. Upgrade UBI and use 64-bit | 678 | * Erase counter overflow. Upgrade UBI and use 64-bit |
@@ -686,6 +682,10 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi, | |||
686 | return -EINVAL; | 682 | return -EINVAL; |
687 | } | 683 | } |
688 | 684 | ||
685 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | ||
686 | if (!ec_hdr) | ||
687 | return -ENOMEM; | ||
688 | |||
689 | ec_hdr->ec = cpu_to_be64(ec); | 689 | ec_hdr->ec = cpu_to_be64(ec); |
690 | 690 | ||
691 | err = ubi_io_sync_erase(ubi, pnum, 0); | 691 | err = ubi_io_sync_erase(ubi, pnum, 0); |