Skip to content

Commit c19286d

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubi: Replace erase_block() with sync_erase()
Since erase_block() has same logic with sync_erase(), just replace it with sync_erase(), also rename 'sync_erase()' to 'ubi_sync_erase()'. Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent a033ab4 commit c19286d

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

drivers/mtd/ubi/fastmap.c

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,50 +1389,6 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
13891389
return ret;
13901390
}
13911391

1392-
/**
1393-
* erase_block - Manually erase a PEB.
1394-
* @ubi: UBI device object
1395-
* @e: the physical eraseblock to erase
1396-
*
1397-
* This function returns zero in case of success and a negative error code in
1398-
* case of failure.
1399-
*/
1400-
static int erase_block(struct ubi_device *ubi, struct ubi_wl_entry *e)
1401-
{
1402-
int err;
1403-
struct ubi_ec_hdr *ec_hdr;
1404-
long long ec = e->ec;
1405-
1406-
ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
1407-
if (!ec_hdr)
1408-
return -ENOMEM;
1409-
1410-
err = ubi_io_sync_erase(ubi, e->pnum, 0);
1411-
if (err < 0)
1412-
goto out;
1413-
1414-
ec += err;
1415-
if (ec > UBI_MAX_ERASECOUNTER) {
1416-
err = -EINVAL;
1417-
goto out;
1418-
}
1419-
1420-
ec_hdr->ec = cpu_to_be64(ec);
1421-
err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr);
1422-
if (err < 0)
1423-
goto out;
1424-
1425-
e->ec = ec;
1426-
spin_lock(&ubi->wl_lock);
1427-
if (e->ec > ubi->max_ec)
1428-
ubi->max_ec = e->ec;
1429-
spin_unlock(&ubi->wl_lock);
1430-
1431-
out:
1432-
kfree(ec_hdr);
1433-
return err;
1434-
}
1435-
14361392
/**
14371393
* invalidate_fastmap - destroys a fastmap.
14381394
* @ubi: UBI device object
@@ -1573,7 +1529,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
15731529

15741530
if (!tmp_e) {
15751531
if (old_fm && old_fm->e[i]) {
1576-
ret = erase_block(ubi, old_fm->e[i]);
1532+
ret = ubi_sync_erase(ubi, old_fm->e[i], 0);
15771533
if (ret < 0) {
15781534
ubi_err(ubi, "could not erase old fastmap PEB");
15791535

@@ -1625,7 +1581,7 @@ int ubi_update_fastmap(struct ubi_device *ubi)
16251581
if (old_fm) {
16261582
/* no fresh anchor PEB was found, reuse the old one */
16271583
if (!tmp_e) {
1628-
ret = erase_block(ubi, old_fm->e[0]);
1584+
ret = ubi_sync_erase(ubi, old_fm->e[0], 0);
16291585
if (ret < 0) {
16301586
ubi_err(ubi, "could not erase old anchor PEB");
16311587

drivers/mtd/ubi/ubi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap,
902902
struct ubi_attach_info *ai_scan);
903903

904904
/* wl.c */
905+
int ubi_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture);
905906
int ubi_wl_get_peb(struct ubi_device *ubi);
906907
int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,
907908
int pnum, int torture);

drivers/mtd/ubi/wl.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,15 @@ static int prot_queue_del(struct ubi_device *ubi, int pnum)
427427
}
428428

429429
/**
430-
* sync_erase - synchronously erase a physical eraseblock.
430+
* ubi_sync_erase - synchronously erase a physical eraseblock.
431431
* @ubi: UBI device description object
432432
* @e: the physical eraseblock to erase
433433
* @torture: if the physical eraseblock has to be tortured
434434
*
435435
* This function returns zero in case of success and a negative error code in
436436
* case of failure.
437437
*/
438-
static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
439-
int torture)
438+
int ubi_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture)
440439
{
441440
int err;
442441
struct ubi_ec_hdr *ec_hdr;
@@ -1094,7 +1093,7 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
10941093
dbg_wl("erase PEB %d EC %d LEB %d:%d",
10951094
pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum);
10961095

1097-
err = sync_erase(ubi, e, wl_wrk->torture);
1096+
err = ubi_sync_erase(ubi, e, wl_wrk->torture);
10981097
if (!err) {
10991098
spin_lock(&ubi->wl_lock);
11001099

@@ -1749,7 +1748,7 @@ static int erase_aeb(struct ubi_device *ubi, struct ubi_ainf_peb *aeb, bool sync
17491748
ubi->lookuptbl[e->pnum] = e;
17501749

17511750
if (sync) {
1752-
err = sync_erase(ubi, e, false);
1751+
err = ubi_sync_erase(ubi, e, false);
17531752
if (err)
17541753
goto out_free;
17551754

0 commit comments

Comments
 (0)