blob: 1b79161bd78fd273a7ea73fef261913a94f42fb1 [file] [log] [blame]
Alex Elderb09c94a2014-10-01 21:54:16 -05001/*
Viresh Kumara93db2d2015-04-01 20:32:02 +05302 * Greybus manifest parsing
Alex Elderb09c94a2014-10-01 21:54:16 -05003 *
Alex Elderd8187aa2015-03-27 15:06:24 -05004 * Copyright 2014-2015 Google Inc.
5 * Copyright 2014-2015 Linaro Ltd.
Alex Elderb09c94a2014-10-01 21:54:16 -05006 *
7 * Released under the GPLv2 only.
8 */
9
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
Alex Elderb09c94a2014-10-01 21:54:16 -050012#include "greybus.h"
13
Viresh Kumar19b3b2c2015-03-24 17:08:13 +053014static const char *get_descriptor_type_string(u8 type)
15{
16 switch(type) {
17 case GREYBUS_TYPE_INVALID:
18 return "invalid";
Viresh Kumar19b3b2c2015-03-24 17:08:13 +053019 case GREYBUS_TYPE_STRING:
20 return "string";
21 case GREYBUS_TYPE_INTERFACE:
22 return "interface";
23 case GREYBUS_TYPE_CPORT:
24 return "cport";
Viresh Kumar83a0cb52015-04-01 20:31:59 +053025 case GREYBUS_TYPE_BUNDLE:
26 return "bundle";
Viresh Kumar19b3b2c2015-03-24 17:08:13 +053027 default:
28 WARN_ON(1);
29 return "unknown";
30 }
31}
32
Alex Elderb09c94a2014-10-01 21:54:16 -050033/*
34 * We scan the manifest once to identify where all the descriptors
35 * are. The result is a list of these manifest_desc structures. We
36 * then pick through them for what we're looking for (starting with
Viresh Kumara93db2d2015-04-01 20:32:02 +053037 * the interface descriptor). As each is processed we remove it from
Alex Elderb09c94a2014-10-01 21:54:16 -050038 * the list. When we're done the list should (probably) be empty.
39 */
40struct manifest_desc {
41 struct list_head links;
42
43 size_t size;
44 void *data;
45 enum greybus_descriptor_type type;
46};
47
Alex Elderb09c94a2014-10-01 21:54:16 -050048static void release_manifest_descriptor(struct manifest_desc *descriptor)
49{
50 list_del(&descriptor->links);
51 kfree(descriptor);
52}
53
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -080054static void release_manifest_descriptors(struct gb_interface *intf)
Alex Elderb09c94a2014-10-01 21:54:16 -050055{
56 struct manifest_desc *descriptor;
57 struct manifest_desc *next;
58
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -080059 list_for_each_entry_safe(descriptor, next, &intf->manifest_descs, links)
Alex Elderb09c94a2014-10-01 21:54:16 -050060 release_manifest_descriptor(descriptor);
61}
62
63/*
64 * Validate the given descriptor. Its reported size must fit within
Viresh Kumar696e0cc2014-11-21 11:26:30 +053065 * the number of bytes remaining, and it must have a recognized
Alex Elderb09c94a2014-10-01 21:54:16 -050066 * type. Check that the reported size is at least as big as what
67 * we expect to see. (It could be bigger, perhaps for a new version
68 * of the format.)
69 *
Alex Elderd393c982015-06-09 17:42:53 -050070 * Returns the (non-zero) number of bytes consumed by the descriptor,
71 * or a negative errno.
Alex Elderb09c94a2014-10-01 21:54:16 -050072 */
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -080073static int identify_descriptor(struct gb_interface *intf,
74 struct greybus_descriptor *desc, size_t size)
Alex Elderb09c94a2014-10-01 21:54:16 -050075{
76 struct greybus_descriptor_header *desc_header = &desc->header;
77 struct manifest_desc *descriptor;
Alex Elderd8187aa2015-03-27 15:06:24 -050078 size_t desc_size;
Alex Elderb09c94a2014-10-01 21:54:16 -050079 size_t expected_size;
80
81 if (size < sizeof(*desc_header)) {
Alex Elderd51c0ff2015-06-08 12:05:14 -050082 pr_err("manifest too small (%zu < %zu)\n",
83 size, sizeof(*desc_header));
Alex Elderb09c94a2014-10-01 21:54:16 -050084 return -EINVAL; /* Must at least have header */
85 }
86
Alex Elderd8187aa2015-03-27 15:06:24 -050087 desc_size = le16_to_cpu(desc_header->size);
88 if (desc_size > size) {
Alex Elderd51c0ff2015-06-08 12:05:14 -050089 pr_err("descriptor too big (%zu > %zu)\n", desc_size, size);
Alex Elderb09c94a2014-10-01 21:54:16 -050090 return -EINVAL;
91 }
92
Viresh Kumar19b3b2c2015-03-24 17:08:13 +053093 /* Descriptor needs to at least have a header */
94 expected_size = sizeof(*desc_header);
95
Alex Elderb09c94a2014-10-01 21:54:16 -050096 switch (desc_header->type) {
Alex Elderb09c94a2014-10-01 21:54:16 -050097 case GREYBUS_TYPE_STRING:
Alex Elderb09c94a2014-10-01 21:54:16 -050098 expected_size += sizeof(struct greybus_descriptor_string);
Viresh Kumar19b3b2c2015-03-24 17:08:13 +053099 expected_size += desc->string.length;
Viresh Kumarfa2fbf12015-04-28 19:51:35 +0530100
101 /* String descriptors are padded to 4 byte boundaries */
102 expected_size = ALIGN(expected_size, 4);
Alex Elderb09c94a2014-10-01 21:54:16 -0500103 break;
Alex Elder63cc9322014-10-02 12:30:02 -0500104 case GREYBUS_TYPE_INTERFACE:
Viresh Kumara93db2d2015-04-01 20:32:02 +0530105 expected_size += sizeof(struct greybus_descriptor_interface);
Alex Elder63cc9322014-10-02 12:30:02 -0500106 break;
Viresh Kumar7c183f72015-04-01 20:32:00 +0530107 case GREYBUS_TYPE_BUNDLE:
108 expected_size += sizeof(struct greybus_descriptor_bundle);
109 break;
Alex Elderb09c94a2014-10-01 21:54:16 -0500110 case GREYBUS_TYPE_CPORT:
Viresh Kumar19b3b2c2015-03-24 17:08:13 +0530111 expected_size += sizeof(struct greybus_descriptor_cport);
Alex Elderb09c94a2014-10-01 21:54:16 -0500112 break;
113 case GREYBUS_TYPE_INVALID:
114 default:
115 pr_err("invalid descriptor type (%hhu)\n", desc_header->type);
116 return -EINVAL;
117 }
118
Viresh Kumar19b3b2c2015-03-24 17:08:13 +0530119 if (desc_size < expected_size) {
Alex Elderd8187aa2015-03-27 15:06:24 -0500120 pr_err("%s descriptor too small (%zu < %zu)\n",
Viresh Kumar19b3b2c2015-03-24 17:08:13 +0530121 get_descriptor_type_string(desc_header->type),
122 desc_size, expected_size);
123 return -EINVAL;
124 }
125
Viresh Kumar55b930c2015-04-29 11:02:08 +0530126 /* Descriptor bigger than what we expect */
127 if (desc_size > expected_size) {
128 pr_warn("%s descriptor size mismatch (want %zu got %zu)\n",
129 get_descriptor_type_string(desc_header->type),
130 expected_size, desc_size);
131 }
132
Alex Elderb09c94a2014-10-01 21:54:16 -0500133 descriptor = kzalloc(sizeof(*descriptor), GFP_KERNEL);
134 if (!descriptor)
135 return -ENOMEM;
136
137 descriptor->size = desc_size;
Alex Elderd393c982015-06-09 17:42:53 -0500138 descriptor->data = (char *)desc + sizeof(*desc_header);
Alex Elderb09c94a2014-10-01 21:54:16 -0500139 descriptor->type = desc_header->type;
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800140 list_add_tail(&descriptor->links, &intf->manifest_descs);
Alex Elderb09c94a2014-10-01 21:54:16 -0500141
Alex Elderd393c982015-06-09 17:42:53 -0500142 /* desc_size is positive and is known to fit in a signed int */
Alex Elderd8187aa2015-03-27 15:06:24 -0500143
Alex Elderb09c94a2014-10-01 21:54:16 -0500144 return desc_size;
145}
146
147/*
148 * Find the string descriptor having the given id, validate it, and
149 * allocate a duplicate copy of it. The duplicate has an extra byte
150 * which guarantees the returned string is NUL-terminated.
151 *
152 * String index 0 is valid (it represents "no string"), and for
153 * that a null pointer is returned.
154 *
155 * Otherwise returns a pointer to a newly-allocated copy of the
156 * descriptor string, or an error-coded pointer on failure.
157 */
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800158static char *gb_string_get(struct gb_interface *intf, u8 string_id)
Alex Elderb09c94a2014-10-01 21:54:16 -0500159{
160 struct greybus_descriptor_string *desc_string;
161 struct manifest_desc *descriptor;
162 bool found = false;
163 char *string;
164
165 /* A zero string id means no string (but no error) */
166 if (!string_id)
167 return NULL;
168
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800169 list_for_each_entry(descriptor, &intf->manifest_descs, links) {
Alex Elderb09c94a2014-10-01 21:54:16 -0500170 if (descriptor->type != GREYBUS_TYPE_STRING)
171 continue;
172
Matt Porter7a13e2f2014-10-06 09:58:44 -0400173 desc_string = descriptor->data;
Alex Elderb09c94a2014-10-01 21:54:16 -0500174 if (desc_string->id == string_id) {
175 found = true;
176 break;
177 }
178 }
179 if (!found)
180 return ERR_PTR(-ENOENT);
181
182 /* Allocate an extra byte so we can guarantee it's NUL-terminated */
Alex Elderd393c982015-06-09 17:42:53 -0500183 string = kmemdup(&desc_string->string, desc_string->length + 1,
Alex Elderb09c94a2014-10-01 21:54:16 -0500184 GFP_KERNEL);
185 if (!string)
186 return ERR_PTR(-ENOMEM);
187 string[desc_string->length] = '\0';
188
189 /* Ok we've used this string, so we're done with it */
190 release_manifest_descriptor(descriptor);
191
192 return string;
193}
194
Alex Elderd88bfb52014-10-01 21:54:17 -0500195/*
Alex Elderd393c982015-06-09 17:42:53 -0500196 * Find cport descriptors in the manifest associated with the given
197 * bundle, and set up data structures for the functions that use
198 * them. Returns the number of cports set up for the bundle, or 0
199 * if there is an error.
Alex Elderc095bbc2014-10-01 21:54:18 -0500200 */
Alex Elderc46839d2015-06-09 17:42:54 -0500201static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
Alex Elderc095bbc2014-10-01 21:54:18 -0500202{
Alex Elderc46839d2015-06-09 17:42:54 -0500203 struct gb_interface *intf = bundle->intf;
Alex Eldera6b13eb2015-06-09 17:42:55 -0500204 struct manifest_desc *desc;
205 struct manifest_desc *next;
206 u8 bundle_id = bundle->id;
Alex Elderc095bbc2014-10-01 21:54:18 -0500207 u32 count = 0;
208
Alex Eldera6b13eb2015-06-09 17:42:55 -0500209 /* Set up all cport descriptors associated with this bundle */
210 list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) {
Alex Elderc095bbc2014-10-01 21:54:18 -0500211 struct greybus_descriptor_cport *desc_cport;
Alex Elder7fba0072014-10-28 19:35:59 -0500212 u8 protocol_id;
Alex Elderc095bbc2014-10-01 21:54:18 -0500213 u16 cport_id;
Alex Elderc095bbc2014-10-01 21:54:18 -0500214
Alex Eldera6b13eb2015-06-09 17:42:55 -0500215 if (desc->type != GREYBUS_TYPE_CPORT)
216 continue;
217
218 desc_cport = desc->data;
219 if (desc_cport->bundle != bundle_id)
220 continue;
Alex Elderc095bbc2014-10-01 21:54:18 -0500221
222 /* Found one. Set up its function structure */
Alex Elder7fba0072014-10-28 19:35:59 -0500223 protocol_id = desc_cport->protocol_id;
Alex Elderc095bbc2014-10-01 21:54:18 -0500224 cport_id = le16_to_cpu(desc_cport->id);
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500225 if (!gb_connection_create(bundle, cport_id, protocol_id))
Alex Elderc095bbc2014-10-01 21:54:18 -0500226 return 0; /* Error */
227
228 count++;
Alex Eldera6b13eb2015-06-09 17:42:55 -0500229
Alex Elderc095bbc2014-10-01 21:54:18 -0500230 /* Release the cport descriptor */
Alex Eldera6b13eb2015-06-09 17:42:55 -0500231 release_manifest_descriptor(desc);
Alex Elderc095bbc2014-10-01 21:54:18 -0500232 }
233
234 return count;
235}
236
237/*
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500238 * Find bundle descriptors in the manifest and set up their data
239 * structures. Returns the number of bundles set up for the
Viresh Kumar7c183f72015-04-01 20:32:00 +0530240 * given interface.
Alex Elderd88bfb52014-10-01 21:54:17 -0500241 */
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800242static u32 gb_manifest_parse_bundles(struct gb_interface *intf)
Alex Elderd88bfb52014-10-01 21:54:17 -0500243{
244 u32 count = 0;
245
246 while (true) {
247 struct manifest_desc *descriptor;
Viresh Kumar7c183f72015-04-01 20:32:00 +0530248 struct greybus_descriptor_bundle *desc_bundle;
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500249 struct gb_bundle *bundle;
Alex Elderd88bfb52014-10-01 21:54:17 -0500250 bool found = false;
251
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500252 /* Find an bundle descriptor */
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800253 list_for_each_entry(descriptor, &intf->manifest_descs, links) {
Viresh Kumar7c183f72015-04-01 20:32:00 +0530254 if (descriptor->type == GREYBUS_TYPE_BUNDLE) {
Alex Elderd88bfb52014-10-01 21:54:17 -0500255 found = true;
256 break;
257 }
258 }
259 if (!found)
260 break;
261
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500262 /* Found one. Set up its bundle structure*/
Viresh Kumar7c183f72015-04-01 20:32:00 +0530263 desc_bundle = descriptor->data;
264 bundle = gb_bundle_create(intf, desc_bundle->id,
Viresh Kumar88e6d372015-04-06 15:49:36 +0530265 desc_bundle->class);
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500266 if (!bundle)
Alex Elderd88bfb52014-10-01 21:54:17 -0500267 return 0; /* Error */
Alex Elderc095bbc2014-10-01 21:54:18 -0500268
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500269 /* Now go set up this bundle's functions and cports */
Alex Elderc46839d2015-06-09 17:42:54 -0500270 if (!gb_manifest_parse_cports(bundle))
Alex Elderc095bbc2014-10-01 21:54:18 -0500271 return 0; /* Error parsing cports */
272
Alex Elderd88bfb52014-10-01 21:54:17 -0500273 count++;
274
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500275 /* Done with this bundle descriptor */
Alex Elderd88bfb52014-10-01 21:54:17 -0500276 release_manifest_descriptor(descriptor);
277 }
278
279 return count;
280}
281
Viresh Kumara93db2d2015-04-01 20:32:02 +0530282static bool gb_manifest_parse_interface(struct gb_interface *intf,
283 struct manifest_desc *interface_desc)
Alex Elderb09c94a2014-10-01 21:54:16 -0500284{
Viresh Kumara93db2d2015-04-01 20:32:02 +0530285 struct greybus_descriptor_interface *desc_intf = interface_desc->data;
Alex Elderb09c94a2014-10-01 21:54:16 -0500286
287 /* Handle the strings first--they can fail */
Viresh Kumara93db2d2015-04-01 20:32:02 +0530288 intf->vendor_string = gb_string_get(intf, desc_intf->vendor_stringid);
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800289 if (IS_ERR(intf->vendor_string))
Alex Elder937d0da2014-10-03 14:14:25 -0500290 return false;
291
Alex Elderd393c982015-06-09 17:42:53 -0500292 intf->product_string = gb_string_get(intf, desc_intf->product_stringid);
293 if (IS_ERR(intf->product_string))
Viresh Kumar50fc08f2014-11-13 18:14:32 +0530294 goto out_free_vendor_string;
Alex Elderb09c94a2014-10-01 21:54:16 -0500295
Viresh Kumar8a5286e2015-04-28 19:51:37 +0530296 // FIXME
297 // Vendor, Product and Unique id must come via control protocol
298 intf->vendor = 0xffff;
299 intf->product = 0x0001;
300 intf->unique_id = 0;
Alex Elderb09c94a2014-10-01 21:54:16 -0500301
Viresh Kumara93db2d2015-04-01 20:32:02 +0530302 /* Release the interface descriptor, now that we're done with it */
303 release_manifest_descriptor(interface_desc);
Alex Elderb09c94a2014-10-01 21:54:16 -0500304
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500305 /* An interface must have at least one bundle descriptor */
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800306 if (!gb_manifest_parse_bundles(intf)) {
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -0500307 pr_err("manifest bundle descriptors not valid\n");
Alex Elder937d0da2014-10-03 14:14:25 -0500308 goto out_err;
Alex Elderd88bfb52014-10-01 21:54:17 -0500309 }
310
Alex Elder937d0da2014-10-03 14:14:25 -0500311 return true;
312out_err:
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800313 kfree(intf->product_string);
314 intf->product_string = NULL;
Viresh Kumar50fc08f2014-11-13 18:14:32 +0530315out_free_vendor_string:
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800316 kfree(intf->vendor_string);
317 intf->vendor_string = NULL;
Alex Elder937d0da2014-10-03 14:14:25 -0500318
319 return false;
Alex Elderb09c94a2014-10-01 21:54:16 -0500320}
321
322/*
Alex Elderd393c982015-06-09 17:42:53 -0500323 * Parse a buffer containing an interface manifest.
Alex Elderb09c94a2014-10-01 21:54:16 -0500324 *
325 * If we find anything wrong with the content/format of the buffer
326 * we reject it.
327 *
328 * The first requirement is that the manifest's version is
329 * one we can parse.
330 *
331 * We make an initial pass through the buffer and identify all of
332 * the descriptors it contains, keeping track for each its type
333 * and the location size of its data in the buffer.
334 *
Alex Elderd393c982015-06-09 17:42:53 -0500335 * Next we scan the descriptors, looking for an interface descriptor;
Alex Elderb09c94a2014-10-01 21:54:16 -0500336 * there must be exactly one of those. When found, we record the
337 * information it contains, and then remove that descriptor (and any
338 * string descriptors it refers to) from further consideration.
339 *
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800340 * After that we look for the interface's bundles--there must be at
Alex Elderb09c94a2014-10-01 21:54:16 -0500341 * least one of those.
342 *
Alex Elder937d0da2014-10-03 14:14:25 -0500343 * Returns true if parsing was successful, false otherwise.
Alex Elderb09c94a2014-10-01 21:54:16 -0500344 */
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -0800345bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size)
Alex Elderb09c94a2014-10-01 21:54:16 -0500346{
347 struct greybus_manifest *manifest;
348 struct greybus_manifest_header *header;
349 struct greybus_descriptor *desc;
350 struct manifest_desc *descriptor;
Viresh Kumara93db2d2015-04-01 20:32:02 +0530351 struct manifest_desc *interface_desc = NULL;
Alex Elderb09c94a2014-10-01 21:54:16 -0500352 u16 manifest_size;
353 u32 found = 0;
Viresh Kumar43d94312014-11-13 18:14:30 +0530354 bool result;
Alex Elderb09c94a2014-10-01 21:54:16 -0500355
Viresh Kumar1dd90df2014-11-14 17:25:03 +0530356 /* Manifest descriptor list should be empty here */
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800357 if (WARN_ON(!list_empty(&intf->manifest_descs)))
Viresh Kumar1dd90df2014-11-14 17:25:03 +0530358 return false;
359
Alex Elderb09c94a2014-10-01 21:54:16 -0500360 /* we have to have at _least_ the manifest header */
Alex Elderd393c982015-06-09 17:42:53 -0500361 if (size < sizeof(*header)) {
362 pr_err("short manifest (%zu < %zu)\n", size, sizeof(*header));
Alex Elder937d0da2014-10-03 14:14:25 -0500363 return false;
Alex Elderb09c94a2014-10-01 21:54:16 -0500364 }
365
366 /* Make sure the size is right */
367 manifest = data;
368 header = &manifest->header;
369 manifest_size = le16_to_cpu(header->size);
370 if (manifest_size != size) {
Alex Elderd51c0ff2015-06-08 12:05:14 -0500371 pr_err("manifest size mismatch (%zu != %hu)\n",
Alex Elderb09c94a2014-10-01 21:54:16 -0500372 size, manifest_size);
Alex Elder937d0da2014-10-03 14:14:25 -0500373 return false;
Alex Elderb09c94a2014-10-01 21:54:16 -0500374 }
375
376 /* Validate major/minor number */
377 if (header->version_major > GREYBUS_VERSION_MAJOR) {
378 pr_err("manifest version too new (%hhu.%hhu > %hhu.%hhu)\n",
379 header->version_major, header->version_minor,
380 GREYBUS_VERSION_MAJOR, GREYBUS_VERSION_MINOR);
Alex Elder937d0da2014-10-03 14:14:25 -0500381 return false;
Alex Elderb09c94a2014-10-01 21:54:16 -0500382 }
383
384 /* OK, find all the descriptors */
385 desc = (struct greybus_descriptor *)(header + 1);
386 size -= sizeof(*header);
387 while (size) {
388 int desc_size;
389
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800390 desc_size = identify_descriptor(intf, desc, size);
Viresh Kumar13fe6a92015-03-24 17:08:14 +0530391 if (desc_size < 0) {
Matt Porterff8aed52014-10-06 13:46:36 -0400392 result = false;
Alex Elder937d0da2014-10-03 14:14:25 -0500393 goto out;
Alex Elderb09c94a2014-10-01 21:54:16 -0500394 }
395 desc = (struct greybus_descriptor *)((char *)desc + desc_size);
396 size -= desc_size;
Greg Kroah-Hartman86bf33a2014-11-14 14:37:56 -0800397 }
Alex Elderb09c94a2014-10-01 21:54:16 -0500398
Viresh Kumara93db2d2015-04-01 20:32:02 +0530399 /* There must be a single interface descriptor */
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800400 list_for_each_entry(descriptor, &intf->manifest_descs, links) {
Viresh Kumara93db2d2015-04-01 20:32:02 +0530401 if (descriptor->type == GREYBUS_TYPE_INTERFACE)
Greg Kroah-Hartman86bf33a2014-11-14 14:37:56 -0800402 if (!found++)
Viresh Kumara93db2d2015-04-01 20:32:02 +0530403 interface_desc = descriptor;
Greg Kroah-Hartman86bf33a2014-11-14 14:37:56 -0800404 }
405 if (found != 1) {
Viresh Kumara93db2d2015-04-01 20:32:02 +0530406 pr_err("manifest must have 1 interface descriptor (%u found)\n",
Greg Kroah-Hartman86bf33a2014-11-14 14:37:56 -0800407 found);
408 result = false;
409 goto out;
Alex Elderb09c94a2014-10-01 21:54:16 -0500410 }
411
Viresh Kumara93db2d2015-04-01 20:32:02 +0530412 /* Parse the manifest, starting with the interface descriptor */
413 result = gb_manifest_parse_interface(intf, interface_desc);
Alex Elderb09c94a2014-10-01 21:54:16 -0500414
415 /*
416 * We really should have no remaining descriptors, but we
417 * don't know what newer format manifests might leave.
418 */
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800419 if (result && !list_empty(&intf->manifest_descs))
Viresh Kumara93db2d2015-04-01 20:32:02 +0530420 pr_info("excess descriptors in interface manifest\n");
Alex Elder937d0da2014-10-03 14:14:25 -0500421out:
Greg Kroah-Hartman86cad662014-12-23 15:16:50 -0800422 release_manifest_descriptors(intf);
Alex Elderb09c94a2014-10-01 21:54:16 -0500423
Matt Porterff8aed52014-10-06 13:46:36 -0400424 return result;
Alex Elderb09c94a2014-10-01 21:54:16 -0500425}