Skip to contentSkip to conversation

Fix loading of large firmware files.

PATCH Superseded [email protected] 1 participant 2 messages Apr 17, 2008 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix loading of large firmware files.

From: Thomas Hellstrom <[email protected]>

drivers/base/firmware_class.c +3 -1
index 4a1b9bf..4215cbf 100644
@@ -206,7 +206,9 @@ fw_realloc_buffer(struct firmware_priv *
 	if (min_size <= fw_priv->alloc_size)
 		return 0;
 
-	new_size = ALIGN(min_size, PAGE_SIZE);
+	new_size = 2 * new_size;
+	new_size = (min_size > new_size) ? min_size : new_size;
+	new_size = ALIGN(new_size, PAGE_SIZE);
 	new_data = vmalloc(new_size);
 	if (!new_data) {
 		printk(KERN_ERR "%s: unable to alloc buffer\n", __FUNCTION__);
Signature · 1 line
1.4.1
#1 lore raw

PATCH RESEND 1/1 Fix loading of large firmware files

Firmware loading has a memory allocation complexity of O(size * size), which makes loads of very large firmware files stall and fail. This patch fixes that problem by making the allocation complexity O(size * ln(size)).

---
 drivers/base/firmware_class.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/base/firmware_class.c +3 -1
index 4a1b9bf..4215cbf 100644
@@ -206,7 +206,9 @@ fw_realloc_buffer(struct firmware_priv *
 	if (min_size <= fw_priv->alloc_size)
 		return 0;
 
-	new_size = ALIGN(min_size, PAGE_SIZE);
+	new_size = 2 * new_size;
+	new_size = (min_size > new_size) ? min_size : new_size;
+	new_size = ALIGN(new_size, PAGE_SIZE);
 	new_data = vmalloc(new_size);
 	if (!new_data) {
 		printk(KERN_ERR "%s: unable to alloc buffer\n", __FUNCTION__);
Signature · 1 line
1.4.1