summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-03-14 17:06:52 +0200
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-03-16 13:50:16 +0200
commita75867432a7eb2cdcaa8613a3b72b1d0594dd930 (patch)
treef83b3760bf171a3402ff48616726c6c71d01df2c /drivers
parenta87f29cbbcbd5bd1e4990367cd18967e9bbeacff (diff)
UBI: allocate write checking buffer on demand
Instead of using pre-allocated 'ubi->dbg_peb_buf' buffer in 'ubi_dbg_check_write()', dynamically allocate it when needed. The intend is to get rid of the pre-allocated 'ubi->dbg_peb_buf' buffer completely. And the need for this arises because we want to change to dynamic debugging control instead of compile-time control, i.e., we are going to kill the CONFIG_MTD_UBI_DEBUG_PARANOID Kconfig option, which would mean that 'ubi->dbg_peb_buf' is always allocated, which would be wasteful. Thus, we are getting rid of 'ubi->dbg_peb_buf', and this is a preparation for that. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/ubi/io.c24
-rw-r--r--drivers/mtd/ubi/ubi.h1
2 files changed, 16 insertions, 9 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 889e25c49323..b4d34ba60608 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -1326,16 +1326,22 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
{
int err, i;
size_t read;
+ void *buf1;
loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
- mutex_lock(&ubi->dbg_buf_mutex);
- err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf);
+ buf1 = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
+ if (!buf1) {
+ ubi_err("cannot allocate memory to check writes");
+ return 0;
+ }
+
+ err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1);
if (err && err != -EUCLEAN)
- goto out_unlock;
+ goto out_free;
for (i = 0; i < len; i++) {
uint8_t c = ((uint8_t *)buf)[i];
- uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i];
+ uint8_t c1 = ((uint8_t *)buf1)[i];
int dump_len;
if (c == c1)
@@ -1352,17 +1358,17 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
ubi_msg("hex dump of the read buffer from %d to %d",
i, i + dump_len);
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
- ubi->dbg_peb_buf + i, dump_len, 1);
+ buf1 + i, dump_len, 1);
ubi_dbg_dump_stack();
err = -EINVAL;
- goto out_unlock;
+ goto out_free;
}
- mutex_unlock(&ubi->dbg_buf_mutex);
+ vfree(buf1);
return 0;
-out_unlock:
- mutex_unlock(&ubi->dbg_buf_mutex);
+out_free:
+ vfree(buf1);
return err;
}
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 0b0149c41fe3..9af362c2a137 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -40,6 +40,7 @@
#include <linux/notifier.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/ubi.h>
+#include <asm/pgtable.h>
#include "ubi-media.h"
#include "scan.h"