mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] partitions: efi: use calloc instead of kzalloc
@ 2024-10-22  8:33 Ahmad Fatoum
  2024-10-22  8:33 ` [PATCH 2/2] partition: dos: use xmalloc for unchecked allocations Ahmad Fatoum
  2024-10-22  9:22 ` [PATCH 1/2] partitions: efi: use calloc instead of kzalloc Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-10-22  8:33 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

kzalloc() uses at least DMA_ALIGNMENT as alignment, which is more than
we need for the data structures that are used to hold the partition info.

Use the normal allocator to be more efficient with memory.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/partitions/efi.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 829360da6e1f..07944109ac89 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -92,7 +92,7 @@ static gpt_entry *alloc_read_gpt_entries(struct block_device *blk,
 	if (!count)
 		return NULL;
 
-	pte = kzalloc(count, GFP_KERNEL);
+	pte = calloc(count, 1);
 	if (!pte)
 		return NULL;
 
@@ -100,7 +100,7 @@ static gpt_entry *alloc_read_gpt_entries(struct block_device *blk,
 	size = count / GPT_BLOCK_SIZE;
 	ret = block_read(blk, pte, from, size);
 	if (ret) {
-		kfree(pte);
+		free(pte);
 		pte=NULL;
 		return NULL;
 	}
@@ -129,13 +129,13 @@ static gpt_header *alloc_read_gpt_header(struct block_device *blk,
 	unsigned ssz = bdev_logical_block_size(blk);
 	int ret;
 
-	gpt = kzalloc(ssz, GFP_KERNEL);
+	gpt = calloc(ssz, 1);
 	if (!gpt)
 		return NULL;
 
 	ret = block_read(blk, gpt, lba, 1);
 	if (ret) {
-		kfree(gpt);
+		free(gpt);
 		gpt=NULL;
 		return NULL;
 	}
@@ -227,10 +227,10 @@ static int is_gpt_valid(struct block_device *blk, u64 lba,
 	return 1;
 
  fail_ptes:
-	kfree(*ptes);
+	free(*ptes);
 	*ptes = NULL;
  fail:
-	kfree(*gpt);
+	free(*gpt);
 	*gpt = NULL;
 	return 0;
 }
@@ -406,8 +406,8 @@ static int find_valid_gpt(void *buf, struct block_device *blk, gpt_header **gpt,
 	if (good_pgpt) {
 		*gpt  = pgpt;
 		*ptes = pptes;
-		kfree(agpt);
-		kfree(aptes);
+		free(agpt);
+		free(aptes);
 		if (!good_agpt)
 			dev_warn(blk->dev, "Alternate GPT is invalid, using primary GPT.\n");
 		return 1;
@@ -415,17 +415,17 @@ static int find_valid_gpt(void *buf, struct block_device *blk, gpt_header **gpt,
 	else if (good_agpt) {
 		*gpt  = agpt;
 		*ptes = aptes;
-		kfree(pgpt);
-		kfree(pptes);
+		free(pgpt);
+		free(pptes);
 		dev_warn(blk->dev, "Primary GPT is invalid, using alternate GPT.\n");
 		return 1;
 	}
 
  fail:
-	kfree(pgpt);
-	kfree(agpt);
-	kfree(pptes);
-	kfree(aptes);
+	free(pgpt);
+	free(agpt);
+	free(pptes);
+	free(aptes);
 	*gpt = NULL;
 	*ptes = NULL;
 	return 0;
-- 
2.39.5




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-22  9:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-22  8:33 [PATCH 1/2] partitions: efi: use calloc instead of kzalloc Ahmad Fatoum
2024-10-22  8:33 ` [PATCH 2/2] partition: dos: use xmalloc for unchecked allocations Ahmad Fatoum
2024-10-22  9:22 ` [PATCH 1/2] partitions: efi: use calloc instead of kzalloc Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox