diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-03-14 11:09:40 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-03-16 07:50:16 -0400 |
commit | 332873d60b943c9bf53957c6e334038ac5e9dc6b (patch) | |
tree | f930b7e315d478901d567ec4057cc78e789d3e2c /drivers/mtd | |
parent | a75867432a7eb2cdcaa8613a3b72b1d0594dd930 (diff) |
UBI: allocate erase checking buffer on demand
Instead of using pre-allocated 'ubi->dbg_peb_buf' buffer in
'ubi_dbg_check_all_ff()', 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.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index b4d34ba60608..35da5aadbe10 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -1387,35 +1387,40 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | |||
1387 | { | 1387 | { |
1388 | size_t read; | 1388 | size_t read; |
1389 | int err; | 1389 | int err; |
1390 | void *buf; | ||
1390 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | 1391 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; |
1391 | 1392 | ||
1392 | mutex_lock(&ubi->dbg_buf_mutex); | 1393 | buf = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL); |
1393 | err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf); | 1394 | if (!buf) { |
1395 | ubi_err("cannot allocate memory to check for 0xFFs"); | ||
1396 | return 0; | ||
1397 | } | ||
1398 | |||
1399 | err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); | ||
1394 | if (err && err != -EUCLEAN) { | 1400 | if (err && err != -EUCLEAN) { |
1395 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | 1401 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " |
1396 | "read %zd bytes", err, len, pnum, offset, read); | 1402 | "read %zd bytes", err, len, pnum, offset, read); |
1397 | goto error; | 1403 | goto error; |
1398 | } | 1404 | } |
1399 | 1405 | ||
1400 | err = ubi_check_pattern(ubi->dbg_peb_buf, 0xFF, len); | 1406 | err = ubi_check_pattern(buf, 0xFF, len); |
1401 | if (err == 0) { | 1407 | if (err == 0) { |
1402 | ubi_err("flash region at PEB %d:%d, length %d does not " | 1408 | ubi_err("flash region at PEB %d:%d, length %d does not " |
1403 | "contain all 0xFF bytes", pnum, offset, len); | 1409 | "contain all 0xFF bytes", pnum, offset, len); |
1404 | goto fail; | 1410 | goto fail; |
1405 | } | 1411 | } |
1406 | mutex_unlock(&ubi->dbg_buf_mutex); | ||
1407 | 1412 | ||
1413 | vfree(buf); | ||
1408 | return 0; | 1414 | return 0; |
1409 | 1415 | ||
1410 | fail: | 1416 | fail: |
1411 | ubi_err("paranoid check failed for PEB %d", pnum); | 1417 | ubi_err("paranoid check failed for PEB %d", pnum); |
1412 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); | 1418 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); |
1413 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 1419 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); |
1414 | ubi->dbg_peb_buf, len, 1); | ||
1415 | err = -EINVAL; | 1420 | err = -EINVAL; |
1416 | error: | 1421 | error: |
1417 | ubi_dbg_dump_stack(); | 1422 | ubi_dbg_dump_stack(); |
1418 | mutex_unlock(&ubi->dbg_buf_mutex); | 1423 | vfree(buf); |
1419 | return err; | 1424 | return err; |
1420 | } | 1425 | } |
1421 | 1426 | ||