[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 |
|
---|
[3b77628] | 29 | /** @addtogroup libusb
|
---|
[02ccfcd] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief Functions for recognising kind of attached devices.
|
---|
| 34 | */
|
---|
[17aca1c] | 35 | #include <sys/types.h>
|
---|
[eb1a2f4] | 36 | #include <fibril_synch.h>
|
---|
[4e8e1f5] | 37 | #include <usb/pipes.h>
|
---|
| 38 | #include <usb/recognise.h>
|
---|
[357a302] | 39 | #include <usb/ddfiface.h>
|
---|
[4e8e1f5] | 40 | #include <usb/request.h>
|
---|
[02ccfcd] | 41 | #include <usb/classes/classes.h>
|
---|
| 42 | #include <stdio.h>
|
---|
| 43 | #include <errno.h>
|
---|
[eb1a2f4] | 44 | #include <assert.h>
|
---|
[02ccfcd] | 45 |
|
---|
[4e8e1f5] | 46 | static size_t device_name_index = 0;
|
---|
| 47 | static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
|
---|
| 48 |
|
---|
[eb1a2f4] | 49 | ddf_dev_ops_t child_ops = {
|
---|
[357a302] | 50 | .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
|
---|
[71ed4849] | 51 | };
|
---|
[02ccfcd] | 52 |
|
---|
| 53 | #define BCD_INT(a) (((unsigned int)(a)) / 256)
|
---|
| 54 | #define BCD_FRAC(a) (((unsigned int)(a)) % 256)
|
---|
| 55 |
|
---|
| 56 | #define BCD_FMT "%x.%x"
|
---|
| 57 | #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a))
|
---|
| 58 |
|
---|
| 59 | /* FIXME: make this dynamic */
|
---|
| 60 | #define MATCH_STRING_MAX 256
|
---|
| 61 |
|
---|
| 62 | /** Add formatted match id.
|
---|
| 63 | *
|
---|
| 64 | * @param matches List of match ids where to add to.
|
---|
| 65 | * @param score Score of the match.
|
---|
| 66 | * @param format Printf-like format
|
---|
| 67 | * @return Error code.
|
---|
| 68 | */
|
---|
| 69 | static int usb_add_match_id(match_id_list_t *matches, int score,
|
---|
| 70 | const char *format, ...)
|
---|
| 71 | {
|
---|
| 72 | char *match_str = NULL;
|
---|
| 73 | match_id_t *match_id = NULL;
|
---|
| 74 | int rc;
|
---|
| 75 |
|
---|
| 76 | match_str = malloc(MATCH_STRING_MAX + 1);
|
---|
| 77 | if (match_str == NULL) {
|
---|
| 78 | rc = ENOMEM;
|
---|
| 79 | goto failure;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * FIXME: replace with dynamic allocation of exact size
|
---|
| 84 | */
|
---|
| 85 | va_list args;
|
---|
| 86 | va_start(args, format );
|
---|
| 87 | vsnprintf(match_str, MATCH_STRING_MAX, format, args);
|
---|
| 88 | match_str[MATCH_STRING_MAX] = 0;
|
---|
| 89 | va_end(args);
|
---|
| 90 |
|
---|
| 91 | match_id = create_match_id();
|
---|
| 92 | if (match_id == NULL) {
|
---|
| 93 | rc = ENOMEM;
|
---|
| 94 | goto failure;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | match_id->id = match_str;
|
---|
| 98 | match_id->score = score;
|
---|
| 99 | add_match_id(matches, match_id);
|
---|
| 100 |
|
---|
| 101 | return EOK;
|
---|
| 102 |
|
---|
| 103 | failure:
|
---|
| 104 | if (match_str != NULL) {
|
---|
| 105 | free(match_str);
|
---|
| 106 | }
|
---|
| 107 | if (match_id != NULL) {
|
---|
| 108 | match_id->id = NULL;
|
---|
| 109 | delete_match_id(match_id);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | return rc;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[6e6dc7d] | 115 | #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \
|
---|
| 116 | do { \
|
---|
| 117 | int __rc = usb_add_match_id((match_ids), (score), \
|
---|
| 118 | format, ##__VA_ARGS__); \
|
---|
| 119 | if (__rc != EOK) { \
|
---|
| 120 | return __rc; \
|
---|
| 121 | } \
|
---|
| 122 | } while (0)
|
---|
| 123 |
|
---|
[540e2d2] | 124 | /** Create device match ids based on its interface.
|
---|
| 125 | *
|
---|
| 126 | * @param[in] descriptor Interface descriptor.
|
---|
| 127 | * @param[out] matches Initialized list of match ids.
|
---|
| 128 | * @return Error code (the two mentioned are not the only ones).
|
---|
| 129 | * @retval EINVAL Invalid input parameters (expects non NULL pointers).
|
---|
| 130 | * @retval ENOENT Interface does not specify class.
|
---|
| 131 | */
|
---|
| 132 | int usb_device_create_match_ids_from_interface(
|
---|
[51f0e410] | 133 | const usb_standard_device_descriptor_t *desc_device,
|
---|
| 134 | const usb_standard_interface_descriptor_t *desc_interface,
|
---|
[540e2d2] | 135 | match_id_list_t *matches)
|
---|
| 136 | {
|
---|
[51f0e410] | 137 | if (desc_interface == NULL) {
|
---|
[540e2d2] | 138 | return EINVAL;
|
---|
| 139 | }
|
---|
| 140 | if (matches == NULL) {
|
---|
| 141 | return EINVAL;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[51f0e410] | 144 | if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {
|
---|
[540e2d2] | 145 | return ENOENT;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[51f0e410] | 148 | const char *classname = usb_str_class(desc_interface->interface_class);
|
---|
[540e2d2] | 149 | assert(classname != NULL);
|
---|
| 150 |
|
---|
[51f0e410] | 151 | #define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"
|
---|
| 152 | #define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \
|
---|
| 153 | desc_interface->interface_protocol
|
---|
| 154 |
|
---|
| 155 | #define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"
|
---|
| 156 | #define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass
|
---|
| 157 |
|
---|
| 158 | #define IFACE_CLASS_FMT "interface&class=%s"
|
---|
| 159 | #define IFACE_CLASS_ARGS classname
|
---|
| 160 |
|
---|
| 161 | #define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT
|
---|
| 162 | #define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \
|
---|
| 163 | BCD_ARGS(desc_device->device_version)
|
---|
| 164 |
|
---|
| 165 | #define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"
|
---|
| 166 | #define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id
|
---|
| 167 |
|
---|
| 168 | #define VENDOR_ONLY_FMT "vendor=0x%04x"
|
---|
| 169 | #define VENDOR_ONLY_ARGS desc_device->vendor_id
|
---|
| 170 |
|
---|
| 171 | /*
|
---|
| 172 | * If the vendor is specified, create match ids with vendor with
|
---|
| 173 | * higher score.
|
---|
| 174 | * Then the same ones without the vendor part.
|
---|
| 175 | */
|
---|
| 176 | if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {
|
---|
| 177 | /* First, interface matches with device release number. */
|
---|
| 178 | ADD_MATCHID_OR_RETURN(matches, 250,
|
---|
| 179 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 180 | VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 181 | ADD_MATCHID_OR_RETURN(matches, 240,
|
---|
| 182 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 183 | VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 184 | ADD_MATCHID_OR_RETURN(matches, 230,
|
---|
| 185 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,
|
---|
| 186 | VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);
|
---|
| 187 |
|
---|
| 188 | /* Next, interface matches without release number. */
|
---|
| 189 | ADD_MATCHID_OR_RETURN(matches, 220,
|
---|
| 190 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 191 | VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 192 | ADD_MATCHID_OR_RETURN(matches, 210,
|
---|
| 193 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 194 | VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 195 | ADD_MATCHID_OR_RETURN(matches, 200,
|
---|
| 196 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,
|
---|
| 197 | VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);
|
---|
| 198 |
|
---|
| 199 | /* Finally, interface matches with only vendor. */
|
---|
| 200 | ADD_MATCHID_OR_RETURN(matches, 190,
|
---|
| 201 | "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 202 | VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 203 | ADD_MATCHID_OR_RETURN(matches, 180,
|
---|
| 204 | "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 205 | VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 206 | ADD_MATCHID_OR_RETURN(matches, 170,
|
---|
| 207 | "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,
|
---|
| 208 | VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /* Now, the same but without any vendor specification. */
|
---|
| 212 | ADD_MATCHID_OR_RETURN(matches, 160,
|
---|
| 213 | "usb&" IFACE_PROTOCOL_FMT,
|
---|
| 214 | IFACE_PROTOCOL_ARGS);
|
---|
| 215 | ADD_MATCHID_OR_RETURN(matches, 150,
|
---|
| 216 | "usb&" IFACE_SUBCLASS_FMT,
|
---|
| 217 | IFACE_SUBCLASS_ARGS);
|
---|
| 218 | ADD_MATCHID_OR_RETURN(matches, 140,
|
---|
| 219 | "usb&" IFACE_CLASS_FMT,
|
---|
| 220 | IFACE_CLASS_ARGS);
|
---|
| 221 |
|
---|
| 222 | #undef IFACE_PROTOCOL_FMT
|
---|
| 223 | #undef IFACE_PROTOCOL_ARGS
|
---|
| 224 | #undef IFACE_SUBCLASS_FMT
|
---|
| 225 | #undef IFACE_SUBCLASS_ARGS
|
---|
| 226 | #undef IFACE_CLASS_FMT
|
---|
| 227 | #undef IFACE_CLASS_ARGS
|
---|
| 228 | #undef VENDOR_RELEASE_FMT
|
---|
| 229 | #undef VENDOR_RELEASE_ARGS
|
---|
| 230 | #undef VENDOR_PRODUCT_FMT
|
---|
| 231 | #undef VENDOR_PRODUCT_ARGS
|
---|
| 232 | #undef VENDOR_ONLY_FMT
|
---|
| 233 | #undef VENDOR_ONLY_ARGS
|
---|
[540e2d2] | 234 |
|
---|
[6e6dc7d] | 235 | return EOK;
|
---|
[540e2d2] | 236 | }
|
---|
| 237 |
|
---|
[692c0d3e] | 238 | /** Create DDF match ids from USB device descriptor.
|
---|
| 239 | *
|
---|
| 240 | * @param matches List of match ids to extend.
|
---|
| 241 | * @param device_descriptor Device descriptor returned by given device.
|
---|
| 242 | * @return Error code.
|
---|
| 243 | */
|
---|
[0f21c0c] | 244 | int usb_device_create_match_ids_from_device_descriptor(
|
---|
| 245 | const usb_standard_device_descriptor_t *device_descriptor,
|
---|
| 246 | match_id_list_t *matches)
|
---|
[692c0d3e] | 247 | {
|
---|
| 248 | /*
|
---|
| 249 | * Unless the vendor id is 0, the pair idVendor-idProduct
|
---|
| 250 | * quite uniquely describes the device.
|
---|
| 251 | */
|
---|
| 252 | if (device_descriptor->vendor_id != 0) {
|
---|
| 253 | /* First, with release number. */
|
---|
[6e6dc7d] | 254 | ADD_MATCHID_OR_RETURN(matches, 100,
|
---|
[345ea18] | 255 | "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
|
---|
[692c0d3e] | 256 | (int) device_descriptor->vendor_id,
|
---|
| 257 | (int) device_descriptor->product_id,
|
---|
| 258 | BCD_ARGS(device_descriptor->device_version));
|
---|
| 259 |
|
---|
| 260 | /* Next, without release number. */
|
---|
[6e6dc7d] | 261 | ADD_MATCHID_OR_RETURN(matches, 90,
|
---|
[345ea18] | 262 | "usb&vendor=0x%04x&product=0x%04x",
|
---|
[692c0d3e] | 263 | (int) device_descriptor->vendor_id,
|
---|
| 264 | (int) device_descriptor->product_id);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | /*
|
---|
| 268 | * If the device class points to interface we skip adding
|
---|
[3ae93a8] | 269 | * class directly but we add a multi interface device.
|
---|
[692c0d3e] | 270 | */
|
---|
| 271 | if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
|
---|
[6e6dc7d] | 272 | ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
|
---|
[692c0d3e] | 273 | usb_str_class(device_descriptor->device_class));
|
---|
[3ae93a8] | 274 | } else {
|
---|
[6e6dc7d] | 275 | ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
|
---|
[692c0d3e] | 276 | }
|
---|
| 277 |
|
---|
| 278 | return EOK;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[a66225f3] | 281 |
|
---|
[02ccfcd] | 282 | /** Create match ids describing attached device.
|
---|
| 283 | *
|
---|
| 284 | * @warning The list of match ids @p matches may change even when
|
---|
| 285 | * function exits with error.
|
---|
| 286 | *
|
---|
[4e8e1f5] | 287 | * @param ctrl_pipe Control pipe to given device (session must be already
|
---|
| 288 | * started).
|
---|
[02ccfcd] | 289 | * @param matches Initialized list of match ids.
|
---|
| 290 | * @return Error code.
|
---|
| 291 | */
|
---|
[4e8e1f5] | 292 | int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
|
---|
| 293 | match_id_list_t *matches)
|
---|
[02ccfcd] | 294 | {
|
---|
| 295 | int rc;
|
---|
[692c0d3e] | 296 | /*
|
---|
| 297 | * Retrieve device descriptor and add matches from it.
|
---|
| 298 | */
|
---|
[02ccfcd] | 299 | usb_standard_device_descriptor_t device_descriptor;
|
---|
| 300 |
|
---|
[4e8e1f5] | 301 | rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
|
---|
[02ccfcd] | 302 | if (rc != EOK) {
|
---|
| 303 | return rc;
|
---|
| 304 | }
|
---|
[4e8e1f5] | 305 |
|
---|
[0f21c0c] | 306 | rc = usb_device_create_match_ids_from_device_descriptor(
|
---|
| 307 | &device_descriptor, matches);
|
---|
[692c0d3e] | 308 | if (rc != EOK) {
|
---|
| 309 | return rc;
|
---|
[a66225f3] | 310 | }
|
---|
[4e8e1f5] | 311 |
|
---|
[02ccfcd] | 312 | return EOK;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | /** Probe for device kind and register it in devman.
|
---|
| 316 | *
|
---|
[3b77628] | 317 | * @param[in] address Address of the (unknown) attached device.
|
---|
[4e8e1f5] | 318 | * @param[in] hc_handle Handle of the host controller.
|
---|
| 319 | * @param[in] parent Parent device.
|
---|
[3b77628] | 320 | * @param[out] child_handle Handle of the child device.
|
---|
[02ccfcd] | 321 | * @return Error code.
|
---|
| 322 | */
|
---|
[4e8e1f5] | 323 | int usb_device_register_child_in_devman(usb_address_t address,
|
---|
| 324 | devman_handle_t hc_handle,
|
---|
[eb1a2f4] | 325 | ddf_dev_t *parent, devman_handle_t *child_handle,
|
---|
| 326 | ddf_dev_ops_t *dev_ops, void *dev_data, ddf_fun_t **child_fun)
|
---|
[02ccfcd] | 327 | {
|
---|
[38648f0] | 328 | size_t this_device_name_index;
|
---|
| 329 |
|
---|
| 330 | fibril_mutex_lock(&device_name_index_mutex);
|
---|
| 331 | this_device_name_index = device_name_index;
|
---|
| 332 | device_name_index++;
|
---|
| 333 | fibril_mutex_unlock(&device_name_index_mutex);
|
---|
| 334 |
|
---|
[eb1a2f4] | 335 | ddf_fun_t *child = NULL;
|
---|
[7ed5b576] | 336 | char *child_name = NULL;
|
---|
| 337 | int rc;
|
---|
[4e8e1f5] | 338 | usb_device_connection_t dev_connection;
|
---|
| 339 | usb_endpoint_pipe_t ctrl_pipe;
|
---|
| 340 |
|
---|
| 341 | rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
|
---|
| 342 | if (rc != EOK) {
|
---|
| 343 | goto failure;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
|
---|
| 347 | &dev_connection);
|
---|
| 348 | if (rc != EOK) {
|
---|
| 349 | goto failure;
|
---|
| 350 | }
|
---|
[7ed5b576] | 351 |
|
---|
| 352 | /*
|
---|
[b207803] | 353 | * TODO: Once the device driver framework support persistent
|
---|
| 354 | * naming etc., something more descriptive could be created.
|
---|
[7ed5b576] | 355 | */
|
---|
[38648f0] | 356 | rc = asprintf(&child_name, "usbdev%02zu", this_device_name_index);
|
---|
[7ed5b576] | 357 | if (rc < 0) {
|
---|
| 358 | goto failure;
|
---|
| 359 | }
|
---|
[eb1a2f4] | 360 |
|
---|
| 361 | child = ddf_fun_create(parent, fun_inner, child_name);
|
---|
| 362 | if (child == NULL) {
|
---|
| 363 | rc = ENOMEM;
|
---|
| 364 | goto failure;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | if (dev_ops != NULL) {
|
---|
| 368 | child->ops = dev_ops;
|
---|
| 369 | } else {
|
---|
| 370 | child->ops = &child_ops;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | child->driver_data = dev_data;
|
---|
[4e8e1f5] | 374 |
|
---|
| 375 | rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
|
---|
| 376 | if (rc != EOK) {
|
---|
| 377 | goto failure;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids);
|
---|
| 381 | if (rc != EOK) {
|
---|
| 382 | goto failure;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
|
---|
[7ed5b576] | 386 | if (rc != EOK) {
|
---|
| 387 | goto failure;
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[eb1a2f4] | 390 | rc = ddf_fun_bind(child);
|
---|
[7ed5b576] | 391 | if (rc != EOK) {
|
---|
| 392 | goto failure;
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | if (child_handle != NULL) {
|
---|
| 396 | *child_handle = child->handle;
|
---|
| 397 | }
|
---|
[4e8e1f5] | 398 |
|
---|
[eb1a2f4] | 399 | if (child_fun != NULL) {
|
---|
| 400 | *child_fun = child;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
[7ed5b576] | 403 | return EOK;
|
---|
| 404 |
|
---|
| 405 | failure:
|
---|
| 406 | if (child != NULL) {
|
---|
| 407 | child->name = NULL;
|
---|
| 408 | /* This takes care of match_id deallocation as well. */
|
---|
[eb1a2f4] | 409 | ddf_fun_destroy(child);
|
---|
[7ed5b576] | 410 | }
|
---|
| 411 | if (child_name != NULL) {
|
---|
| 412 | free(child_name);
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | return rc;
|
---|
[02ccfcd] | 416 | }
|
---|
[7ed5b576] | 417 |
|
---|
[02ccfcd] | 418 |
|
---|
| 419 | /**
|
---|
| 420 | * @}
|
---|
| 421 | */
|
---|