// SPDX-License-Identifier: GPL-2.0 /* * Greybus manifest parsing * * Copyright 2014-2015 Google Inc. * Copyright 2014-2015 Linaro Ltd. */ #include <linux/greybus.h> static const char *get_descriptor_type_string(u8 type) { … } /* * We scan the manifest once to identify where all the descriptors * are. The result is a list of these manifest_desc structures. We * then pick through them for what we're looking for (starting with * the interface descriptor). As each is processed we remove it from * the list. When we're done the list should (probably) be empty. */ struct manifest_desc { … }; static void release_manifest_descriptor(struct manifest_desc *descriptor) { … } static void release_manifest_descriptors(struct gb_interface *intf) { … } static void release_cport_descriptors(struct list_head *head, u8 bundle_id) { … } static struct manifest_desc *get_next_bundle_desc(struct gb_interface *intf) { … } /* * Validate the given descriptor. Its reported size must fit within * the number of bytes remaining, and it must have a recognized * type. Check that the reported size is at least as big as what * we expect to see. (It could be bigger, perhaps for a new version * of the format.) * * Returns the (non-zero) number of bytes consumed by the descriptor, * or a negative errno. */ static int identify_descriptor(struct gb_interface *intf, struct greybus_descriptor *desc, size_t size) { … } /* * Find the string descriptor having the given id, validate it, and * allocate a duplicate copy of it. The duplicate has an extra byte * which guarantees the returned string is NUL-terminated. * * String index 0 is valid (it represents "no string"), and for * that a null pointer is returned. * * Otherwise returns a pointer to a newly-allocated copy of the * descriptor string, or an error-coded pointer on failure. */ static char *gb_string_get(struct gb_interface *intf, u8 string_id) { … } /* * Find cport descriptors in the manifest associated with the given * bundle, and set up data structures for the functions that use * them. Returns the number of cports set up for the bundle, or 0 * if there is an error. */ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) { … } /* * Find bundle descriptors in the manifest and set up their data * structures. Returns the number of bundles set up for the * given interface. */ static u32 gb_manifest_parse_bundles(struct gb_interface *intf) { … } static bool gb_manifest_parse_interface(struct gb_interface *intf, struct manifest_desc *interface_desc) { … } /* * Parse a buffer containing an interface manifest. * * If we find anything wrong with the content/format of the buffer * we reject it. * * The first requirement is that the manifest's version is * one we can parse. * * We make an initial pass through the buffer and identify all of * the descriptors it contains, keeping track for each its type * and the location size of its data in the buffer. * * Next we scan the descriptors, looking for an interface descriptor; * there must be exactly one of those. When found, we record the * information it contains, and then remove that descriptor (and any * string descriptors it refers to) from further consideration. * * After that we look for the interface's bundles--there must be at * least one of those. * * Returns true if parsing was successful, false otherwise. */ bool gb_manifest_parse(struct gb_interface *intf, void *data, size_t size) { … }