diff options
author | Richard Weinberger <richard@nod.at> | 2014-10-06 08:47:51 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2015-03-26 17:17:47 -0400 |
commit | c4ca6be9d67eaf5a53054903530c8f422b4b88bd (patch) | |
tree | 70f4e66f64464cc208ac09bc19c4906db3072b77 /drivers/mtd | |
parent | 6830356466a57db21c7bc31bf3be4e61189e145b (diff) |
UBI: Fastmap: Don't allocate new ubi_wl_entry objects
There is no need to allocate new ones every time, we can reuse
the existing ones.
This makes the code cleaner and more easy to follow.
Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Tanya Brokhman <tlinder@codeaurora.org>
Reviewed-by: Guido MartÃnez <guido@vanguardiasur.com.ar>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/ubi/fastmap.c | 31 | ||||
-rw-r--r-- | drivers/mtd/ubi/wl.c | 3 |
2 files changed, 5 insertions, 29 deletions
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index db3defdfc3c0..95077026ad53 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c | |||
@@ -1446,19 +1446,6 @@ int ubi_update_fastmap(struct ubi_device *ubi) | |||
1446 | } | 1446 | } |
1447 | 1447 | ||
1448 | new_fm->used_blocks = ubi->fm_size / ubi->leb_size; | 1448 | new_fm->used_blocks = ubi->fm_size / ubi->leb_size; |
1449 | |||
1450 | for (i = 0; i < new_fm->used_blocks; i++) { | ||
1451 | new_fm->e[i] = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); | ||
1452 | if (!new_fm->e[i]) { | ||
1453 | while (i--) | ||
1454 | kfree(new_fm->e[i]); | ||
1455 | |||
1456 | kfree(new_fm); | ||
1457 | mutex_unlock(&ubi->fm_mutex); | ||
1458 | return -ENOMEM; | ||
1459 | } | ||
1460 | } | ||
1461 | |||
1462 | old_fm = ubi->fm; | 1449 | old_fm = ubi->fm; |
1463 | ubi->fm = NULL; | 1450 | ubi->fm = NULL; |
1464 | 1451 | ||
@@ -1494,12 +1481,9 @@ int ubi_update_fastmap(struct ubi_device *ubi) | |||
1494 | ubi_err(ubi, "could not erase old fastmap PEB"); | 1481 | ubi_err(ubi, "could not erase old fastmap PEB"); |
1495 | goto err; | 1482 | goto err; |
1496 | } | 1483 | } |
1497 | 1484 | new_fm->e[i] = old_fm->e[i]; | |
1498 | new_fm->e[i]->pnum = old_fm->e[i]->pnum; | ||
1499 | new_fm->e[i]->ec = old_fm->e[i]->ec; | ||
1500 | } else { | 1485 | } else { |
1501 | new_fm->e[i]->pnum = tmp_e->pnum; | 1486 | new_fm->e[i] = tmp_e; |
1502 | new_fm->e[i]->ec = tmp_e->ec; | ||
1503 | 1487 | ||
1504 | if (old_fm) | 1488 | if (old_fm) |
1505 | ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, | 1489 | ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, |
@@ -1524,16 +1508,13 @@ int ubi_update_fastmap(struct ubi_device *ubi) | |||
1524 | i, 0); | 1508 | i, 0); |
1525 | goto err; | 1509 | goto err; |
1526 | } | 1510 | } |
1527 | 1511 | new_fm->e[0] = old_fm->e[0]; | |
1528 | new_fm->e[0]->pnum = old_fm->e[0]->pnum; | ||
1529 | new_fm->e[0]->ec = ret; | 1512 | new_fm->e[0]->ec = ret; |
1530 | } else { | 1513 | } else { |
1531 | /* we've got a new anchor PEB, return the old one */ | 1514 | /* we've got a new anchor PEB, return the old one */ |
1532 | ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0, | 1515 | ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0, |
1533 | old_fm->to_be_tortured[0]); | 1516 | old_fm->to_be_tortured[0]); |
1534 | 1517 | new_fm->e[0] = tmp_e; | |
1535 | new_fm->e[0]->pnum = tmp_e->pnum; | ||
1536 | new_fm->e[0]->ec = tmp_e->ec; | ||
1537 | } | 1518 | } |
1538 | } else { | 1519 | } else { |
1539 | if (!tmp_e) { | 1520 | if (!tmp_e) { |
@@ -1546,9 +1527,7 @@ int ubi_update_fastmap(struct ubi_device *ubi) | |||
1546 | ret = -ENOSPC; | 1527 | ret = -ENOSPC; |
1547 | goto err; | 1528 | goto err; |
1548 | } | 1529 | } |
1549 | 1530 | new_fm->e[0] = tmp_e; | |
1550 | new_fm->e[0]->pnum = tmp_e->pnum; | ||
1551 | new_fm->e[0]->ec = tmp_e->ec; | ||
1552 | } | 1531 | } |
1553 | 1532 | ||
1554 | down_write(&ubi->work_sem); | 1533 | down_write(&ubi->work_sem); |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 227ca641f700..34a8ec44cc59 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -1011,9 +1011,6 @@ int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e, | |||
1011 | e = fm_e; | 1011 | e = fm_e; |
1012 | ubi_assert(e->ec >= 0); | 1012 | ubi_assert(e->ec >= 0); |
1013 | ubi->lookuptbl[pnum] = e; | 1013 | ubi->lookuptbl[pnum] = e; |
1014 | } else { | ||
1015 | e->ec = fm_e->ec; | ||
1016 | kfree(fm_e); | ||
1017 | } | 1014 | } |
1018 | 1015 | ||
1019 | spin_unlock(&ubi->wl_lock); | 1016 | spin_unlock(&ubi->wl_lock); |