Skip to content

Commit b32b78f

Browse files
ubi: Introduce in_pq()
This function works like in_wl_tree() but checks whether an ubi_wl_entry is currently in the protection queue. We need this function to query the current state of an ubi_wl_entry. Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent a3b22b9 commit b32b78f

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

drivers/mtd/ubi/wl.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ static int in_wl_tree(struct ubi_wl_entry *e, struct rb_root *root)
277277
return 0;
278278
}
279279

280+
/**
281+
* in_pq - check if a wear-leveling entry is present in the protection queue.
282+
* @ubi: UBI device description object
283+
* @e: the wear-leveling entry to check
284+
*
285+
* This function returns non-zero if @e is in the protection queue and zero
286+
* if it is not.
287+
*/
288+
static inline int in_pq(const struct ubi_device *ubi, struct ubi_wl_entry *e)
289+
{
290+
struct ubi_wl_entry *p;
291+
int i;
292+
293+
for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i)
294+
list_for_each_entry(p, &ubi->pq[i], u.list)
295+
if (p == e)
296+
return 1;
297+
298+
return 0;
299+
}
300+
280301
/**
281302
* prot_queue_add - add physical eraseblock to the protection queue.
282303
* @ubi: UBI device description object
@@ -1848,16 +1869,11 @@ static int self_check_in_wl_tree(const struct ubi_device *ubi,
18481869
static int self_check_in_pq(const struct ubi_device *ubi,
18491870
struct ubi_wl_entry *e)
18501871
{
1851-
struct ubi_wl_entry *p;
1852-
int i;
1853-
18541872
if (!ubi_dbg_chk_gen(ubi))
18551873
return 0;
18561874

1857-
for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i)
1858-
list_for_each_entry(p, &ubi->pq[i], u.list)
1859-
if (p == e)
1860-
return 0;
1875+
if (in_pq(ubi, e))
1876+
return 0;
18611877

18621878
ubi_err(ubi, "self-check failed for PEB %d, EC %d, Protect queue",
18631879
e->pnum, e->ec);

0 commit comments

Comments
 (0)