[02ccfcd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[160b75e] | 29 | /** @addtogroup libusbdev
|
---|
[02ccfcd] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[a6add7a] | 33 | * Functions for recognition of attached devices.
|
---|
[02ccfcd] | 34 | */
|
---|
[77ad86c] | 35 |
|
---|
[17aca1c] | 36 | #include <sys/types.h>
|
---|
[eb1a2f4] | 37 | #include <fibril_synch.h>
|
---|
[59c163c] | 38 | #include <usb/debug.h>
|
---|
| 39 | #include <usb/dev/hub.h>
|
---|
[7d521e24] | 40 | #include <usb/dev/pipes.h>
|
---|
| 41 | #include <usb/dev/recognise.h>
|
---|
[357a302] | 42 | #include <usb/ddfiface.h>
|
---|
[7d521e24] | 43 | #include <usb/dev/request.h>
|
---|
[02ccfcd] | 44 | #include <usb/classes/classes.h>
|
---|
| 45 | #include <stdio.h>
|
---|
| 46 | #include <errno.h>
|
---|
[eb1a2f4] | 47 | #include <assert.h>
|
---|
[02ccfcd] | 48 |
|
---|
[a6add7a] | 49 | /** DDF operations of child devices. */
|
---|
[eea3e39] | 50 | static ddf_dev_ops_t child_ops = {
|
---|
[357a302] | 51 | .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
|
---|
[71ed4849] | 52 | };
|
---|
[02ccfcd] | 53 |
|
---|
[a6add7a] | 54 | /** Get integer part from BCD coded number. */
|
---|
[02ccfcd] | 55 | #define BCD_INT(a) (((unsigned int)(a)) / 256)
|
---|
[a6add7a] | 56 | /** Get fraction part from BCD coded number (as an integer, no less). */
|
---|
[02ccfcd] | 57 | #define BCD_FRAC(a) (((unsigned int)(a)) % 256)
|
---|
| 58 |
|
---|
[a6add7a] | 59 | /** Format for BCD coded number to be used in printf. */
|
---|
[02ccfcd] | 60 | #define BCD_FMT "%x.%x"
|
---|
[a6add7a] | 61 | /** Arguments to printf for BCD coded number. */
|
---|
[02ccfcd] | 62 | #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a))
|
---|
| 63 |
|
---|
| 64 | /** Add formatted match id.
|
---|
| 65 | *
|
---|
| 66 | * @param matches List of match ids where to add to.
|
---|
| 67 | * @param score Score of the match.
|
---|
| 68 | * @param format Printf-like format
|
---|
| 69 | * @return Error code.
|
---|
| 70 | */
|
---|
| 71 | static int usb_add_match_id(match_id_list_t *matches, int score,
|
---|
[37e4025] | 72 | const char *match_str)
|
---|
[02ccfcd] | 73 | {
|
---|
[37e4025] | 74 | assert(matches);
|
---|
[02ccfcd] | 75 |
|
---|
[37e4025] | 76 | match_id_t *match_id = create_match_id();
|
---|
[02ccfcd] | 77 | if (match_id == NULL) {
|
---|
[37e4025] | 78 | return ENOMEM;
|
---|
[02ccfcd] | 79 | }
|
---|
| 80 |
|
---|
| 81 | match_id->id = match_str;
|
---|
| 82 | match_id->score = score;
|
---|
| 83 | add_match_id(matches, match_id);
|
---|
| 84 |
|
---|
| 85 | return EOK;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[a6add7a] | 88 | /** Add match id to list or return with error code.
|
---|
| 89 | *
|
---|
| 90 | * @param match_ids List of match ids.
|
---|
| 91 | * @param score Match id score.
|
---|
| 92 | * @param format Format of the matching string
|
---|
| 93 | * @param ... Arguments for the format.
|
---|
| 94 | */
|
---|
[6e6dc7d] | 95 | #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \
|
---|
| 96 | do { \
|
---|
[37e4025] | 97 | char *str = NULL; \
|
---|
| 98 | int __rc = asprintf(&str, format, ##__VA_ARGS__); \
|
---|
| 99 | if (__rc > 0) { \
|
---|
| 100 | __rc = usb_add_match_id((match_ids), (score), str); \
|
---|
| 101 | } \
|
---|
[6e6dc7d] | 102 | if (__rc != EOK) { \
|
---|
[37e4025] | 103 | free(str); \
|
---|
[6e6dc7d] | 104 | return __rc; \
|
---|
| 105 | } \
|
---|
| 106 | } while (0)
|
---|
| 107 |
|
---|
[540e2d2] | 108 | /** Create device match ids based on its interface.
|
---|
| 109 | *
|
---|
[bc1c6fb] | 110 | * @param[in] desc_device Device descriptor.
|
---|
| 111 | * @param[in] desc_interface Interface descriptor.
|
---|
[540e2d2] | 112 | * @param[out] matches Initialized list of match ids.
|
---|
| 113 | * @return Error code (the two mentioned are not the only ones).
|
---|
| 114 | * @retval EINVAL Invalid input parameters (expects non NULL pointers).
|
---|
[bc1c6fb] | 115 | * @retval ENOENT Device class is not "use interface".
|
---|
[540e2d2] | 116 | */
|
---|
| 117 | int usb_device_create_match_ids_from_interface(
|
---|
[51f0e410] | 118 | const usb_standard_device_descriptor_t *desc_device,
|
---|
| 119 | const usb_standard_interface_descriptor_t *desc_interface,
|
---|
[540e2d2] | 120 | match_id_list_t *matches)
|
---|
| 121 | {
|
---|
[37e4025] | 122 | if (desc_interface == NULL || matches == NULL) {
|
---|
[540e2d2] | 123 | return EINVAL;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[51f0e410] | 126 | if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {
|
---|
[540e2d2] | 127 | return ENOENT;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[51f0e410] | 130 | const char *classname = usb_str_class(desc_interface->interface_class);
|
---|
[540e2d2] | 131 | assert(classname != NULL);
|
---|
| 132 |
|
---|
[51f0e410] | 133 | #define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"
|
---|
| 134 | #define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \
|
---|
| 135 | desc_interface->interface_protocol
|
---|
| 136 |
|
---|
| 137 | #define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"
|
---|
| 138 | #define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass
|
---|
| 139 |
|
---|
| 140 | #define IFACE_CLASS_FMT "interface&class=%s"
|
---|
| 141 | #define IFACE_CLASS_ARGS classname
|
---|
| 142 |
|
---|
| 143 | #define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT
|
---|
| 144 | #define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \
|
---|
| 145 | BCD_ARGS(desc_device->device_version)
|
---|
| 146 |
|
---|
| 147 | #define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"
|
---|
| 148 | #define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id
|
---|
| 149 |
|
---|
| 150 | #define VENDOR_ONLY_FMT "vendor=0x%04x"
|
---|
| 151 | #define VENDOR_ONLY_ARGS desc_device->vendor_id
|
---|
| 152 |
|
---|
| 153 | /*
|
---|
| 154 | * If the vendor is specified, create match ids with vendor with
|
---|
| 155 | * higher score.
|
---|
| 156 | * Then the same ones without the vendor part.
|
---|
| 157 | */
|
---|
| 158 | if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {
|
---|
| 159 | /* First, interface matches with device release number. */
|
---|
| 160 | ADD_MATCHID_OR_RETURN(matches, 250,
|
---|
| 161 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 162 | VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 163 | ADD_MATCHID_OR_RETURN(matches, 240,
|
---|
| 164 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 165 | VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 166 | ADD_MATCHID_OR_RETURN(matches, 230,
|
---|
| 167 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,
|
---|
| 168 | VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);
|
---|
| 169 |
|
---|
| 170 | /* Next, interface matches without release number. */
|
---|
| 171 | ADD_MATCHID_OR_RETURN(matches, 220,
|
---|
| 172 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 173 | VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 174 | ADD_MATCHID_OR_RETURN(matches, 210,
|
---|
| 175 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 176 | VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 177 | ADD_MATCHID_OR_RETURN(matches, 200,
|
---|
| 178 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,
|
---|
| 179 | VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);
|
---|
| 180 |
|
---|
| 181 | /* Finally, interface matches with only vendor. */
|
---|
| 182 | ADD_MATCHID_OR_RETURN(matches, 190,
|
---|
| 183 | "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 184 | VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 185 | ADD_MATCHID_OR_RETURN(matches, 180,
|
---|
| 186 | "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 187 | VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 188 | ADD_MATCHID_OR_RETURN(matches, 170,
|
---|
| 189 | "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,
|
---|
| 190 | VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | /* Now, the same but without any vendor specification. */
|
---|
| 194 | ADD_MATCHID_OR_RETURN(matches, 160,
|
---|
| 195 | "usb&" IFACE_PROTOCOL_FMT,
|
---|
| 196 | IFACE_PROTOCOL_ARGS);
|
---|
| 197 | ADD_MATCHID_OR_RETURN(matches, 150,
|
---|
| 198 | "usb&" IFACE_SUBCLASS_FMT,
|
---|
| 199 | IFACE_SUBCLASS_ARGS);
|
---|
| 200 | ADD_MATCHID_OR_RETURN(matches, 140,
|
---|
| 201 | "usb&" IFACE_CLASS_FMT,
|
---|
| 202 | IFACE_CLASS_ARGS);
|
---|
| 203 |
|
---|
| 204 | #undef IFACE_PROTOCOL_FMT
|
---|
| 205 | #undef IFACE_PROTOCOL_ARGS
|
---|
| 206 | #undef IFACE_SUBCLASS_FMT
|
---|
| 207 | #undef IFACE_SUBCLASS_ARGS
|
---|
| 208 | #undef IFACE_CLASS_FMT
|
---|
| 209 | #undef IFACE_CLASS_ARGS
|
---|
| 210 | #undef VENDOR_RELEASE_FMT
|
---|
| 211 | #undef VENDOR_RELEASE_ARGS
|
---|
| 212 | #undef VENDOR_PRODUCT_FMT
|
---|
| 213 | #undef VENDOR_PRODUCT_ARGS
|
---|
| 214 | #undef VENDOR_ONLY_FMT
|
---|
| 215 | #undef VENDOR_ONLY_ARGS
|
---|
[540e2d2] | 216 |
|
---|
[2211125e] | 217 | /* As a last resort, try fallback driver. */
|
---|
| 218 | ADD_MATCHID_OR_RETURN(matches, 10, "usb&interface&fallback");
|
---|
| 219 |
|
---|
[6e6dc7d] | 220 | return EOK;
|
---|
[540e2d2] | 221 | }
|
---|
| 222 |
|
---|
[692c0d3e] | 223 | /** Create DDF match ids from USB device descriptor.
|
---|
| 224 | *
|
---|
| 225 | * @param matches List of match ids to extend.
|
---|
| 226 | * @param device_descriptor Device descriptor returned by given device.
|
---|
| 227 | * @return Error code.
|
---|
| 228 | */
|
---|
[0f21c0c] | 229 | int usb_device_create_match_ids_from_device_descriptor(
|
---|
| 230 | const usb_standard_device_descriptor_t *device_descriptor,
|
---|
| 231 | match_id_list_t *matches)
|
---|
[692c0d3e] | 232 | {
|
---|
| 233 | /*
|
---|
| 234 | * Unless the vendor id is 0, the pair idVendor-idProduct
|
---|
| 235 | * quite uniquely describes the device.
|
---|
| 236 | */
|
---|
| 237 | if (device_descriptor->vendor_id != 0) {
|
---|
| 238 | /* First, with release number. */
|
---|
[6e6dc7d] | 239 | ADD_MATCHID_OR_RETURN(matches, 100,
|
---|
[345ea18] | 240 | "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
|
---|
[692c0d3e] | 241 | (int) device_descriptor->vendor_id,
|
---|
| 242 | (int) device_descriptor->product_id,
|
---|
| 243 | BCD_ARGS(device_descriptor->device_version));
|
---|
| 244 |
|
---|
| 245 | /* Next, without release number. */
|
---|
[6e6dc7d] | 246 | ADD_MATCHID_OR_RETURN(matches, 90,
|
---|
[345ea18] | 247 | "usb&vendor=0x%04x&product=0x%04x",
|
---|
[692c0d3e] | 248 | (int) device_descriptor->vendor_id,
|
---|
| 249 | (int) device_descriptor->product_id);
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[daf199f] | 252 | /* Class match id */
|
---|
| 253 | ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
|
---|
| 254 | usb_str_class(device_descriptor->device_class));
|
---|
[692c0d3e] | 255 |
|
---|
[93855d4] | 256 | /* As a last resort, try fallback driver. */
|
---|
| 257 | ADD_MATCHID_OR_RETURN(matches, 10, "usb&fallback");
|
---|
| 258 |
|
---|
[692c0d3e] | 259 | return EOK;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
[a66225f3] | 262 |
|
---|
[02ccfcd] | 263 | /** Create match ids describing attached device.
|
---|
| 264 | *
|
---|
| 265 | * @warning The list of match ids @p matches may change even when
|
---|
| 266 | * function exits with error.
|
---|
| 267 | *
|
---|
[4e8e1f5] | 268 | * @param ctrl_pipe Control pipe to given device (session must be already
|
---|
| 269 | * started).
|
---|
[02ccfcd] | 270 | * @param matches Initialized list of match ids.
|
---|
| 271 | * @return Error code.
|
---|
| 272 | */
|
---|
[a372663] | 273 | int usb_device_create_match_ids(usb_pipe_t *ctrl_pipe,
|
---|
[4e8e1f5] | 274 | match_id_list_t *matches)
|
---|
[02ccfcd] | 275 | {
|
---|
[2179cf95] | 276 | assert(ctrl_pipe);
|
---|
[02ccfcd] | 277 | int rc;
|
---|
[692c0d3e] | 278 | /*
|
---|
| 279 | * Retrieve device descriptor and add matches from it.
|
---|
| 280 | */
|
---|
[02ccfcd] | 281 | usb_standard_device_descriptor_t device_descriptor;
|
---|
| 282 |
|
---|
[4e8e1f5] | 283 | rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
|
---|
[02ccfcd] | 284 | if (rc != EOK) {
|
---|
| 285 | return rc;
|
---|
| 286 | }
|
---|
[4e8e1f5] | 287 |
|
---|
[0f21c0c] | 288 | rc = usb_device_create_match_ids_from_device_descriptor(
|
---|
| 289 | &device_descriptor, matches);
|
---|
[692c0d3e] | 290 | if (rc != EOK) {
|
---|
| 291 | return rc;
|
---|
[a66225f3] | 292 | }
|
---|
[4e8e1f5] | 293 |
|
---|
[02ccfcd] | 294 | return EOK;
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | /** Probe for device kind and register it in devman.
|
---|
| 298 | *
|
---|
[2179cf95] | 299 | * @param[in] ctrl_pipe Control pipe to the device.
|
---|
[4e8e1f5] | 300 | * @param[in] parent Parent device.
|
---|
[eea3e39] | 301 | * @param[in] dev_ops Child device ops. Default child_ops will be used if NULL.
|
---|
[bc1c6fb] | 302 | * @param[in] dev_data Arbitrary pointer to be stored in the child
|
---|
| 303 | * as @c driver_data.
|
---|
| 304 | * @param[out] child_fun Storage where pointer to allocated child function
|
---|
| 305 | * will be written.
|
---|
[02ccfcd] | 306 | * @return Error code.
|
---|
[77ad86c] | 307 | *
|
---|
[02ccfcd] | 308 | */
|
---|
[2179cf95] | 309 | int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,
|
---|
[db8b7ca] | 310 | ddf_dev_t *parent, ddf_fun_t **child_fun)
|
---|
[02ccfcd] | 311 | {
|
---|
[2179cf95] | 312 | if (child_fun == NULL || ctrl_pipe == NULL)
|
---|
[ae754e5f] | 313 | return EINVAL;
|
---|
[77ad86c] | 314 |
|
---|
[c046942] | 315 | /** Index to append after device name for uniqueness. */
|
---|
| 316 | static atomic_t device_name_index = {0};
|
---|
| 317 | const size_t this_device_name_index =
|
---|
| 318 | (size_t) atomic_preinc(&device_name_index);
|
---|
[77ad86c] | 319 |
|
---|
[eb1a2f4] | 320 | ddf_fun_t *child = NULL;
|
---|
[7ed5b576] | 321 | int rc;
|
---|
[77ad86c] | 322 |
|
---|
[7ed5b576] | 323 | /*
|
---|
[b207803] | 324 | * TODO: Once the device driver framework support persistent
|
---|
| 325 | * naming etc., something more descriptive could be created.
|
---|
[7ed5b576] | 326 | */
|
---|
[77ad86c] | 327 | char child_name[12]; /* The format is: "usbAB_aXYZ", length 11 */
|
---|
[2179cf95] | 328 | rc = snprintf(child_name, sizeof(child_name),
|
---|
| 329 | "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address);
|
---|
[7ed5b576] | 330 | if (rc < 0) {
|
---|
| 331 | goto failure;
|
---|
| 332 | }
|
---|
[77ad86c] | 333 |
|
---|
[eb1a2f4] | 334 | child = ddf_fun_create(parent, fun_inner, child_name);
|
---|
| 335 | if (child == NULL) {
|
---|
| 336 | rc = ENOMEM;
|
---|
| 337 | goto failure;
|
---|
| 338 | }
|
---|
[77ad86c] | 339 |
|
---|
[db8b7ca] | 340 | ddf_fun_set_ops(child, &child_ops);
|
---|
[77ad86c] | 341 | /*
|
---|
| 342 | * Store the attached device in fun
|
---|
| 343 | * driver data if there is no other data
|
---|
| 344 | */
|
---|
[db8b7ca] | 345 | usb_hub_attached_device_t *new_device = ddf_fun_data_alloc(
|
---|
| 346 | child, sizeof(usb_hub_attached_device_t));
|
---|
| 347 | if (!new_device) {
|
---|
| 348 | rc = ENOMEM;
|
---|
| 349 | goto failure;
|
---|
[59c163c] | 350 | }
|
---|
[77ad86c] | 351 |
|
---|
[db8b7ca] | 352 | new_device->address = ctrl_pipe->wire->address;
|
---|
| 353 | new_device->fun = child;
|
---|
| 354 |
|
---|
[56fd7cf] | 355 | match_id_list_t match_ids;
|
---|
| 356 | init_match_ids(&match_ids);
|
---|
| 357 | rc = usb_device_create_match_ids(ctrl_pipe, &match_ids);
|
---|
[77ad86c] | 358 | if (rc != EOK)
|
---|
[4e8e1f5] | 359 | goto failure;
|
---|
[77ad86c] | 360 |
|
---|
[56fd7cf] | 361 | list_foreach(match_ids.ids, id_link) {
|
---|
| 362 | match_id_t *match_id = list_get_instance(id_link, match_id_t, link);
|
---|
| 363 | rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
|
---|
| 364 | if (rc != EOK) {
|
---|
| 365 | clean_match_ids(&match_ids);
|
---|
| 366 | goto failure;
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | clean_match_ids(&match_ids);
|
---|
| 371 |
|
---|
[eb1a2f4] | 372 | rc = ddf_fun_bind(child);
|
---|
[77ad86c] | 373 | if (rc != EOK)
|
---|
[7ed5b576] | 374 | goto failure;
|
---|
[77ad86c] | 375 |
|
---|
[ae754e5f] | 376 | *child_fun = child;
|
---|
[7ed5b576] | 377 | return EOK;
|
---|
[77ad86c] | 378 |
|
---|
[7ed5b576] | 379 | failure:
|
---|
| 380 | if (child != NULL) {
|
---|
| 381 | /* This takes care of match_id deallocation as well. */
|
---|
[eb1a2f4] | 382 | ddf_fun_destroy(child);
|
---|
[7ed5b576] | 383 | }
|
---|
[77ad86c] | 384 |
|
---|
[7ed5b576] | 385 | return rc;
|
---|
[02ccfcd] | 386 | }
|
---|
[7ed5b576] | 387 |
|
---|
[02ccfcd] | 388 | /**
|
---|
| 389 | * @}
|
---|
| 390 | */
|
---|