From d8187aa2241136e9fb3801e82fe8c2dfdae06802 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Fri, 27 Mar 2015 15:06:24 -0500 Subject: 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: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/manifest.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'drivers/staging/greybus/manifest.c') diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c index 1b9edbcd08c5..c29a0c822f23 100644 --- a/drivers/staging/greybus/manifest.c +++ b/drivers/staging/greybus/manifest.c @@ -1,8 +1,8 @@ /* * Greybus module manifest parsing * - * Copyright 2014 Google Inc. - * Copyright 2014 Linaro Ltd. + * Copyright 2014-2015 Google Inc. + * Copyright 2014-2015 Linaro Ltd. * * Released under the GPLv2 only. */ @@ -79,7 +79,7 @@ static int identify_descriptor(struct gb_interface *intf, { struct greybus_descriptor_header *desc_header = &desc->header; struct manifest_desc *descriptor; - int desc_size; + size_t desc_size; size_t expected_size; if (size < sizeof(*desc_header)) { @@ -87,8 +87,8 @@ static int identify_descriptor(struct gb_interface *intf, return -EINVAL; /* Must at least have header */ } - desc_size = (int)le16_to_cpu(desc_header->size); - if ((size_t)desc_size > size) { + desc_size = le16_to_cpu(desc_header->size); + if (desc_size > size) { pr_err("descriptor too big\n"); return -EINVAL; } @@ -119,7 +119,7 @@ static int identify_descriptor(struct gb_interface *intf, } 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), desc_size, expected_size); return -EINVAL; @@ -134,6 +134,8 @@ static int identify_descriptor(struct gb_interface *intf, descriptor->type = desc_header->type; 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; } -- cgit v1.2.3