]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
s390/dasd: Remove variable sized array
authorJan Höppner <hoeppner@linux.vnet.ibm.com>
Tue, 9 May 2017 12:07:37 +0000 (14:07 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 12 Jun 2017 14:25:56 +0000 (16:25 +0200)
Dynamic stack allocations are considered bad. Get rid of this one
occurrence and use kstrdup() instead.

Also, set the return codes so that we have only one exit where we can
call kfree().

Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/block/dasd_devmap.c

index 1164b51d09f3b942bf6c04d3b233e79e08fc2259..05e5762d045e377ebfa291f0b03cd064d1dfc690 100644 (file)
@@ -315,45 +315,58 @@ static int __init dasd_parse_range(const char *range)
        char *features_str = NULL;
        char *from_str = NULL;
        char *to_str = NULL;
-       size_t len = strlen(range) + 1;
-       char tmp[len];
+       int rc = 0;
+       char *tmp;
 
-       strlcpy(tmp, range, len);
+       tmp = kstrdup(range, GFP_KERNEL);
+       if (!tmp)
+               return -ENOMEM;
 
-       if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str))
-               goto out_err;
+       if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
+               rc = -EINVAL;
+               goto out;
+       }
 
-       if (dasd_busid(from_str, &from_id0, &from_id1, &from))
-               goto out_err;
+       if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
+               rc = -EINVAL;
+               goto out;
+       }
 
        to = from;
        to_id0 = from_id0;
        to_id1 = from_id1;
        if (to_str) {
-               if (dasd_busid(to_str, &to_id0, &to_id1, &to))
-                       goto out_err;
+               if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
+                       rc = -EINVAL;
+                       goto out;
+               }
                if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
                        pr_err("%s is not a valid device range\n", range);
-                       goto out_err;
+                       rc = -EINVAL;
+                       goto out;
                }
        }
 
        features = dasd_feature_list(features_str);
-       if (features < 0)
-               goto out_err;
+       if (features < 0) {
+               rc = -EINVAL;
+               goto out;
+       }
        /* each device in dasd= parameter should be set initially online */
        features |= DASD_FEATURE_INITIAL_ONLINE;
        while (from <= to) {
                sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++);
                devmap = dasd_add_busid(bus_id, features);
-               if (IS_ERR(devmap))
-                       return PTR_ERR(devmap);
+               if (IS_ERR(devmap)) {
+                       rc = PTR_ERR(devmap);
+                       goto out;
+               }
        }
 
-       return 0;
+out:
+       kfree(tmp);
 
-out_err:
-       return -EINVAL;
+       return rc;
 }
 
 /*