Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/recognise.c

    r56fd7cf r6e3c005  
    3333 * Functions for recognition of attached devices.
    3434 */
    35 
    36 /** XXX Fix this */
    37 #define _DDF_DATA_IMPLANT
    38 
    3935#include <sys/types.h>
    4036#include <fibril_synch.h>
     
    315311 *      will be written.
    316312 * @return Error code.
    317  *
    318313 */
    319314int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,
     
    323318        if (child_fun == NULL || ctrl_pipe == NULL)
    324319                return EINVAL;
    325        
     320
    326321        if (!dev_ops && dev_data) {
    327322                usb_log_warning("Using standard fun ops with arbitrary "
    328323                    "driver data. This does not have to work.\n");
    329324        }
    330        
     325
    331326        /** Index to append after device name for uniqueness. */
    332327        static atomic_t device_name_index = {0};
    333328        const size_t this_device_name_index =
    334329            (size_t) atomic_preinc(&device_name_index);
    335        
     330
    336331        ddf_fun_t *child = NULL;
    337332        int rc;
    338        
     333
    339334        /*
    340335         * TODO: Once the device driver framework support persistent
    341336         * naming etc., something more descriptive could be created.
    342337         */
    343         char child_name[12];  /* The format is: "usbAB_aXYZ", length 11 */
     338        char child_name[12]; /* The format is: "usbAB_aXYZ", length 11 */
    344339        rc = snprintf(child_name, sizeof(child_name),
    345340            "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address);
     
    347342                goto failure;
    348343        }
    349        
     344
    350345        child = ddf_fun_create(parent, fun_inner, child_name);
    351346        if (child == NULL) {
     
    353348                goto failure;
    354349        }
    355        
    356         if (dev_ops != NULL)
    357                 ddf_fun_set_ops(child, dev_ops);
    358         else
    359                 ddf_fun_set_ops(child, &child_ops);
    360        
    361         ddf_fun_data_implant(child, dev_data);
    362        
    363         /*
    364          * Store the attached device in fun
    365          * driver data if there is no other data
    366          */
     350
     351        if (dev_ops != NULL) {
     352                child->ops = dev_ops;
     353        } else {
     354                child->ops = &child_ops;
     355        }
     356
     357        child->driver_data = dev_data;
     358        /* Store the attached device in fun driver data if there is no
     359         * other data */
    367360        if (!dev_data) {
    368361                usb_hub_attached_device_t *new_device = ddf_fun_data_alloc(
     
    372365                        goto failure;
    373366                }
    374                
    375367                new_device->address = ctrl_pipe->wire->address;
    376368                new_device->fun = child;
    377369        }
    378        
    379         match_id_list_t match_ids;
    380         init_match_ids(&match_ids);
    381         rc = usb_device_create_match_ids(ctrl_pipe, &match_ids);
    382         if (rc != EOK)
     370
     371
     372        rc = usb_device_create_match_ids(ctrl_pipe, &child->match_ids);
     373        if (rc != EOK) {
    383374                goto failure;
    384        
    385         list_foreach(match_ids.ids, id_link) {
    386                 match_id_t *match_id = list_get_instance(id_link, match_id_t, link);
    387                 rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
    388                 if (rc != EOK) {
    389                         clean_match_ids(&match_ids);
    390                         goto failure;
    391                 }
    392         }
    393        
    394         clean_match_ids(&match_ids);
    395        
     375        }
     376
    396377        rc = ddf_fun_bind(child);
    397         if (rc != EOK)
     378        if (rc != EOK) {
    398379                goto failure;
    399        
     380        }
     381
    400382        *child_fun = child;
    401383        return EOK;
    402        
     384
    403385failure:
    404386        if (child != NULL) {
     387                /* We know nothing about the data if it came from outside. */
     388                if (dev_data) {
     389                        child->driver_data = NULL;
     390                }
    405391                /* This takes care of match_id deallocation as well. */
    406392                ddf_fun_destroy(child);
    407393        }
    408        
     394
    409395        return rc;
    410396}
    411397
     398
    412399/**
    413400 * @}
Note: See TracChangeset for help on using the changeset viewer.