Skip to content

Commit f9efe8d

Browse files
Boris Brezillonrichardweinberger
authored andcommitted
UBI: factorize destroy_av() and ubi_remove_av() code
Those functions are pretty much doing the same thing, except ubi_remove_av() is putting the aeb elements attached to the volume into the ai->erase list and the destroy_av() is freeing them. Rework destroy_av() to handle both cases. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent de4c455 commit f9efe8d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

drivers/mtd/ubi/attach.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -722,26 +722,20 @@ struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai,
722722
&created);
723723
}
724724

725+
static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av,
726+
struct list_head *list);
727+
725728
/**
726729
* ubi_remove_av - delete attaching information about a volume.
727730
* @ai: attaching information
728731
* @av: the volume attaching information to delete
729732
*/
730733
void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
731734
{
732-
struct rb_node *rb;
733-
struct ubi_ainf_peb *aeb;
734-
735735
dbg_bld("remove attaching information about volume %d", av->vol_id);
736736

737-
while ((rb = rb_first(&av->root))) {
738-
aeb = rb_entry(rb, struct ubi_ainf_peb, u.rb);
739-
rb_erase(&aeb->u.rb, &av->root);
740-
list_add_tail(&aeb->u.list, &ai->erase);
741-
}
742-
743737
rb_erase(&av->rb, &ai->volumes);
744-
kfree(av);
738+
destroy_av(ai, av, &ai->erase);
745739
ai->vols_found -= 1;
746740
}
747741

@@ -1256,10 +1250,12 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
12561250
* destroy_av - free volume attaching information.
12571251
* @av: volume attaching information
12581252
* @ai: attaching information
1253+
* @list: put the aeb elements in there if !NULL, otherwise free them
12591254
*
12601255
* This function destroys the volume attaching information.
12611256
*/
1262-
static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
1257+
static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av,
1258+
struct list_head *list)
12631259
{
12641260
struct ubi_ainf_peb *aeb;
12651261
struct rb_node *this = av->root.rb_node;
@@ -1279,7 +1275,10 @@ static void destroy_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av)
12791275
this->rb_right = NULL;
12801276
}
12811277

1282-
kmem_cache_free(ai->aeb_slab_cache, aeb);
1278+
if (list)
1279+
list_add_tail(&aeb->u.list, list);
1280+
else
1281+
kmem_cache_free(ai->aeb_slab_cache, aeb);
12831282
}
12841283
}
12851284
kfree(av);
@@ -1334,7 +1333,7 @@ static void destroy_ai(struct ubi_attach_info *ai)
13341333
rb->rb_right = NULL;
13351334
}
13361335

1337-
destroy_av(ai, av);
1336+
destroy_av(ai, av, NULL);
13381337
}
13391338
}
13401339

0 commit comments

Comments
 (0)