[RFC,05/13] libflash/libffs: ffs_close() should use ffs_hdr_free()

Message ID 20170829062506.8317-6-cyril.bur@au1.ibm.com
State New
Headers show
Series
  • Rework flash TOC generation
Related show

Commit Message

Cyril Bur Aug. 29, 2017, 6:24 a.m.
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 libflash/libffs.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

Patch

diff --git a/libflash/libffs.c b/libflash/libffs.c
index 1684388f..822169b7 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -428,14 +428,32 @@  out:
 	return rc;
 }
 
-void ffs_close(struct ffs_handle *ffs)
+static void __hdr_free(struct ffs_hdr *hdr)
 {
 	struct ffs_entry *ent, *next;
 
-	list_for_each_safe(&ffs->hdr.entries, ent, next, list) {
+	list_for_each_safe(&hdr->entries, ent, next, list) {
 		list_del(&ent->list);
 		free(ent);
 	}
+	if (hdr->side) {
+		hdr->side->side = NULL;
+		ffs_hdr_free(hdr->side);
+	}
+}
+
+int ffs_hdr_free(struct ffs_hdr *hdr)
+{
+	printf("Freeing hdr\n");
+	__hdr_free(hdr);
+	free(hdr);
+
+	return 0;
+}
+
+void ffs_close(struct ffs_handle *ffs)
+{
+	__hdr_free(&ffs->hdr);
 
 	if (ffs->cache)
 		free(ffs->cache);
@@ -889,24 +907,6 @@  int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r)
 	return 0;
 }
 
-int ffs_hdr_free(struct ffs_hdr *hdr)
-{
-	struct ffs_entry *ent, *next;
-
-	printf("Freeing hdr\n");
-	list_for_each_safe(&hdr->entries, ent, next, list) {
-		list_del(&ent->list);
-		free(ent);
-	}
-	if (hdr->side) {
-		hdr->side->side = NULL;
-		ffs_hdr_free(hdr->side);
-	}
-	free(hdr);
-
-	return 0;
-}
-
 int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx,
 			uint32_t act_size)
 {