Commit d8187aa2 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: manifest: use size_t for a size variable

In identify_descriptor(), the variable desc_size represents the size
of a memory object.  So change its type from int to size_t.

The return value for this function can be desc_size cast to int.
One can verify by inspection this will never exceed INT_MAX.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 973ccfd6
/* /*
* Greybus module manifest parsing * Greybus module manifest parsing
* *
* Copyright 2014 Google Inc. * Copyright 2014-2015 Google Inc.
* Copyright 2014 Linaro Ltd. * Copyright 2014-2015 Linaro Ltd.
* *
* Released under the GPLv2 only. * Released under the GPLv2 only.
*/ */
...@@ -79,7 +79,7 @@ static int identify_descriptor(struct gb_interface *intf, ...@@ -79,7 +79,7 @@ static int identify_descriptor(struct gb_interface *intf,
{ {
struct greybus_descriptor_header *desc_header = &desc->header; struct greybus_descriptor_header *desc_header = &desc->header;
struct manifest_desc *descriptor; struct manifest_desc *descriptor;
int desc_size; size_t desc_size;
size_t expected_size; size_t expected_size;
if (size < sizeof(*desc_header)) { if (size < sizeof(*desc_header)) {
...@@ -87,8 +87,8 @@ static int identify_descriptor(struct gb_interface *intf, ...@@ -87,8 +87,8 @@ static int identify_descriptor(struct gb_interface *intf,
return -EINVAL; /* Must at least have header */ return -EINVAL; /* Must at least have header */
} }
desc_size = (int)le16_to_cpu(desc_header->size); desc_size = le16_to_cpu(desc_header->size);
if ((size_t)desc_size > size) { if (desc_size > size) {
pr_err("descriptor too big\n"); pr_err("descriptor too big\n");
return -EINVAL; return -EINVAL;
} }
...@@ -119,7 +119,7 @@ static int identify_descriptor(struct gb_interface *intf, ...@@ -119,7 +119,7 @@ static int identify_descriptor(struct gb_interface *intf,
} }
if (desc_size < expected_size) { if (desc_size < expected_size) {
pr_err("%s descriptor too small (%u < %zu)\n", pr_err("%s descriptor too small (%zu < %zu)\n",
get_descriptor_type_string(desc_header->type), get_descriptor_type_string(desc_header->type),
desc_size, expected_size); desc_size, expected_size);
return -EINVAL; return -EINVAL;
...@@ -134,6 +134,8 @@ static int identify_descriptor(struct gb_interface *intf, ...@@ -134,6 +134,8 @@ static int identify_descriptor(struct gb_interface *intf,
descriptor->type = desc_header->type; descriptor->type = desc_header->type;
list_add_tail(&descriptor->links, &intf->manifest_descs); list_add_tail(&descriptor->links, &intf->manifest_descs);
/* desc_size is is positive and is known to fit in a signed int */
return desc_size; return desc_size;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment