aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-03-14 11:06:52 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-03-16 07:50:16 -0400
commita75867432a7eb2cdcaa8613a3b72b1d0594dd930 (patch)
treef83b3760bf171a3402ff48616726c6c71d01df2c /drivers/mtd
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/mtd')
-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,
1326{ 1326{
1327 int err, i; 1327 int err, i;
1328 size_t read; 1328 size_t read;
1329 void *buf1;
1329 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; 1330 loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
1330 1331
1331 mutex_lock(&ubi->dbg_buf_mutex); 1332 buf1 = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
1332 err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf); 1333 if (!buf1) {
1334 ubi_err("cannot allocate memory to check writes");
1335 return 0;
1336 }
1337
1338 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1);
1333 if (err && err != -EUCLEAN) 1339 if (err && err != -EUCLEAN)
1334 goto out_unlock; 1340 goto out_free;
1335 1341
1336 for (i = 0; i < len; i++) { 1342 for (i = 0; i < len; i++) {
1337 uint8_t c = ((uint8_t *)buf)[i]; 1343 uint8_t c = ((uint8_t *)buf)[i];
1338 uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i]; 1344 uint8_t c1 = ((uint8_t *)buf1)[i];
1339 int dump_len; 1345 int dump_len;
1340 1346
1341 if (c == c1) 1347 if (c == c1)
@@ -1352,17 +1358,17 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1352 ubi_msg("hex dump of the read buffer from %d to %d", 1358 ubi_msg("hex dump of the read buffer from %d to %d",
1353 i, i + dump_len); 1359 i, i + dump_len);
1354 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1360 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1355 ubi->dbg_peb_buf + i, dump_len, 1); 1361 buf1 + i, dump_len, 1);
1356 ubi_dbg_dump_stack(); 1362 ubi_dbg_dump_stack();
1357 err = -EINVAL; 1363 err = -EINVAL;
1358 goto out_unlock; 1364 goto out_free;
1359 } 1365 }
1360 mutex_unlock(&ubi->dbg_buf_mutex);
1361 1366
1367 vfree(buf1);
1362 return 0; 1368 return 0;
1363 1369
1364out_unlock: 1370out_free:
1365 mutex_unlock(&ubi->dbg_buf_mutex); 1371 vfree(buf1);
1366 return err; 1372 return err;
1367} 1373}
1368 1374
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 @@
40#include <linux/notifier.h> 40#include <linux/notifier.h>
41#include <linux/mtd/mtd.h> 41#include <linux/mtd/mtd.h>
42#include <linux/mtd/ubi.h> 42#include <linux/mtd/ubi.h>
43#include <asm/pgtable.h>
43 44
44#include "ubi-media.h" 45#include "ubi-media.h"
45#include "scan.h" 46#include "scan.h"