]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dell-laptop: Fix krealloc() misuse in parse_da_table()
authorDavid Woodhouse <David.Woodhouse@intel.com>
Thu, 14 Mar 2013 13:21:00 +0000 (13:21 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 18 Mar 2013 11:40:12 +0000 (11:40 +0000)
If krealloc() returns NULL, it *doesn't* free the original. So any code
of the form 'foo = krealloc(foo, …);' is almost certainly a bug.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/platform/x86/dell-laptop.c

index fa3ee6209572976b71d623585ecfb026842d5645..1134119521ac2e4da9708703d8b4252ac807ce15 100644 (file)
@@ -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);