public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] UBI: potential leak in ubi_scan_erase_peb
@ 2007-07-19 19:22 Florin Malita
  2007-07-20  7:25 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Florin Malita @ 2007-07-19 19:22 UTC (permalink / raw)
  To: dedekind; +Cc: linux-mtd, Linux Kernel Mailing List

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>
---

 drivers/mtd/ubi/scan.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 94ee549..80c73d8 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,
 	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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] UBI: potential leak in ubi_scan_erase_peb
  2007-07-19 19:22 [PATCH] UBI: potential leak in ubi_scan_erase_peb Florin Malita
@ 2007-07-20  7:25 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2007-07-20  7:25 UTC (permalink / raw)
  To: Florin Malita; +Cc: linux-mtd, Linux Kernel Mailing List

On Thu, 2007-07-19 at 15:22 -0400, Florin Malita wrote:
> 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>

Committed, thank you!

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-07-20  7:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-19 19:22 [PATCH] UBI: potential leak in ubi_scan_erase_peb Florin Malita
2007-07-20  7:25 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox