diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-09-16 10:59:19 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2016-10-02 16:48:14 -0400 |
commit | 7b6b749b125a93d673ba12977007dfbd65a61c32 (patch) | |
tree | 75de2e3cad32f5d09b5799974cf1fcda113cde3b | |
parent | 91f4285fe389a2729efcd5db642d7652d8f27a40 (diff) |
UBI: move the global ech and vidh variables into struct ubi_attach_info
Even if it works fine with those global variables, attaching the
temporary ech and vidh objects used during UBI scan to the
ubi_attach_info object sounds like a more future-proof option.
For example, attaching several UBI devices in parallel is prevented by
this use of global variable. And also because global variables should
be avoided in general.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r-- | drivers/mtd/ubi/attach.c | 39 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 4 |
2 files changed, 23 insertions, 20 deletions
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c index 82b30c959a28..507f5d6b6114 100644 --- a/drivers/mtd/ubi/attach.c +++ b/drivers/mtd/ubi/attach.c | |||
@@ -91,10 +91,6 @@ | |||
91 | 91 | ||
92 | static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai); | 92 | static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai); |
93 | 93 | ||
94 | /* Temporary variables used during scanning */ | ||
95 | static struct ubi_ec_hdr *ech; | ||
96 | static struct ubi_vid_hdr *vidh; | ||
97 | |||
98 | #define AV_FIND BIT(0) | 94 | #define AV_FIND BIT(0) |
99 | #define AV_ADD BIT(1) | 95 | #define AV_ADD BIT(1) |
100 | #define AV_FIND_OR_ADD (AV_FIND | AV_ADD) | 96 | #define AV_FIND_OR_ADD (AV_FIND | AV_ADD) |
@@ -958,6 +954,8 @@ static bool vol_ignored(int vol_id) | |||
958 | static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, | 954 | static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, |
959 | int pnum, bool fast) | 955 | int pnum, bool fast) |
960 | { | 956 | { |
957 | struct ubi_ec_hdr *ech = ai->ech; | ||
958 | struct ubi_vid_hdr *vidh = ai->vidh; | ||
961 | long long ec; | 959 | long long ec; |
962 | int err, bitflips = 0, vol_id = -1, ec_err = 0; | 960 | int err, bitflips = 0, vol_id = -1, ec_err = 0; |
963 | 961 | ||
@@ -1394,12 +1392,12 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
1394 | 1392 | ||
1395 | err = -ENOMEM; | 1393 | err = -ENOMEM; |
1396 | 1394 | ||
1397 | ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | 1395 | ai->ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); |
1398 | if (!ech) | 1396 | if (!ai->ech) |
1399 | return err; | 1397 | return err; |
1400 | 1398 | ||
1401 | vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); | 1399 | ai->vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
1402 | if (!vidh) | 1400 | if (!ai->vidh) |
1403 | goto out_ech; | 1401 | goto out_ech; |
1404 | 1402 | ||
1405 | for (pnum = start; pnum < ubi->peb_count; pnum++) { | 1403 | for (pnum = start; pnum < ubi->peb_count; pnum++) { |
@@ -1448,15 +1446,15 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
1448 | if (err) | 1446 | if (err) |
1449 | goto out_vidh; | 1447 | goto out_vidh; |
1450 | 1448 | ||
1451 | ubi_free_vid_hdr(ubi, vidh); | 1449 | ubi_free_vid_hdr(ubi, ai->vidh); |
1452 | kfree(ech); | 1450 | kfree(ai->ech); |
1453 | 1451 | ||
1454 | return 0; | 1452 | return 0; |
1455 | 1453 | ||
1456 | out_vidh: | 1454 | out_vidh: |
1457 | ubi_free_vid_hdr(ubi, vidh); | 1455 | ubi_free_vid_hdr(ubi, ai->vidh); |
1458 | out_ech: | 1456 | out_ech: |
1459 | kfree(ech); | 1457 | kfree(ai->ech); |
1460 | return err; | 1458 | return err; |
1461 | } | 1459 | } |
1462 | 1460 | ||
@@ -1508,12 +1506,12 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai) | |||
1508 | if (!scan_ai) | 1506 | if (!scan_ai) |
1509 | goto out; | 1507 | goto out; |
1510 | 1508 | ||
1511 | ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | 1509 | scan_ai->ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); |
1512 | if (!ech) | 1510 | if (!scan_ai->ech) |
1513 | goto out_ai; | 1511 | goto out_ai; |
1514 | 1512 | ||
1515 | vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); | 1513 | scan_ai->vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
1516 | if (!vidh) | 1514 | if (!scan_ai->vidh) |
1517 | goto out_ech; | 1515 | goto out_ech; |
1518 | 1516 | ||
1519 | for (pnum = 0; pnum < UBI_FM_MAX_START; pnum++) { | 1517 | for (pnum = 0; pnum < UBI_FM_MAX_START; pnum++) { |
@@ -1525,8 +1523,8 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai) | |||
1525 | goto out_vidh; | 1523 | goto out_vidh; |
1526 | } | 1524 | } |
1527 | 1525 | ||
1528 | ubi_free_vid_hdr(ubi, vidh); | 1526 | ubi_free_vid_hdr(ubi, scan_ai->vidh); |
1529 | kfree(ech); | 1527 | kfree(scan_ai->ech); |
1530 | 1528 | ||
1531 | if (scan_ai->force_full_scan) | 1529 | if (scan_ai->force_full_scan) |
1532 | err = UBI_NO_FASTMAP; | 1530 | err = UBI_NO_FASTMAP; |
@@ -1546,9 +1544,9 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai) | |||
1546 | return err; | 1544 | return err; |
1547 | 1545 | ||
1548 | out_vidh: | 1546 | out_vidh: |
1549 | ubi_free_vid_hdr(ubi, vidh); | 1547 | ubi_free_vid_hdr(ubi, scan_ai->vidh); |
1550 | out_ech: | 1548 | out_ech: |
1551 | kfree(ech); | 1549 | kfree(scan_ai->ech); |
1552 | out_ai: | 1550 | out_ai: |
1553 | destroy_ai(scan_ai); | 1551 | destroy_ai(scan_ai); |
1554 | out: | 1552 | out: |
@@ -1670,6 +1668,7 @@ out_ai: | |||
1670 | */ | 1668 | */ |
1671 | static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai) | 1669 | static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai) |
1672 | { | 1670 | { |
1671 | struct ubi_vid_hdr *vidh = ai->vidh; | ||
1673 | int pnum, err, vols_found = 0; | 1672 | int pnum, err, vols_found = 0; |
1674 | struct rb_node *rb1, *rb2; | 1673 | struct rb_node *rb1, *rb2; |
1675 | struct ubi_ainf_volume *av; | 1674 | struct ubi_ainf_volume *av; |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index f22c6c2e980f..b51d398f2356 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -724,6 +724,8 @@ struct ubi_ainf_volume { | |||
724 | * @ec_sum: a temporary variable used when calculating @mean_ec | 724 | * @ec_sum: a temporary variable used when calculating @mean_ec |
725 | * @ec_count: a temporary variable used when calculating @mean_ec | 725 | * @ec_count: a temporary variable used when calculating @mean_ec |
726 | * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects | 726 | * @aeb_slab_cache: slab cache for &struct ubi_ainf_peb objects |
727 | * @ech: temporary EC header. Only available during scan | ||
728 | * @vidh: temporary VID header. Only available during scan | ||
727 | * | 729 | * |
728 | * This data structure contains the result of attaching an MTD device and may | 730 | * This data structure contains the result of attaching an MTD device and may |
729 | * be used by other UBI sub-systems to build final UBI data structures, further | 731 | * be used by other UBI sub-systems to build final UBI data structures, further |
@@ -752,6 +754,8 @@ struct ubi_attach_info { | |||
752 | uint64_t ec_sum; | 754 | uint64_t ec_sum; |
753 | int ec_count; | 755 | int ec_count; |
754 | struct kmem_cache *aeb_slab_cache; | 756 | struct kmem_cache *aeb_slab_cache; |
757 | struct ubi_ec_hdr *ech; | ||
758 | struct ubi_vid_hdr *vidh; | ||
755 | }; | 759 | }; |
756 | 760 | ||
757 | /** | 761 | /** |