Commit 85f3aeed authored by Viresh Kumar's avatar Viresh Kumar Committed by Greg Kroah-Hartman

greybus: manifest: remove extra loop for finding module descriptor

Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent a68bd742
...@@ -54,7 +54,8 @@ static void release_manifest_descriptors(void) ...@@ -54,7 +54,8 @@ static void release_manifest_descriptors(void)
* Returns the number of bytes consumed by the descriptor, or a * Returns the number of bytes consumed by the descriptor, or a
* negative errno. * negative errno.
*/ */
static int identify_descriptor(struct greybus_descriptor *desc, size_t size) static int identify_descriptor(struct greybus_descriptor *desc, size_t size,
bool *is_module)
{ {
struct greybus_descriptor_header *desc_header = &desc->header; struct greybus_descriptor_header *desc_header = &desc->header;
struct manifest_desc *descriptor; struct manifest_desc *descriptor;
...@@ -79,6 +80,7 @@ static int identify_descriptor(struct greybus_descriptor *desc, size_t size) ...@@ -79,6 +80,7 @@ static int identify_descriptor(struct greybus_descriptor *desc, size_t size)
desc_size); desc_size);
return -EINVAL; return -EINVAL;
} }
*is_module = true;
break; break;
case GREYBUS_TYPE_STRING: case GREYBUS_TYPE_STRING:
expected_size = sizeof(struct greybus_descriptor_header); expected_size = sizeof(struct greybus_descriptor_header);
...@@ -309,7 +311,7 @@ static bool gb_manifest_parse_module(struct gb_module *gmod, ...@@ -309,7 +311,7 @@ static bool gb_manifest_parse_module(struct gb_module *gmod,
* the descriptors it contains, keeping track for each its type * the descriptors it contains, keeping track for each its type
* and the location size of its data in the buffer. * and the location size of its data in the buffer.
* *
* Next we scan the descriptors, looking for a module descriptor; * We also identify the module descriptor during this iteration,
* there must be exactly one of those. When found, we record the * there must be exactly one of those. When found, we record the
* information it contains, and then remove that descriptor (and any * information it contains, and then remove that descriptor (and any
* string descriptors it refers to) from further consideration. * string descriptors it refers to) from further consideration.
...@@ -359,8 +361,9 @@ bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size) ...@@ -359,8 +361,9 @@ bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size)
size -= sizeof(*header); size -= sizeof(*header);
while (size) { while (size) {
int desc_size; int desc_size;
bool is_module = false;
desc_size = identify_descriptor(desc, size); desc_size = identify_descriptor(desc, size, &is_module);
if (desc_size <= 0) { if (desc_size <= 0) {
if (!desc_size) if (!desc_size)
pr_err("zero-sized manifest descriptor\n"); pr_err("zero-sized manifest descriptor\n");
...@@ -369,19 +372,17 @@ bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size) ...@@ -369,19 +372,17 @@ bool gb_manifest_parse(struct gb_module *gmod, void *data, size_t size)
} }
desc = (struct greybus_descriptor *)((char *)desc + desc_size); desc = (struct greybus_descriptor *)((char *)desc + desc_size);
size -= desc_size; size -= desc_size;
}
/* There must be a single module descriptor */ if (is_module) {
list_for_each_entry(descriptor, &manifest_descs, links) { if (++found > 1) {
if (descriptor->type == GREYBUS_TYPE_MODULE)
if (!found++)
module_desc = descriptor;
}
if (found != 1) {
pr_err("manifest must have 1 module descriptor (%u found)\n", pr_err("manifest must have 1 module descriptor (%u found)\n",
found); found);
result = false; result = false;
goto out; goto out;
} else {
module_desc = descriptor;
}
}
} }
/* Parse the module manifest, starting with the module descriptor */ /* Parse the module manifest, starting with the module descriptor */
......
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