Changeset 58b833c in mainline


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.

Location:
uspace/srv/devman
Files:
2 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);
  • uspace/srv/devman/devman.h

    r667eac4 r58b833c  
    222222} dev_class_t;
    223223
    224 /** Provides n-to-m mapping between device nodes and classes - each device may
     224/**
     225 * Provides n-to-m mapping between device nodes and classes - each device may
    225226 * be register to the arbitrary number of classes and each class may contain
    226227 * the arbitrary number of devices.
     
    290291static inline void init_driver_list(driver_list_t *drv_list)
    291292{
    292         assert(NULL != drv_list);
     293        assert(drv_list != NULL);
    293294       
    294295        list_initialize(&drv_list->drivers);
     
    348349static inline void delete_driver(driver_t *drv)
    349350{
    350         assert(NULL != drv);
     351        assert(drv != NULL);
    351352       
    352353        clean_driver(drv);
     
    382383{
    383384        assert(list_empty(&node->children));
    384         assert(NULL == node->parent);
    385         assert(NULL == node->drv);
     385        assert(node->parent == NULL);
     386        assert(node->drv == NULL);
    386387       
    387388        clean_match_ids(&node->match_ids);
     
    399400 * @return              The device node.
    400401 */
    401 static inline node_t *
    402 find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
     402static inline node_t *find_dev_node_no_lock(dev_tree_t *tree,
     403    device_handle_t handle)
    403404{
    404405        unsigned long key = handle;
     
    413414 * @return              The device node.
    414415 */
    415 static inline node_t *
    416 find_dev_node(dev_tree_t *tree, device_handle_t handle)
     416static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
    417417{
    418418        node_t *node = NULL;
     
    440440/** Create device class.
    441441 *
    442  * @return              Device class.
     442 * @return      Device class.
    443443 */
    444444static inline dev_class_t *create_dev_class(void)
     
    447447       
    448448        cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    449         if (NULL != cl) {
     449        if (cl != NULL) {
    450450                memset(cl, 0, sizeof(dev_class_t));
    451451                list_initialize(&cl->devices);
     
    465465       
    466466        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    467         if (NULL != info)
     467        if (info != NULL)
    468468                memset(info, 0, sizeof(dev_class_info_t));
    469469       
     
    491491extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
    492492
    493 static inline void
    494 add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
     493static inline void add_dev_class_no_lock(class_list_t *class_list,
     494    dev_class_t *cl)
    495495{
    496496        list_append(&cl->link, &class_list->classes);
     
    503503extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
    504504
    505 static inline void
    506 class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     505static inline void class_add_devmap_device(class_list_t *class_list,
     506    dev_class_info_t *cli)
    507507{
    508508        unsigned long key = (unsigned long) cli->devmap_handle;
Note: See TracChangeset for help on using the changeset viewer.