Skip to content

Commit 7b6b749

Browse files
Boris Brezillonrichardweinberger
authored andcommitted
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>
1 parent 91f4285 commit 7b6b749

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

drivers/mtd/ubi/attach.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191

9292
static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai);
9393

94-
/* Temporary variables used during scanning */
95-
static struct ubi_ec_hdr *ech;
96-
static struct ubi_vid_hdr *vidh;
97-
9894
#define AV_FIND BIT(0)
9995
#define AV_ADD BIT(1)
10096
#define AV_FIND_OR_ADD (AV_FIND | AV_ADD)
@@ -958,6 +954,8 @@ static bool vol_ignored(int vol_id)
958954
static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
959955
int pnum, bool fast)
960956
{
957+
struct ubi_ec_hdr *ech = ai->ech;
958+
struct ubi_vid_hdr *vidh = ai->vidh;
961959
long long ec;
962960
int err, bitflips = 0, vol_id = -1, ec_err = 0;
963961

@@ -1394,12 +1392,12 @@ static int scan_all(struct ubi_device *ubi, struct ubi_attach_info *ai,
13941392

13951393
err = -ENOMEM;
13961394

1397-
ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
1398-
if (!ech)
1395+
ai->ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
1396+
if (!ai->ech)
13991397
return err;
14001398

1401-
vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
1402-
if (!vidh)
1399+
ai->vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
1400+
if (!ai->vidh)
14031401
goto out_ech;
14041402

14051403
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,
14481446
if (err)
14491447
goto out_vidh;
14501448

1451-
ubi_free_vid_hdr(ubi, vidh);
1452-
kfree(ech);
1449+
ubi_free_vid_hdr(ubi, ai->vidh);
1450+
kfree(ai->ech);
14531451

14541452
return 0;
14551453

14561454
out_vidh:
1457-
ubi_free_vid_hdr(ubi, vidh);
1455+
ubi_free_vid_hdr(ubi, ai->vidh);
14581456
out_ech:
1459-
kfree(ech);
1457+
kfree(ai->ech);
14601458
return err;
14611459
}
14621460

@@ -1508,12 +1506,12 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
15081506
if (!scan_ai)
15091507
goto out;
15101508

1511-
ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
1512-
if (!ech)
1509+
scan_ai->ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
1510+
if (!scan_ai->ech)
15131511
goto out_ai;
15141512

1515-
vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
1516-
if (!vidh)
1513+
scan_ai->vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
1514+
if (!scan_ai->vidh)
15171515
goto out_ech;
15181516

15191517
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)
15251523
goto out_vidh;
15261524
}
15271525

1528-
ubi_free_vid_hdr(ubi, vidh);
1529-
kfree(ech);
1526+
ubi_free_vid_hdr(ubi, scan_ai->vidh);
1527+
kfree(scan_ai->ech);
15301528

15311529
if (scan_ai->force_full_scan)
15321530
err = UBI_NO_FASTMAP;
@@ -1546,9 +1544,9 @@ static int scan_fast(struct ubi_device *ubi, struct ubi_attach_info **ai)
15461544
return err;
15471545

15481546
out_vidh:
1549-
ubi_free_vid_hdr(ubi, vidh);
1547+
ubi_free_vid_hdr(ubi, scan_ai->vidh);
15501548
out_ech:
1551-
kfree(ech);
1549+
kfree(scan_ai->ech);
15521550
out_ai:
15531551
destroy_ai(scan_ai);
15541552
out:
@@ -1670,6 +1668,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
16701668
*/
16711669
static int self_check_ai(struct ubi_device *ubi, struct ubi_attach_info *ai)
16721670
{
1671+
struct ubi_vid_hdr *vidh = ai->vidh;
16731672
int pnum, err, vols_found = 0;
16741673
struct rb_node *rb1, *rb2;
16751674
struct ubi_ainf_volume *av;

drivers/mtd/ubi/ubi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ struct ubi_ainf_volume {
724724
* @ec_sum: a temporary variable used when calculating @mean_ec
725725
* @ec_count: a temporary variable used when calculating @mean_ec
726726
* @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
727729
*
728730
* This data structure contains the result of attaching an MTD device and may
729731
* be used by other UBI sub-systems to build final UBI data structures, further
@@ -752,6 +754,8 @@ struct ubi_attach_info {
752754
uint64_t ec_sum;
753755
int ec_count;
754756
struct kmem_cache *aeb_slab_cache;
757+
struct ubi_ec_hdr *ech;
758+
struct ubi_vid_hdr *vidh;
755759
};
756760

757761
/**

0 commit comments

Comments
 (0)