]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
staging: unisys: visorbus: clean up parser_string_get function
authorDavid Kershner <david.kershner@unisys.com>
Wed, 27 Sep 2017 17:14:08 +0000 (13:14 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Sep 2017 09:17:12 +0000 (11:17 +0200)
The function parser_string_get was writing its own strnlen function, use
the kernel version instead.

Signed-off-by: David Kershner <david.kershner@unisys.com>
Reviewed-by: Tim Sell <timothy.sell@unisys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/unisys/visorbus/visorchipset.c

index b7865b18c362e492f6c1b20ce21683eb9fa257cd..ff275d028e0239ba09cdf6132b5a0d60713ef39c 100644 (file)
@@ -641,36 +641,20 @@ static const guid_t *parser_id_get(struct parser_context *ctx)
        return &ctx->data.id;
 }
 
-static void *parser_string_get(struct parser_context *ctx)
+static void *parser_string_get(u8 *pscan, int nscan)
 {
-       u8 *pscan;
-       unsigned long nscan;
        int value_length;
        void *value;
-       int i;
 
-       pscan = ctx->curr;
-       if (!pscan)
-               return NULL;
-       nscan = ctx->bytes_remaining;
        if (nscan == 0)
                return NULL;
 
-       for (i = 0, value_length = -1; i < nscan; i++)
-               if (pscan[i] == '\0') {
-                       value_length = i;
-                       break;
-               }
-       /* '\0' was not included in the length */
-       if (value_length < 0)
-               value_length = nscan;
-
-       value = kmalloc(value_length + 1, GFP_KERNEL);
+       value_length = strnlen(pscan, nscan);
+       value = kzalloc(value_length + 1, GFP_KERNEL);
        if (!value)
                return NULL;
        if (value_length > 0)
                memcpy(value, pscan, value_length);
-       ((u8 *)(value))[value_length] = '\0';
        return value;
 }
 
@@ -685,7 +669,7 @@ static void *parser_name_get(struct parser_context *ctx)
 
        ctx->curr = (char *)&phdr + phdr->name_offset;
        ctx->bytes_remaining = phdr->name_length;
-       return parser_string_get(ctx);
+       return parser_string_get(ctx->curr, phdr->name_length);
 }
 
 static int visorbus_configure(struct controlvm_message *inmsg,