Skip to contentSkip to conversation

dell-laptop: Fix krealloc() misuse in parse_da_table()

PATCH New David Woodhouse 1 participant 1 message Mar 14, 2013 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 dell-laptop: Fix krealloc() misuse in parse_da_table()

If krealloc() returns NULL, it *doesn't* free the original. So any code of the form 'foo = krealloc(foo, …);' is almost certainly a bug.

---
 drivers/platform/x86/dell-laptop.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/platform/x86/dell-laptop.c +6 -4
index fa3ee62..79c6916 100644
@@ -284,6 +284,7 @@ static void __init parse_da_table(const struct dmi_header *dm)
 {
 	/* Final token is a terminator, so we don't want to copy it */
 	int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
+	struct calling_interface_token *new_da_tokens;
 	struct calling_interface_structure *table =
 		container_of(dm, struct calling_interface_structure, header);
 
@@ -296,12 +297,13 @@ static void __init parse_da_table(const struct dmi_header *dm)
 	da_command_address = table->cmdIOAddress;
 	da_command_code = table->cmdIOCode;
 
-	da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
-			     sizeof(struct calling_interface_token),
-			     GFP_KERNEL);
+	new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
+				 sizeof(struct calling_interface_token),
+				 GFP_KERNEL);
 
-	if (!da_tokens)
+	if (!new_da_tokens)
 		return;
+	da_tokens = new_da_tokens;
 
 	memcpy(da_tokens+da_num_tokens, table->tokens,
 	       sizeof(struct calling_interface_token) * tokens);
Signature · 6 lines
1.8.1.4


-- 
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation