Skip to content

Commit 3291b52

Browse files
Boris Brezillonrichardweinberger
authored andcommitted
UBI: introduce the VID buffer concept
Currently, all VID headers are allocated and freed using the ubi_zalloc_vid_hdr() and ubi_free_vid_hdr() function. These functions make sure to align allocation on ubi->vid_hdr_alsize and adjust the vid_hdr pointer to match the ubi->vid_hdr_shift requirements. This works fine, but is a bit convoluted. Moreover, the future introduction of LEB consolidation (needed to support MLC/TLC NANDs) will allows a VID buffer to contain more than one VID header. Hence the creation of a ubi_vid_io_buf struct to attach extra information to the VID header. We currently only store the actual pointer of the underlying buffer, but will soon add the number of VID headers contained in the buffer. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 799dca3 commit 3291b52

File tree

7 files changed

+218
-142
lines changed

7 files changed

+218
-142
lines changed

drivers/mtd/ubi/attach.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
453453
{
454454
int len, err, second_is_newer, bitflips = 0, corrupted = 0;
455455
uint32_t data_crc, crc;
456-
struct ubi_vid_hdr *vh = NULL;
456+
struct ubi_vid_io_buf *vidb = NULL;
457457
unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);
458458

459459
if (sqnum2 == aeb->sqnum) {
@@ -496,12 +496,12 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
496496
return bitflips << 1;
497497
}
498498

499-
vh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
500-
if (!vh)
499+
vidb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
500+
if (!vidb)
501501
return -ENOMEM;
502502

503503
pnum = aeb->pnum;
504-
err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
504+
err = ubi_io_read_vid_hdr(ubi, pnum, vidb, 0);
505505
if (err) {
506506
if (err == UBI_IO_BITFLIPS)
507507
bitflips = 1;
@@ -515,7 +515,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
515515
}
516516
}
517517

518-
vid_hdr = vh;
518+
vid_hdr = ubi_get_vid_hdr(vidb);
519519
}
520520

521521
/* Read the data of the copy and check the CRC */
@@ -541,7 +541,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
541541
}
542542
mutex_unlock(&ubi->buf_mutex);
543543

544-
ubi_free_vid_hdr(ubi, vh);
544+
ubi_free_vid_buf(vidb);
545545

546546
if (second_is_newer)
547547
dbg_bld("second PEB %d is newer, copy_flag is set", pnum);
@@ -553,7 +553,7 @@ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
553553
out_unlock:
554554
mutex_unlock(&ubi->buf_mutex);
555555
out_free_vidh:
556-
ubi_free_vid_hdr(ubi, vh);
556+
ubi_free_vid_buf(vidb);
557557
return err;
558558
}
559559

@@ -955,7 +955,8 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
955955
int pnum, bool fast)
956956
{
957957
struct ubi_ec_hdr *ech = ai->ech;
958-
struct ubi_vid_hdr *vidh = ai->vidh;
958+
struct ubi_vid_io_buf *vidb = ai->vidb;
959+
struct ubi_vid_hdr *vidh = ubi_get_vid_hdr(vidb);
959960
long long ec;
960961
int err, bitflips = 0, vol_id = -1, ec_err = 0;
961962

@@ -1053,7 +1054,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
10531054

10541055
/* OK, we've done with the EC header, let's look at the VID header */
10551056

1056-
err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0);
1057+
err = ubi_io_read_vid_hdr(ubi, pnum, vidb, 0);
10571058
if (err < 0)
10581059
return err;
10591060
switch (err) {
@@ -1396,8 +1397,8 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai,
13961397
if (!ai->ech)
13971398
return err;
13981399

1399-
ai->vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
1400-
if (!ai->vidh)
1400+
ai->vidb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
1401+
if (!ai->vidb)
14011402
goto out_ech;
14021403

14031404
for (pnum = start; pnum < ubi->peb_count; pnum++) {
@@ -1446,13 +1447,13 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai,
14461447
if (err)
14471448
goto out_vidh;
14481449

1449-
ubi_free_vid_hdr(ubi, ai->vidh);
1450+
ubi_free_vid_buf(ai->vidb);
14501451
kfree(ai->ech);
14511452

14521453
return 0;
14531454

14541455
out_vidh:
1455-
ubi_free_vid_hdr(ubi, ai->vidh);
1456+
ubi_free_vid_buf(ai->vidb);
14561457
out_ech:
14571458
kfree(ai->ech);
14581459
return err;
@@ -1510,8 +1511,8 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
15101511
if (!scan_ai->ech)
15111512
goto out_ai;
15121513

1513-
scan_ai->vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
1514-
if (!scan_ai->vidh)
1514+
scan_ai->vidb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
1515+
if (!scan_ai->vidb)
15151516
goto out_ech;
15161517

15171518
for (pnum = 0; pnum < UBI_FM_MAX_START; pnum++) {
@@ -1523,7 +1524,7 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
15231524
goto out_vidh;
15241525
}
15251526

1526-
ubi_free_vid_hdr(ubi, scan_ai->vidh);
1527+
ubi_free_vid_buf(scan_ai->vidb);
15271528
kfree(scan_ai->ech);
15281529

15291530
if (scan_ai->force_full_scan)
@@ -1544,7 +1545,7 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
15441545
return err;
15451546

15461547
out_vidh:
1547-
ubi_free_vid_hdr(ubi, scan_ai->vidh);
1548+
ubi_free_vid_buf(scan_ai->vidb);
15481549
out_ech:
15491550
kfree(scan_ai->ech);
15501551
out_ai:
@@ -1668,7 +1669,8 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
16681669
*/
16691670
static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
16701671
{
1671-
struct ubi_vid_hdr *vidh = ai->vidh;
1672+
struct ubi_vid_io_buf *vidb = ai->vidb;
1673+
struct ubi_vid_hdr *vidh = ubi_get_vid_hdr(vidb);
16721674
int pnum, err, vols_found = 0;
16731675
struct rb_node *rb1, *rb2;
16741676
struct ubi_ainf_volume *av;
@@ -1804,7 +1806,7 @@ static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
18041806

18051807
last_aeb = aeb;
18061808

1807-
err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidh, 1);
1809+
err = ubi_io_read_vid_hdr(ubi, aeb->pnum, vidb, 1);
18081810
if (err && err != UBI_IO_BITFLIPS) {
18091811
ubi_err(ubi, "VID header is not OK (%d)",
18101812
err);

0 commit comments

Comments
 (0)