Changeset 58b833c in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2010-10-23T13:43:51Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b11576d, c6c389ed
Parents:
667eac4
Message:

More cstyle in devman.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    r667eac4 r58b833c  
    4747}
    4848
    49 static int
    50 devman_devices_compare(unsigned long key[], hash_count_t keys, link_t *item)
     49static int devman_devices_compare(unsigned long key[], hash_count_t keys,
     50    link_t *item)
    5151{
    5252        node_t *dev = hash_table_get_instance(item, node_t, devman_link);
     
    5454}
    5555
    56 static int
    57 devmap_devices_compare(unsigned long key[], hash_count_t keys, link_t *item)
     56static int devmap_devices_compare(unsigned long key[], hash_count_t keys,
     57    link_t *item)
    5858{
    5959        node_t *dev = hash_table_get_instance(item, node_t, devmap_link);
     
    7979/** Allocate and initialize a new driver structure.
    8080 *
    81  * @return              Driver structure.
     81 * @return      Driver structure.
    8282 */
    8383driver_t *create_driver(void)
    84 {       
     84{
    8585        driver_t *res = malloc(sizeof(driver_t));
    8686        if (res != NULL)
     
    9191/** Add a driver to the list of drivers.
    9292 *
    93  * @param drivers_list the list of drivers.
    94  * @param drv the driver's structure.
     93 * @param drivers_list  List of drivers.
     94 * @param drv           Driver structure.
    9595 */
    9696void add_driver(driver_list_t *drivers_list, driver_t *drv)
     
    9999        list_prepend(&drv->drivers, &drivers_list->drivers);
    100100        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    101        
     101
    102102        printf(NAME": the '%s' driver was added to the list of available "
    103103            "drivers.\n", drv->name);
     
    218218                    "'%s'.\n", conf_path);
    219219                goto cleanup;
    220         }       
    221        
    222         if (0 >= read(fd, buf, len)) {
     220        }
     221       
     222        if (read(fd, buf, len) <= 0) {
    223223                printf(NAME ": unable to read file '%s'.\n", conf_path);
    224224                goto cleanup;
     
    231231        free(buf);
    232232       
    233         if(opened)
     233        if (opened)
    234234                close(fd);
    235235       
     
    270270        /* Read the list of match ids from the driver's configuration file. */
    271271        match_path = get_abs_path(base_path, name, MATCH_EXT);
    272         if (NULL == match_path)
     272        if (match_path == NULL)
    273273                goto cleanup;
    274274       
     
    279279        name_size = str_size(name) + 1;
    280280        drv->name = malloc(name_size);
    281         if (!drv->name)
     281        if (drv->name == NULL)
    282282                goto cleanup;
    283283        str_cpy(drv->name, name_size, name);
     
    285285        /* Initialize path with driver's binary. */
    286286        drv->binary_path = get_abs_path(base_path, name, "");
    287         if (NULL == drv->binary_path)
     287        if (drv->binary_path == NULL)
    288288                goto cleanup;
    289289       
    290290        /* Check whether the driver's binary exists. */
    291291        struct stat s;
    292         if (stat(drv->binary_path, &s) == ENOENT) {
     292        if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
    293293                printf(NAME ": driver not found at path %s.", drv->binary_path);
    294294                goto cleanup;
     
    344344/** Create root device node in the device tree.
    345345 *
    346  * @param tree          The device tree.
    347  * @return              True on success, false otherwise.
     346 * @param tree  The device tree.
     347 * @return      True on success, false otherwise.
    348348 */
    349349bool create_root_node(dev_tree_t *tree)
    350350{
     351        node_t *node;
     352
    351353        printf(NAME ": create_root_node\n");
    352         node_t *node = create_dev_node();
    353         if (node) {
     354
     355        node = create_dev_node();
     356        if (node != NULL) {
    354357                insert_dev_node(tree, node, clone_string(""), NULL);
    355358                match_id_t *id = create_match_id();
     
    359362                tree->root_node = node;
    360363        }
     364
    361365        return node != NULL;
    362366}
     
    391395                        best_score = score;
    392396                        best_drv = drv;
    393                 }       
     397                }
    394398                link = link->next;
    395399        }
     
    436440       
    437441        int err;
    438         if (!task_spawn(drv->binary_path, argv, &err)) {
     442        if (task_spawn(drv->binary_path, argv, &err) == 0) {
    439443                printf(NAME ": error spawning %s, errno = %d\n",
    440444                    drv->name, err);
     
    456460{
    457461        driver_t *res = NULL;
     462        driver_t *drv = NULL;
     463        link_t *link;
    458464       
    459465        fibril_mutex_lock(&drv_list->drivers_mutex);
    460466       
    461         driver_t *drv = NULL;
    462         link_t *link = drv_list->drivers.next;
    463         while (link !=  &drv_list->drivers) {
     467        link = drv_list->drivers.next;
     468        while (link != &drv_list->drivers) {
    464469                drv = list_get_instance(link, driver_t, drivers);
    465                 if (0 == str_cmp(drv->name, drv_name)) {
     470                if (str_cmp(drv->name, drv_name) == 0) {
    466471                        res = drv;
    467472                        break;
    468                 }               
     473                }
     474
    469475                link = link->next;
    470         }       
     476        }
    471477       
    472478        fibril_mutex_unlock(&drv_list->drivers_mutex);
     
    483489{
    484490        fibril_mutex_lock(&driver->driver_mutex);
    485         assert(DRIVER_STARTING == driver->state);
     491        assert(driver->state == DRIVER_STARTING);
    486492        driver->phone = phone;
    487493        fibril_mutex_unlock(&driver->driver_mutex);
     
    496502static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    497503{
    498         printf(NAME ": pass_devices_to_driver\n");
    499504        node_t *dev;
    500505        link_t *link;
    501        
    502         int phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
    503        
    504         if (0 < phone) {
     506        int phone;
     507
     508        printf(NAME ": pass_devices_to_driver\n");
     509
     510        phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
     511        if (phone > 0) {
    505512               
    506513                link = driver->devices.next;
     
    549556       
    550557        asprintf(&devmap_name, "%s", node->pathname);
    551         if (NULL == devmap_name)
     558        if (devmap_name == NULL)
    552559                return;
    553560       
     
    556563        asprintf(&devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE,
    557564            devmap_name);
    558         if (NULL == devmap_pathname) {
     565        if (devmap_pathname == NULL) {
    559566                free(devmap_name);
    560567                return;
     
    623630         */
    624631        driver_t *drv = find_best_match_driver(drivers_list, node);
    625         if (NULL == drv) {
     632        if (drv == NULL) {
    626633                printf(NAME ": no driver found for device '%s'.\n",
    627634                    node->pathname);
     
    632639        attach_driver(node, drv);
    633640       
    634         if (DRIVER_NOT_STARTED == drv->state) {
     641        if (drv->state == DRIVER_NOT_STARTED) {
    635642                /* Start the driver. */
    636643                start_driver(drv);
    637644        }
    638645       
    639         if (DRIVER_RUNNING == drv->state) {
     646        if (drv->state == DRIVER_RUNNING) {
    640647                /* Notify the driver about the new device. */
    641648                int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
     
    687694static bool set_dev_path(node_t *node, node_t *parent)
    688695{
    689         assert(NULL != node->name);
     696        assert(node->name != NULL);
    690697       
    691698        size_t pathsize = (str_size(node->name) + 1);
    692         if (NULL != parent)
     699        if (parent != NULL)
    693700                pathsize += str_size(parent->pathname) + 1;
    694701       
    695702        node->pathname = (char *) malloc(pathsize);
    696         if (NULL == node->pathname) {
     703        if (node->pathname == NULL) {
    697704                printf(NAME ": failed to allocate device path.\n");
    698705                return false;
    699706        }
    700707       
    701         if (NULL != parent) {
     708        if (parent != NULL) {
    702709                str_cpy(node->pathname, pathsize, parent->pathname);
    703710                str_append(node->pathname, pathsize, "/");
     
    719726 * @param dev_name      The name of the newly added device.
    720727 * @param parent        The parent device node.
     728 *
    721729 * @return              True on success, false otherwise (insufficient resources
    722730 *                      etc.).
    723731 */
    724 bool
    725 insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent)
    726 {
    727         assert(NULL != node && NULL != tree && NULL != dev_name);
     732bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name,
     733    node_t *parent)
     734{
     735        assert(node != NULL);
     736        assert(tree != NULL);
     737        assert(dev_name != NULL);
    728738       
    729739        node->name = dev_name;
     
    740750        /* Add the node to the list of its parent's children. */
    741751        node->parent = parent;
    742         if (NULL != parent)
     752        if (parent != NULL)
    743753                list_append(&node->sibling, &parent->children);
    744754       
     
    764774        char *rel_path = path;
    765775        char *next_path_elem = NULL;
    766         bool cont = '/' == rel_path[0];
    767        
    768         while (cont && NULL != dev) {
     776        bool cont = (rel_path[0] == '/');
     777       
     778        while (cont && dev != NULL) {
    769779                next_path_elem  = get_path_elem_end(rel_path + 1);
    770                 if ('/' == next_path_elem[0]) {
     780                if (next_path_elem[0] == '/') {
    771781                        cont = true;
    772782                        next_path_elem[0] = 0;
     
    807817                dev = list_get_instance(link, node_t, sibling);
    808818               
    809                 if (0 == str_cmp(name, dev->name))
     819                if (str_cmp(name, dev->name) == 0)
    810820                        return dev;
    811821               
     
    829839        const char *base_name;
    830840       
    831         if (NULL != base_dev_name)
     841        if (base_dev_name != NULL)
    832842                base_name = base_dev_name;
    833843        else
     
    853863 *                      with the class.
    854864 */
    855 dev_class_info_t *
    856 add_device_to_class(node_t *dev, dev_class_t *cl, const char *base_dev_name)
     865dev_class_info_t *add_device_to_class(node_t *dev, dev_class_t *cl,
     866    const char *base_dev_name)
    857867{
    858868        dev_class_info_t *info = create_dev_class_info();
    859869       
    860         if (NULL != info) {
     870        if (info != NULL) {
    861871                info->dev_class = cl;
    862872                info->dev = dev;
     
    883893        fibril_rwlock_write_lock(&class_list->rwlock);
    884894        cl = find_dev_class_no_lock(class_list, class_name);
    885         if (NULL == cl) {
     895        if (cl == NULL) {
    886896                cl = create_dev_class();
    887                 if (NULL != cl) {
     897                if (cl != NULL) {
    888898                        cl->name = class_name;
    889899                        cl->base_dev_name = "";
     
    891901                }
    892902        }
     903
    893904        fibril_rwlock_write_unlock(&class_list->rwlock);
    894905        return cl;
    895906}
    896907
    897 dev_class_t *
    898 find_dev_class_no_lock(class_list_t *class_list, const char *class_name)
     908dev_class_t *find_dev_class_no_lock(class_list_t *class_list,
     909    const char *class_name)
    899910{
    900911        dev_class_t *cl;
     
    903914        while (link != &class_list->classes) {
    904915                cl = list_get_instance(link, dev_class_t, link);
    905                 if (0 == str_cmp(cl->name, class_name))
     916                if (str_cmp(cl->name, class_name) == 0)
    906917                        return cl;
    907918        }
     
    929940        fibril_rwlock_read_lock(&tree->rwlock);
    930941        link = hash_table_find(&tree->devmap_devices, &key);
    931         if (NULL != link)
     942        if (link != NULL)
    932943                dev = hash_table_get_instance(link, node_t, devmap_link);
    933944        fibril_rwlock_read_unlock(&tree->rwlock);
     
    936947}
    937948
    938 node_t *
    939 find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle)
     949node_t *find_devmap_class_device(class_list_t *classes,
     950    dev_handle_t devmap_handle)
    940951{
    941952        node_t *dev = NULL;
     
    946957        fibril_rwlock_read_lock(&classes->rwlock);
    947958        link = hash_table_find(&classes->devmap_devices, &key);
    948         if (NULL != link) {
     959        if (link != NULL) {
    949960                cli = hash_table_get_instance(link, dev_class_info_t,
    950961                    devmap_link);
Note: See TracChangeset for help on using the changeset viewer.