linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] UBI: Fix allocation of volume table
@ 2009-08-11  1:25 JiSheng Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: JiSheng Zhang @ 2009-08-11  1:25 UTC (permalink / raw)
  To: linux-mtd; +Cc: Artem.Bityutskiy, dwmw2, linux-kernel, rmk, adrian.hunter


We can't use vmalloc for the buffer used for volume table for some NAND
or NOR drivers may pass the buffer to DMA. And the volume table size
a.k.a vtbl_size is small so we can use kmalloc or kzalloc for it instead.

Signed-off-by: JiSheng Zhang <jszhang3@gmail.com>
---
 drivers/mtd/ubi/vtbl.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 1afc61e..9dcc7ba 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -424,12 +424,11 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
 
 	/* Read both LEB 0 and LEB 1 into memory */
 	ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) {
-		leb[seb->lnum] = vmalloc(ubi->vtbl_size);
+		leb[seb->lnum] = kzalloc(ubi->vtbl_size, GFP_KERNEL);
 		if (!leb[seb->lnum]) {
 			err = -ENOMEM;
 			goto out_free;
 		}
-		memset(leb[seb->lnum], 0, ubi->vtbl_size);
 
 		err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
 				       ubi->vtbl_size);
@@ -515,10 +514,9 @@ static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi,
 	int i;
 	struct ubi_vtbl_record *vtbl;
 
-	vtbl = vmalloc(ubi->vtbl_size);
+	vtbl = kzalloc(ubi->vtbl_size, GFP_KERNEL);
 	if (!vtbl)
 		return ERR_PTR(-ENOMEM);
-	memset(vtbl, 0, ubi->vtbl_size);
 
 	for (i = 0; i < ubi->vtbl_slots; i++)
 		memcpy(&vtbl[i], &empty_vtbl_record, UBI_VTBL_RECORD_SIZE);
-- 
1.6.3.3

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

* [PATCH] UBI: Fix allocation of volume table
@ 2009-08-11  1:44 JiSheng Zhang
  2009-08-14 16:05 ` Artem Bityutskiy
  0 siblings, 1 reply; 3+ messages in thread
From: JiSheng Zhang @ 2009-08-11  1:44 UTC (permalink / raw)
  To: linux-mtd; +Cc: Artem.Bityutskiy, dwmw2, linux-kernel, rmk, adrian.hunter


We can't use vmalloc for the buffer used for volume table for some NAND
or NOR drivers may pass the buffer to DMA. And the volume table size
a.k.a vtbl_size is small so we can use kmalloc or kzalloc for it instead

Signed-off-by: JiSheng Zhang <jszhang3@gmail.com>
---
 drivers/mtd/ubi/build.c |    6 +++---
 drivers/mtd/ubi/vtbl.c  |   18 ++++++++----------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index e1f7d0a..1c1f877 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -605,7 +605,7 @@ out_wl:
 	ubi_wl_close(ubi);
 out_vtbl:
 	free_internal_volumes(ubi);
-	vfree(ubi->vtbl);
+	kfree(ubi->vtbl);
 out_si:
 	ubi_scan_destroy_si(si);
 	return err;
@@ -1031,7 +1031,7 @@ out_detach:
 	if (do_free)
 		free_user_volumes(ubi);
 	free_internal_volumes(ubi);
-	vfree(ubi->vtbl);
+	kfree(ubi->vtbl);
 out_free:
 	vfree(ubi->peb_buf1);
 	vfree(ubi->peb_buf2);
@@ -1102,7 +1102,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
 	uif_close(ubi);
 	ubi_wl_close(ubi);
 	free_internal_volumes(ubi);
-	vfree(ubi->vtbl);
+	kfree(ubi->vtbl);
 	put_mtd_device(ubi->mtd);
 	vfree(ubi->peb_buf1);
 	vfree(ubi->peb_buf2);
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 1afc61e..59e452a 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -424,12 +424,11 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
 
 	/* Read both LEB 0 and LEB 1 into memory */
 	ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) {
-		leb[seb->lnum] = vmalloc(ubi->vtbl_size);
+		leb[seb->lnum] = kzalloc(ubi->vtbl_size, GFP_KERNEL);
 		if (!leb[seb->lnum]) {
 			err = -ENOMEM;
 			goto out_free;
 		}
-		memset(leb[seb->lnum], 0, ubi->vtbl_size);
 
 		err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
 				       ubi->vtbl_size);
@@ -470,7 +469,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
 		}
 
 		/* Both LEB 1 and LEB 2 are OK and consistent */
-		vfree(leb[1]);
+		kfree(leb[1]);
 		return leb[0];
 	} else {
 		/* LEB 0 is corrupted or does not exist */
@@ -491,13 +490,13 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
 			goto out_free;
 		ubi_msg("volume table was restored");
 
-		vfree(leb[0]);
+		kfree(leb[0]);
 		return leb[1];
 	}
 
 out_free:
-	vfree(leb[0]);
-	vfree(leb[1]);
+	kfree(leb[0]);
+	kfree(leb[1]);
 	return ERR_PTR(err);
 }
 
@@ -515,10 +514,9 @@ static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi,
 	int i;
 	struct ubi_vtbl_record *vtbl;
 
-	vtbl = vmalloc(ubi->vtbl_size);
+	vtbl = kzalloc(ubi->vtbl_size, GFP_KERNEL);
 	if (!vtbl)
 		return ERR_PTR(-ENOMEM);
-	memset(vtbl, 0, ubi->vtbl_size);
 
 	for (i = 0; i < ubi->vtbl_slots; i++)
 		memcpy(&vtbl[i], &empty_vtbl_record, UBI_VTBL_RECORD_SIZE);
@@ -528,7 +526,7 @@ static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi,
 
 		err = create_vtbl(ubi, si, i, vtbl);
 		if (err) {
-			vfree(vtbl);
+			kfree(vtbl);
 			return ERR_PTR(err);
 		}
 	}
@@ -856,7 +854,7 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si)
 	return 0;
 
 out_free:
-	vfree(ubi->vtbl);
+	kfree(ubi->vtbl);
 	for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
 		kfree(ubi->volumes[i]);
 		ubi->volumes[i] = NULL;
-- 
1.6.3.3

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

* Re: [PATCH] UBI: Fix allocation of volume table
  2009-08-11  1:44 JiSheng Zhang
@ 2009-08-14 16:05 ` Artem Bityutskiy
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2009-08-14 16:05 UTC (permalink / raw)
  To: JiSheng Zhang
  Cc: Artem.Bityutskiy, linux-kernel, linux-mtd, dwmw2, rmk,
	adrian.hunter

On 08/11/2009 04:44 AM, JiSheng Zhang wrote:
> We can't use vmalloc for the buffer used for volume table for some NAND
> or NOR drivers may pass the buffer to DMA. And the volume table size
> a.k.a vtbl_size is small so we can use kmalloc or kzalloc for it instead
>
> Signed-off-by: JiSheng Zhang<jszhang3@gmail.com>

I do not have objections if this patch becomes a member of a series of
patches which kick vmalloc from whole UBI. Applying just this patch does
not make much sense.

You may go through UBI code and try to split large vmalloc-ed buffers on
smaller kmalloc-ed ones.

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

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

end of thread, other threads:[~2009-08-14 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-11  1:25 [PATCH] UBI: Fix allocation of volume table JiSheng Zhang
  -- strict thread matches above, loose matches on Subject: below --
2009-08-11  1:44 JiSheng Zhang
2009-08-14 16:05 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).