Changeset a35b458 in mainline for uspace/srv/devman


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/srv/devman
Files:
11 edited

Legend:

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

    r3061bc1 ra35b458  
    6565        char *pathname;
    6666        devman_handle_t handle;
    67        
     67
    6868        errno_t rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0);
    6969        if (rc != EOK) {
     
    7171                return;
    7272        }
    73        
     73
    7474        fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname);
    75        
     75
    7676        free(pathname);
    7777
     
    306306                return;
    307307        }
    308        
     308
    309309        fibril_rwlock_read_lock(&device_tree.rwlock);
    310        
     310
    311311        /* Check function state */
    312312        if (fun->state == FUN_REMOVED) {
     
    319319                return;
    320320        }
    321        
     321
    322322        size_t sent_length = str_size(fun->pathname);
    323323        if (sent_length > data_len) {
     
    337337{
    338338        dev_node_t *dev;
    339        
     339
    340340        fibril_rwlock_read_lock(&device_tree.rwlock);
    341        
     341
    342342        dev = find_dev_node_no_lock(&device_tree, IPC_GET_ARG1(*icall));
    343343        if (dev == NULL || dev->state == DEVICE_REMOVED) {
     
    346346                return;
    347347        }
    348        
     348
    349349        if (dev->pfun == NULL) {
    350350                fibril_rwlock_read_unlock(&device_tree.rwlock);
     
    352352                return;
    353353        }
    354        
     354
    355355        async_answer_1(iid, EOK, dev->pfun->handle);
    356        
     356
    357357        fibril_rwlock_read_unlock(&device_tree.rwlock);
    358358}
     
    364364        size_t act_size;
    365365        errno_t rc;
    366        
     366
    367367        if (!async_data_read_receive(&callid, &size)) {
    368368                async_answer_0(callid, EREFUSED);
     
    370370                return;
    371371        }
    372        
     372
    373373        fibril_rwlock_read_lock(&device_tree.rwlock);
    374        
     374
    375375        dev_node_t *dev = find_dev_node_no_lock(&device_tree,
    376376            IPC_GET_ARG1(*icall));
     
    381381                return;
    382382        }
    383        
     383
    384384        devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size);
    385385        if (hdl_buf == NULL) {
     
    389389                return;
    390390        }
    391        
     391
    392392        rc = dev_get_functions(&device_tree, dev, hdl_buf, size, &act_size);
    393393        if (rc != EOK) {
     
    397397                return;
    398398        }
    399        
    400         fibril_rwlock_read_unlock(&device_tree.rwlock);
    401        
     399
     400        fibril_rwlock_read_unlock(&device_tree.rwlock);
     401
    402402        errno_t retval = async_data_read_finalize(callid, hdl_buf, size);
    403403        free(hdl_buf);
    404        
     404
    405405        async_answer_1(iid, retval, act_size);
    406406}
     
    410410{
    411411        fun_node_t *fun;
    412        
     412
    413413        fibril_rwlock_read_lock(&device_tree.rwlock);
    414        
     414
    415415        fun = find_fun_node_no_lock(&device_tree, IPC_GET_ARG1(*icall));
    416416        if (fun == NULL || fun->state == FUN_REMOVED) {
     
    419419                return;
    420420        }
    421        
     421
    422422        if (fun->child == NULL) {
    423423                fibril_rwlock_read_unlock(&device_tree.rwlock);
     
    425425                return;
    426426        }
    427        
     427
    428428        async_answer_1(iid, EOK, fun->child->handle);
    429        
     429
    430430        fibril_rwlock_read_unlock(&device_tree.rwlock);
    431431}
     
    447447                return;
    448448        }
    449        
     449
    450450        rc = driver_fun_online(&device_tree, fun);
    451451        fun_del_ref(fun);
    452        
     452
    453453        async_answer_0(iid, rc);
    454454}
     
    472472                return;
    473473        }
    474        
     474
    475475        rc = driver_fun_offline(&device_tree, fun);
    476476        fun_del_ref(fun);
    477        
     477
    478478        async_answer_0(iid, rc);
    479479}
     
    485485
    486486        fun = find_loc_tree_function(&device_tree, IPC_GET_ARG1(*icall));
    487        
     487
    488488        if (fun == NULL) {
    489489                async_answer_0(iid, ENOENT);
     
    512512        size_t act_size;
    513513        errno_t rc;
    514        
     514
    515515        if (!async_data_read_receive(&callid, &size)) {
    516516                async_answer_0(iid, EREFUSED);
    517517                return;
    518518        }
    519        
     519
    520520        devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size);
    521521        if (hdl_buf == NULL) {
     
    524524                return;
    525525        }
    526        
     526
    527527        rc = driver_get_list(&drivers_list, hdl_buf, size, &act_size);
    528528        if (rc != EOK) {
     
    531531                return;
    532532        }
    533        
     533
    534534        errno_t retval = async_data_read_finalize(callid, hdl_buf, size);
    535535        free(hdl_buf);
    536        
     536
    537537        async_answer_1(iid, retval, act_size);
    538538}
     
    544544        size_t act_size;
    545545        errno_t rc;
    546        
     546
    547547        if (!async_data_read_receive(&callid, &size)) {
    548548                async_answer_0(iid, EREFUSED);
    549549                return;
    550550        }
    551        
     551
    552552        driver_t *drv = driver_find(&drivers_list, IPC_GET_ARG1(*icall));
    553553        if (drv == NULL) {
     
    556556                return;
    557557        }
    558        
     558
    559559        devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size);
    560560        if (hdl_buf == NULL) {
     
    563563                return;
    564564        }
    565        
     565
    566566        rc = driver_get_devices(drv, hdl_buf, size, &act_size);
    567567        if (rc != EOK) {
     
    571571                return;
    572572        }
    573        
     573
    574574        errno_t retval = async_data_read_finalize(callid, hdl_buf, size);
    575575        free(hdl_buf);
    576        
     576
    577577        async_answer_1(iid, retval, act_size);
    578578}
     
    583583{
    584584        char *drvname;
    585        
     585
    586586        errno_t rc = async_data_write_accept((void **) &drvname, true, 0, 0, 0, 0);
    587587        if (rc != EOK) {
     
    589589                return;
    590590        }
    591        
     591
    592592        driver_t *driver = driver_find_by_name(&drivers_list, drvname);
    593        
     593
    594594        free(drvname);
    595        
     595
    596596        if (driver == NULL) {
    597597                async_answer_0(iid, ENOENT);
    598598                return;
    599599        }
    600        
     600
    601601        async_answer_1(iid, EOK, driver->handle);
    602602}
     
    697697{
    698698        driver_t *drv;
    699        
     699
    700700        drv = driver_find(&drivers_list, IPC_GET_ARG1(*icall));
    701701        if (drv == NULL) {
     
    703703                return;
    704704        }
    705        
     705
    706706        async_answer_1(iid, EOK, (sysarg_t) drv->state);
    707707}
     
    712712        driver_t *drv;
    713713        errno_t rc;
    714        
     714
    715715        drv = driver_find(&drivers_list, IPC_GET_ARG1(*icall));
    716716        if (drv == NULL) {
     
    718718                return;
    719719        }
    720        
     720
    721721        fibril_mutex_lock(&drv->driver_mutex);
    722722        rc = start_driver(drv) ? EOK : EIO;
     
    731731        driver_t *drv;
    732732        errno_t rc;
    733        
     733
    734734        drv = driver_find(&drivers_list, IPC_GET_ARG1(*icall));
    735735        if (drv == NULL) {
     
    737737                return;
    738738        }
    739        
     739
    740740        fibril_mutex_lock(&drv->driver_mutex);
    741741        rc = stop_driver(drv);
     
    750750        /* Accept connection. */
    751751        async_answer_0(iid, EOK);
    752        
     752
    753753        while (true) {
    754754                ipc_call_t call;
    755755                ipc_callid_t callid = async_get_call(&call);
    756                
     756
    757757                if (!IPC_GET_IMETHOD(call))
    758758                        break;
    759                
     759
    760760                switch (IPC_GET_IMETHOD(call)) {
    761761                case DEVMAN_DEVICE_GET_HANDLE:
  • uspace/srv/devman/dev.c

    r3061bc1 ra35b458  
    4343{
    4444        dev_node_t *dev;
    45        
     45
    4646        dev = calloc(1, sizeof(dev_node_t));
    4747        if (dev == NULL)
    4848                return NULL;
    49        
     49
    5050        atomic_set(&dev->refcnt, 0);
    5151        list_initialize(&dev->functions);
    5252        link_initialize(&dev->driver_devices);
    53        
     53
    5454        return dev;
    5555}
     
    6464        assert(dev->pfun == NULL);
    6565        assert(dev->drv == NULL);
    66        
     66
    6767        free(dev);
    6868}
     
    9898{
    9999        assert(fibril_rwlock_is_locked(&tree->rwlock));
    100        
     100
    101101        ht_link_t *link = hash_table_find(&tree->devman_devices, &handle);
    102102        if (link == NULL)
    103103                return NULL;
    104        
     104
    105105        return hash_table_get_inst(link, dev_node_t, devman_dev);
    106106}
     
    115115{
    116116        dev_node_t *dev = NULL;
    117        
     117
    118118        fibril_rwlock_read_lock(&tree->rwlock);
    119119        dev = find_dev_node_no_lock(tree, handle);
    120120        if (dev != NULL)
    121121                dev_add_ref(dev);
    122        
     122
    123123        fibril_rwlock_read_unlock(&tree->rwlock);
    124        
     124
    125125        return dev;
    126126}
  • uspace/srv/devman/devman.h

    r3061bc1 ra35b458  
    6868        /** Handle */
    6969        devman_handle_t handle;
    70        
     70
    7171        /**
    7272         * Specifies whether the driver has been started and wheter is running
     
    7474         */
    7575        driver_state_t state;
    76        
     76
    7777        /** Session asociated with this driver. */
    7878        async_sess_t *sess;
     
    8585        /** List of devices controlled by this driver. */
    8686        list_t devices;
    87        
     87
    8888        /**
    8989         * Fibril mutex for this driver - driver state, list of devices, session.
     
    116116        /** Reference count */
    117117        atomic_t refcnt;
    118        
     118
    119119        /** The global unique identifier of the device. */
    120120        devman_handle_t handle;
    121        
     121
    122122        /** (Parent) function the device is attached to. */
    123123        fun_node_t *pfun;
    124        
     124
    125125        /** List of device functions. */
    126126        list_t functions;
     
    131131        /** Link to list of devices owned by driver (driver_t.devices) */
    132132        link_t driver_devices;
    133        
     133
    134134        /**
    135135         * Used by the hash table of devices indexed by devman device handles.
    136136         */
    137137        ht_link_t devman_dev;
    138        
     138
    139139        /**
    140140         * Whether this device was already passed to the driver.
     
    160160        /** Locked while performing reconfiguration operations */
    161161        fibril_mutex_t busy_lock;
    162        
     162
    163163        /** The global unique identifier of the function */
    164164        devman_handle_t handle;
     
    167167        /** Function type */
    168168        fun_type_t ftype;
    169        
     169
    170170        /** Full path and name of the device in device hierarchy */
    171171        char *pathname;
    172        
     172
    173173        /** Device which this function belongs to */
    174174        dev_node_t *dev;
    175        
     175
    176176        /** Link to list of functions in the device (ddf_dev_t.functions) */
    177177        link_t dev_functions;
    178        
     178
    179179        /** Child device node (if any attached). */
    180180        dev_node_t *child;
    181181        /** List of device ids for device-to-driver matching. */
    182182        match_id_list_t match_ids;
    183        
     183
    184184        /** Service ID if the device function is registered with loc. */
    185185        service_id_t service_id;
    186        
     186
    187187        /**
    188188         * Used by the hash table of functions indexed by devman device handles.
    189189         */
    190190        ht_link_t devman_fun;
    191        
     191
    192192        /**
    193193         * Used by the hash table of functions indexed by service IDs.
     
    200200        /** Root device node. */
    201201        fun_node_t *root_node;
    202        
     202
    203203        /**
    204204         * The next available handle - handles are assigned in a sequential
     
    206206         */
    207207        devman_handle_t current_handle;
    208        
     208
    209209        /** Synchronize access to the device tree. */
    210210        fibril_rwlock_t rwlock;
    211        
     211
    212212        /** Hash table of all devices indexed by devman handles. */
    213213        hash_table_t devman_devices;
    214        
     214
    215215        /** Hash table of all devices indexed by devman handles. */
    216216        hash_table_t devman_functions;
    217        
     217
    218218        /**
    219219         * Hash table of services registered with location service, indexed by
  • uspace/srv/devman/devtree.c

    r3061bc1 ra35b458  
    127127        fun_node_t *fun;
    128128        dev_node_t *dev;
    129        
     129
    130130        log_msg(LOG_DEFAULT, LVL_DEBUG, "create_root_nodes()");
    131        
     131
    132132        fibril_rwlock_write_lock(&tree->rwlock);
    133        
     133
    134134        /*
    135135         * Create root function. This is a pseudo function to which
     
    138138         * the parent function.
    139139         */
    140        
     140
    141141        fun = create_fun_node();
    142142        if (fun == NULL) {
     
    144144                return false;
    145145        }
    146        
     146
    147147        fun_add_ref(fun);
    148148        insert_fun_node(tree, fun, str_dup(""), NULL);
    149        
     149
    150150        match_id_t *id = create_match_id();
    151151        id->id = str_dup("root");
     
    153153        add_match_id(&fun->match_ids, id);
    154154        tree->root_node = fun;
    155        
     155
    156156        /*
    157157         * Create root device node.
     
    162162                return false;
    163163        }
    164        
     164
    165165        dev_add_ref(dev);
    166166        insert_dev_node(tree, dev, fun);
    167        
     167
    168168        fibril_rwlock_write_unlock(&tree->rwlock);
    169        
     169
    170170        return dev != NULL;
    171171}
     
    182182{
    183183        log_msg(LOG_DEFAULT, LVL_DEBUG, "init_device_tree()");
    184        
     184
    185185        tree->current_handle = 0;
    186        
     186
    187187        hash_table_create(&tree->devman_devices, 0, 0, &devman_devices_ops);
    188188        hash_table_create(&tree->devman_functions, 0, 0, &devman_functions_ops);
    189189        hash_table_create(&tree->loc_functions, 0, 0, &loc_devices_ops);
    190        
     190
    191191        fibril_rwlock_initialize(&tree->rwlock);
    192        
     192
    193193        /* Create root function and root device and add them to the device tree. */
    194194        if (!create_root_nodes(tree))
    195195                return false;
    196    
     196
    197197        /* Find suitable driver and start it. */
    198198        dev_node_t *rdev = tree->root_node->child;
     
    200200        bool rc = assign_driver(rdev, drivers_list, tree);
    201201        dev_del_ref(rdev);
    202        
     202
    203203        return rc;
    204204}
     
    216216{
    217217        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    218        
     218
    219219        log_msg(LOG_DEFAULT, LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])",
    220220            dev, pfun, pfun->pathname);
     
    227227        dev->pfun = pfun;
    228228        pfun->child = dev;
    229        
     229
    230230        return true;
    231231}
     
    239239{
    240240        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    241        
     241
    242242        log_msg(LOG_DEFAULT, LVL_DEBUG, "remove_dev_node(dev=%p)", dev);
    243        
     243
    244244        /* Remove node from the handle-to-node map. */
    245245        hash_table_remove(&tree->devman_devices, &dev->handle);
    246        
     246
    247247        /* Unlink from parent function. */
    248248        dev->pfun->child = NULL;
    249249        dev->pfun = NULL;
    250        
     250
    251251        dev->state = DEVICE_REMOVED;
    252252}
     
    267267{
    268268        fun_node_t *pfun;
    269        
     269
    270270        assert(fun_name != NULL);
    271271        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    272        
     272
    273273        /*
    274274         * The root function is a special case, it does not belong to any
     
    276276         */
    277277        pfun = (dev != NULL) ? dev->pfun : NULL;
    278        
     278
    279279        fun->name = fun_name;
    280280        if (!set_fun_path(tree, fun, pfun)) {
    281281                return false;
    282282        }
    283        
     283
    284284        /* Add the node to the handle-to-node map. */
    285285        fun->handle = ++tree->current_handle;
     
    290290        if (dev != NULL)
    291291                list_append(&fun->dev_functions, &dev->functions);
    292        
     292
    293293        return true;
    294294}
     
    302302{
    303303        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    304        
     304
    305305        /* Remove the node from the handle-to-node map. */
    306306        hash_table_remove(&tree->devman_functions, &fun->handle);
    307        
     307
    308308        /* Remove the node from the list of its parent's children. */
    309309        if (fun->dev != NULL)
    310310                list_remove(&fun->dev_functions);
    311        
     311
    312312        fun->dev = NULL;
    313313        fun->state = FUN_REMOVED;
  • uspace/srv/devman/driver.c

    r3061bc1 ra35b458  
    5454{
    5555        assert(drv_list != NULL);
    56        
     56
    5757        list_initialize(&drv_list->drivers);
    5858        fibril_mutex_initialize(&drv_list->drivers_mutex);
     
    112112        log_msg(LOG_DEFAULT, LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")",
    113113            base_path, name);
    114        
     114
    115115        assert(base_path != NULL && name != NULL && drv != NULL);
    116        
     116
    117117        bool suc = false;
    118118        char *match_path = NULL;
    119119        size_t name_size = 0;
    120        
     120
    121121        /* Read the list of match ids from the driver's configuration file. */
    122122        match_path = get_abs_path(base_path, name, MATCH_EXT);
    123123        if (match_path == NULL)
    124124                goto cleanup;
    125        
     125
    126126        if (!read_match_ids(match_path, &drv->match_ids))
    127127                goto cleanup;
    128        
     128
    129129        /* Allocate and fill driver's name. */
    130130        name_size = str_size(name) + 1;
     
    133133                goto cleanup;
    134134        str_cpy(drv->name, name_size, name);
    135        
     135
    136136        /* Initialize path with driver's binary. */
    137137        drv->binary_path = get_abs_path(base_path, name, "");
    138138        if (drv->binary_path == NULL)
    139139                goto cleanup;
    140        
     140
    141141        /* Check whether the driver's binary exists. */
    142142        vfs_stat_t s;
     
    146146                goto cleanup;
    147147        }
    148        
     148
    149149        suc = true;
    150        
     150
    151151cleanup:
    152152        if (!suc) {
     
    156156                init_driver(drv);
    157157        }
    158        
     158
    159159        free(match_path);
    160        
     160
    161161        return suc;
    162162}
     
    171171{
    172172        log_msg(LOG_DEFAULT, LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path);
    173        
     173
    174174        int drv_cnt = 0;
    175175        DIR *dir = NULL;
     
    177177
    178178        dir = opendir(dir_path);
    179        
     179
    180180        if (dir != NULL) {
    181181                driver_t *drv = create_driver();
     
    190190                closedir(dir);
    191191        }
    192        
     192
    193193        return drv_cnt;
    194194}
     
    213213        driver_t *best_drv = NULL;
    214214        int best_score = 0, score = 0;
    215        
     215
    216216        fibril_mutex_lock(&drivers_list->drivers_mutex);
    217        
     217
    218218        list_foreach(drivers_list->drivers, drivers, driver_t, drv) {
    219219                score = get_match_score(drv, node);
     
    223223                }
    224224        }
    225        
     225
    226226        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    227        
     227
    228228        return best_drv;
    229229}
     
    239239        log_msg(LOG_DEFAULT, LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")",
    240240            dev->pfun->pathname, drv->name);
    241        
     241
    242242        fibril_mutex_lock(&drv->driver_mutex);
    243243        fibril_rwlock_write_lock(&tree->rwlock);
    244        
     244
    245245        dev->drv = drv;
    246246        list_append(&dev->driver_devices, &drv->devices);
    247        
     247
    248248        fibril_rwlock_write_unlock(&tree->rwlock);
    249249        fibril_mutex_unlock(&drv->driver_mutex);
     
    259259{
    260260        driver_t *drv = dev->drv;
    261        
     261
    262262        assert(drv != NULL);
    263        
     263
    264264        log_msg(LOG_DEFAULT, LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")",
    265265            dev->pfun->pathname, drv->name);
    266        
     266
    267267        fibril_mutex_lock(&drv->driver_mutex);
    268268        fibril_rwlock_write_lock(&tree->rwlock);
    269        
     269
    270270        dev->drv = NULL;
    271271        list_remove(&dev->driver_devices);
    272        
     272
    273273        fibril_rwlock_write_unlock(&tree->rwlock);
    274274        fibril_mutex_unlock(&drv->driver_mutex);
     
    286286
    287287        assert(fibril_mutex_is_locked(&drv->driver_mutex));
    288        
     288
    289289        log_msg(LOG_DEFAULT, LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name);
    290        
     290
    291291        rc = task_spawnl(NULL, NULL, drv->binary_path, drv->binary_path, NULL);
    292292        if (rc != EOK) {
     
    295295                return false;
    296296        }
    297        
     297
    298298        drv->state = DRIVER_STARTING;
    299299        return true;
     
    310310        async_exch_t *exch;
    311311        errno_t retval;
    312        
     312
    313313        log_msg(LOG_DEFAULT, LVL_DEBUG, "stop_driver(drv=\"%s\")", drv->name);
    314314
     
    316316        retval = async_req_0_0(exch, DRIVER_STOP);
    317317        loc_exchange_end(exch);
    318        
     318
    319319        if (retval != EOK)
    320320                return retval;
    321        
     321
    322322        drv->state = DRIVER_NOT_STARTED;
    323323        async_hangup(drv->sess);
     
    336336{
    337337        driver_t *res = NULL;
    338        
     338
    339339        fibril_mutex_lock(&drv_list->drivers_mutex);
    340        
     340
    341341        list_foreach(drv_list->drivers, drivers, driver_t, drv) {
    342342                if (drv->handle == handle) {
     
    345345                }
    346346        }
    347        
     347
    348348        fibril_mutex_unlock(&drv_list->drivers_mutex);
    349        
     349
    350350        return res;
    351351}
     
    362362{
    363363        driver_t *res = NULL;
    364        
     364
    365365        fibril_mutex_lock(&drv_list->drivers_mutex);
    366        
     366
    367367        list_foreach(drv_list->drivers, drivers, driver_t, drv) {
    368368                if (str_cmp(drv->name, drv_name) == 0) {
     
    371371                }
    372372        }
    373        
     373
    374374        fibril_mutex_unlock(&drv_list->drivers_mutex);
    375        
     375
    376376        return res;
    377377}
     
    399399                dev = list_get_instance(link, dev_node_t, driver_devices);
    400400                fibril_rwlock_write_lock(&tree->rwlock);
    401                
     401
    402402                if (dev->passed_to_driver) {
    403403                        fibril_rwlock_write_unlock(&tree->rwlock);
     
    461461        log_msg(LOG_DEFAULT, LVL_DEBUG, "initialize_running_driver(driver=\"%s\")",
    462462            driver->name);
    463        
     463
    464464        /*
    465465         * Pass devices which have been already assigned to the driver to the
     
    507507{
    508508        assert(drv != NULL);
    509        
     509
    510510        clean_driver(drv);
    511511        free(drv);
     
    525525        assert(drivers_list != NULL);
    526526        assert(tree != NULL);
    527        
     527
    528528        /*
    529529         * Find the driver which is the most suitable for handling this device.
     
    535535                return false;
    536536        }
    537        
     537
    538538        /* Attach the driver to the device. */
    539539        attach_driver(tree, dev, drv);
    540        
     540
    541541        fibril_mutex_lock(&drv->driver_mutex);
    542542        if (drv->state == DRIVER_NOT_STARTED) {
     
    550550        if (is_running)
    551551                add_device(drv, dev, tree);
    552        
     552
    553553        fibril_mutex_lock(&drv->driver_mutex);
    554554        fibril_mutex_unlock(&drv->driver_mutex);
     
    575575        log_msg(LOG_DEFAULT, LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")",
    576576            drv->name, dev->pfun->name);
    577        
     577
    578578        /* Send the device to the driver. */
    579579        devman_handle_t parent_handle;
     
    583583                parent_handle = 0;
    584584        }
    585        
     585
    586586        async_exch_t *exch = async_exchange_begin(drv->sess);
    587        
     587
    588588        ipc_call_t answer;
    589589        aid_t req = async_send_2(exch, DRIVER_DEV_ADD, dev->handle,
    590590            parent_handle, &answer);
    591        
     591
    592592        /* Send the device name to the driver. */
    593593        errno_t rc = async_data_write_start(exch, dev->pfun->name,
    594594            str_size(dev->pfun->name) + 1);
    595        
     595
    596596        async_exchange_end(exch);
    597        
     597
    598598        if (rc != EOK) {
    599599                async_forget(req);
     
    614614                break;
    615615        }
    616        
     616
    617617        dev->passed_to_driver = true;
    618618}
     
    624624        driver_t *drv;
    625625        devman_handle_t handle;
    626        
     626
    627627        assert(dev != NULL);
    628        
     628
    629629        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_remove(%p)", dev);
    630        
     630
    631631        fibril_rwlock_read_lock(&tree->rwlock);
    632632        drv = dev->drv;
    633633        handle = dev->handle;
    634634        fibril_rwlock_read_unlock(&tree->rwlock);
    635        
     635
    636636        exch = async_exchange_begin(drv->sess);
    637637        retval = async_req_1_0(exch, DRIVER_DEV_REMOVE, handle);
    638638        async_exchange_end(exch);
    639        
     639
    640640        return retval;
    641641}
     
    647647        driver_t *drv;
    648648        devman_handle_t handle;
    649        
     649
    650650        assert(dev != NULL);
    651        
     651
    652652        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_gone(%p)", dev);
    653        
     653
    654654        fibril_rwlock_read_lock(&tree->rwlock);
    655655        drv = dev->drv;
    656656        handle = dev->handle;
    657657        fibril_rwlock_read_unlock(&tree->rwlock);
    658        
     658
    659659        exch = async_exchange_begin(drv->sess);
    660660        retval = async_req_1_0(exch, DRIVER_DEV_GONE, handle);
    661661        async_exchange_end(exch);
    662        
     662
    663663        return retval;
    664664}
     
    670670        driver_t *drv;
    671671        devman_handle_t handle;
    672        
     672
    673673        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_online(%p)", fun);
    674674
    675675        fibril_rwlock_read_lock(&tree->rwlock);
    676        
     676
    677677        if (fun->dev == NULL) {
    678678                /* XXX root function? */
     
    680680                return EINVAL;
    681681        }
    682        
     682
    683683        drv = fun->dev->drv;
    684684        handle = fun->handle;
    685685        fibril_rwlock_read_unlock(&tree->rwlock);
    686        
     686
    687687        exch = async_exchange_begin(drv->sess);
    688688        retval = async_req_1_0(exch, DRIVER_FUN_ONLINE, handle);
    689689        loc_exchange_end(exch);
    690        
     690
    691691        return retval;
    692692}
     
    698698        driver_t *drv;
    699699        devman_handle_t handle;
    700        
     700
    701701        log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_offline(%p)", fun);
    702702
     
    707707                return EINVAL;
    708708        }
    709        
     709
    710710        drv = fun->dev->drv;
    711711        handle = fun->handle;
    712712        fibril_rwlock_read_unlock(&tree->rwlock);
    713        
     713
    714714        exch = async_exchange_begin(drv->sess);
    715715        retval = async_req_1_0(exch, DRIVER_FUN_OFFLINE, handle);
    716716        loc_exchange_end(exch);
    717        
     717
    718718        return retval;
    719719
  • uspace/srv/devman/drv_conn.c

    r3061bc1 ra35b458  
    7070
    7171        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_driver_register");
    72        
     72
    7373        /* Get driver name. */
    7474        errno_t rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0);
     
    8080        log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s' driver is trying to register.",
    8181            drv_name);
    82        
     82
    8383        /* Find driver structure. */
    8484        driver = driver_find_by_name(&drivers_list, drv_name);
     
    9090                return NULL;
    9191        }
    92        
     92
    9393        free(drv_name);
    9494        drv_name = NULL;
    95        
     95
    9696        fibril_mutex_lock(&driver->driver_mutex);
    97        
     97
    9898        if (driver->sess) {
    9999                /* We already have a connection to the driver. */
     
    104104                return NULL;
    105105        }
    106        
     106
    107107        switch (driver->state) {
    108108        case DRIVER_NOT_STARTED:
     
    119119                assert(false);
    120120        }
    121        
     121
    122122        /* Create connection to the driver. */
    123123        log_msg(LOG_DEFAULT, LVL_DEBUG, "Creating connection to the `%s' driver.",
     
    131131        /* FIXME: Work around problem with callback sessions */
    132132        async_sess_args_set(driver->sess, INTERFACE_DDF_DEVMAN, 0, 0);
    133        
     133
    134134        log_msg(LOG_DEFAULT, LVL_NOTE,
    135135            "The `%s' driver was successfully registered as running.",
    136136            driver->name);
    137        
     137
    138138        /*
    139139         * Initialize the driver as running (e.g. pass assigned devices to it)
     
    149149                return NULL;
    150150        }
    151        
     151
    152152        fibril_add_ready(fid);
    153153        fibril_mutex_unlock(&driver->driver_mutex);
    154        
     154
    155155        async_answer_0(callid, EOK);
    156156        return driver;
     
    169169        ipc_call_t call;
    170170        errno_t rc = 0;
    171        
     171
    172172        callid = async_get_call(&call);
    173173        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
     
    178178                return EINVAL;
    179179        }
    180        
     180
    181181        if (match_id == NULL) {
    182182                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate match id.");
     
    184184                return ENOMEM;
    185185        }
    186        
     186
    187187        async_answer_0(callid, EOK);
    188        
     188
    189189        match_id->score = IPC_GET_ARG1(call);
    190        
     190
    191191        char *match_id_str;
    192192        rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
     
    198198                return rc;
    199199        }
    200        
     200
    201201        list_append(&match_id->link, &match_ids->ids);
    202        
     202
    203203        log_msg(LOG_DEFAULT, LVL_DEBUG, "Received match id `%s', score %d.",
    204204            match_id->id, match_id->score);
     
    218218        errno_t ret = EOK;
    219219        size_t i;
    220        
     220
    221221        for (i = 0; i < match_count; i++) {
    222222                if (EOK != (ret = devman_receive_match_id(match_ids)))
     
    236236        sysarg_t match_count = IPC_GET_ARG3(*call);
    237237        dev_tree_t *tree = &device_tree;
    238        
     238
    239239        dev_node_t *pdev = find_dev_node(&device_tree, dev_handle);
    240240        if (pdev == NULL) {
     
    242242                return;
    243243        }
    244        
     244
    245245        if (ftype != fun_inner && ftype != fun_exposed) {
    246246                /* Unknown function type */
     
    253253                return;
    254254        }
    255        
     255
    256256        char *fun_name = NULL;
    257257        errno_t rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0);
     
    261261                return;
    262262        }
    263        
     263
    264264        fibril_rwlock_write_lock(&tree->rwlock);
    265        
     265
    266266        /* Check device state */
    267267        if (pdev->state == DEVICE_REMOVED) {
     
    271271                return;
    272272        }
    273        
     273
    274274        /* Check that function with same name is not there already. */
    275275        fun_node_t *tfun = find_fun_node_in_device(tree, pdev, fun_name);
     
    284284                return;
    285285        }
    286        
     286
    287287        fun_node_t *fun = create_fun_node();
    288288        /* One reference for creation, one for us */
     
    290290        fun_add_ref(fun);
    291291        fun->ftype = ftype;
    292        
     292
    293293        /*
    294294         * We can lock the function here even when holding the tree because
     
    296296         */
    297297        fun_busy_lock(fun);
    298        
     298
    299299        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    300300                fibril_rwlock_write_unlock(&tree->rwlock);
     
    306306                return;
    307307        }
    308        
     308
    309309        fibril_rwlock_write_unlock(&tree->rwlock);
    310310        dev_del_ref(pdev);
    311        
     311
    312312        devman_receive_match_ids(match_count, &fun->match_ids);
    313        
     313
    314314        rc = fun_online(fun);
    315315        if (rc != EOK) {
     
    320320                return;
    321321        }
    322        
     322
    323323        fun_busy_unlock(fun);
    324324        fun_del_ref(fun);
    325        
     325
    326326        /* Return device handle to parent's driver. */
    327327        async_answer_1(callid, EOK, fun->handle);
     
    333333        category_id_t cat_id;
    334334        errno_t rc;
    335        
     335
    336336        /* Get category name. */
    337337        char *cat_name;
     
    342342                return;
    343343        }
    344        
     344
    345345        fun_node_t *fun = find_fun_node(&device_tree, handle);
    346346        if (fun == NULL) {
     
    348348                return;
    349349        }
    350        
     350
    351351        fibril_rwlock_read_lock(&device_tree.rwlock);
    352        
     352
    353353        /* Check function state */
    354354        if (fun->state == FUN_REMOVED) {
     
    357357                return;
    358358        }
    359        
     359
    360360        rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING);
    361361        if (rc == EOK) {
     
    367367                    "`%s'.", fun->pathname, cat_name);
    368368        }
    369        
     369
    370370        fibril_rwlock_read_unlock(&device_tree.rwlock);
    371371        fun_del_ref(fun);
    372        
     372
    373373        async_answer_0(callid, rc);
    374374}
     
    382382        fun_node_t *fun;
    383383        errno_t rc;
    384        
     384
    385385        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_drv_fun_online()");
    386        
     386
    387387        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
    388388        if (fun == NULL) {
     
    390390                return;
    391391        }
    392        
     392
    393393        fun_busy_lock(fun);
    394        
     394
    395395        fibril_rwlock_read_lock(&device_tree.rwlock);
    396396        if (fun->dev == NULL || fun->dev->drv != drv) {
     
    402402        }
    403403        fibril_rwlock_read_unlock(&device_tree.rwlock);
    404        
     404
    405405        rc = fun_online(fun);
    406406        if (rc != EOK) {
     
    410410                return;
    411411        }
    412        
     412
    413413        fun_busy_unlock(fun);
    414414        fun_del_ref(fun);
    415        
     415
    416416        async_answer_0(iid, EOK);
    417417}
     
    432432                return;
    433433        }
    434        
     434
    435435        fun_busy_lock(fun);
    436        
     436
    437437        fibril_rwlock_write_lock(&device_tree.rwlock);
    438438        if (fun->dev == NULL || fun->dev->drv != drv) {
     
    443443        }
    444444        fibril_rwlock_write_unlock(&device_tree.rwlock);
    445        
     445
    446446        rc = fun_offline(fun);
    447447        if (rc != EOK) {
     
    451451                return;
    452452        }
    453        
     453
    454454        fun_busy_unlock(fun);
    455455        fun_del_ref(fun);
     
    463463        dev_tree_t *tree = &device_tree;
    464464        errno_t rc;
    465        
     465
    466466        fun_node_t *fun = find_fun_node(&device_tree, fun_handle);
    467467        if (fun == NULL) {
     
    469469                return;
    470470        }
    471        
     471
    472472        fun_busy_lock(fun);
    473        
     473
    474474        fibril_rwlock_write_lock(&tree->rwlock);
    475        
     475
    476476        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
    477        
     477
    478478        /* Check function state */
    479479        if (fun->state == FUN_REMOVED) {
     
    484484                return;
    485485        }
    486        
     486
    487487        if (fun->ftype == fun_inner) {
    488488                /* This is a surprise removal. Handle possible descendants */
     
    491491                        device_state_t dev_state;
    492492                        errno_t gone_rc;
    493                        
     493
    494494                        dev_add_ref(dev);
    495495                        dev_state = dev->state;
    496                        
     496
    497497                        fibril_rwlock_write_unlock(&device_tree.rwlock);
    498                        
     498
    499499                        /* If device is owned by driver, inform driver it is gone. */
    500500                        if (dev_state == DEVICE_USABLE)
     
    502502                        else
    503503                                gone_rc = EOK;
    504                        
     504
    505505                        fibril_rwlock_read_lock(&device_tree.rwlock);
    506                        
     506
    507507                        /* Verify that driver succeeded and removed all functions */
    508508                        if (gone_rc != EOK || !list_empty(&dev->functions)) {
     
    510510                                    "functions for device that is gone. "
    511511                                    "Device node is now defunct.");
    512                                
     512
    513513                                /*
    514514                                 * Not much we can do but mark the device
     
    526526                                return;
    527527                        }
    528                        
     528
    529529                        driver_t *driver = dev->drv;
    530530                        fibril_rwlock_read_unlock(&device_tree.rwlock);
    531                        
     531
    532532                        if (driver)
    533533                                detach_driver(&device_tree, dev);
    534                        
     534
    535535                        fibril_rwlock_write_lock(&device_tree.rwlock);
    536536                        remove_dev_node(&device_tree, dev);
    537                        
     537
    538538                        /* Delete ref created when node was inserted */
    539539                        dev_del_ref(dev);
     
    556556                }
    557557        }
    558        
     558
    559559        remove_fun_node(&device_tree, fun);
    560560        fibril_rwlock_write_unlock(&tree->rwlock);
    561561        fun_busy_unlock(fun);
    562        
     562
    563563        /* Delete ref added when inserting function into tree */
    564564        fun_del_ref(fun);
    565565        /* Delete ref added above when looking up function */
    566566        fun_del_ref(fun);
    567        
     567
    568568        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded.");
    569569        async_answer_0(callid, EOK);
     
    578578{
    579579        driver_t *driver = (driver_t *) drv;
    580        
     580
    581581        initialize_running_driver(driver, &device_tree);
    582582        log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s` driver was successfully initialized.",
     
    590590        client_t *client;
    591591        driver_t *driver = NULL;
    592        
     592
    593593        /* Accept the connection. */
    594594        async_answer_0(iid, EOK);
    595        
     595
    596596        client = async_get_client_data();
    597597        if (client == NULL) {
     
    599599                return;
    600600        }
    601        
     601
    602602        while (true) {
    603603                ipc_call_t call;
    604604                ipc_callid_t callid = async_get_call(&call);
    605                
     605
    606606                if (!IPC_GET_IMETHOD(call))
    607607                        break;
    608                
     608
    609609                if (IPC_GET_IMETHOD(call) != DEVMAN_DRIVER_REGISTER) {
    610610                        fibril_mutex_lock(&client->mutex);
     
    617617                        }
    618618                }
    619                
     619
    620620                switch (IPC_GET_IMETHOD(call)) {
    621621                case DEVMAN_DRIVER_REGISTER:
  • uspace/srv/devman/fun.c

    r3061bc1 ra35b458  
    5858        if (fun == NULL)
    5959                return NULL;
    60        
     60
    6161        fun->state = FUN_INIT;
    6262        atomic_set(&fun->refcnt, 0);
     
    6464        link_initialize(&fun->dev_functions);
    6565        list_initialize(&fun->match_ids.ids);
    66        
     66
    6767        return fun;
    6868}
     
    7676        assert(fun->dev == NULL);
    7777        assert(fun->child == NULL);
    78        
     78
    7979        clean_match_ids(&fun->match_ids);
    8080        free(fun->name);
     
    125125{
    126126        fun_node_t *fun;
    127        
     127
    128128        assert(fibril_rwlock_is_locked(&tree->rwlock));
    129        
     129
    130130        ht_link_t *link = hash_table_find(&tree->devman_functions, &handle);
    131131        if (link == NULL)
    132132                return NULL;
    133        
     133
    134134        fun = hash_table_get_inst(link, fun_node_t, devman_fun);
    135        
     135
    136136        return fun;
    137137}
     
    146146{
    147147        fun_node_t *fun = NULL;
    148        
     148
    149149        fibril_rwlock_read_lock(&tree->rwlock);
    150        
     150
    151151        fun = find_fun_node_no_lock(tree, handle);
    152152        if (fun != NULL)
    153153                fun_add_ref(fun);
    154        
     154
    155155        fibril_rwlock_read_unlock(&tree->rwlock);
    156        
     156
    157157        return fun;
    158158}
     
    170170        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    171171        assert(fun->name != NULL);
    172        
     172
    173173        size_t pathsize = (str_size(fun->name) + 1);
    174174        if (parent != NULL)
    175175                pathsize += str_size(parent->pathname) + 1;
    176        
     176
    177177        fun->pathname = (char *) malloc(pathsize);
    178178        if (fun->pathname == NULL) {
     
    180180                return false;
    181181        }
    182        
     182
    183183        if (parent != NULL) {
    184184                str_cpy(fun->pathname, pathsize, parent->pathname);
     
    188188                str_cpy(fun->pathname, pathsize, fun->name);
    189189        }
    190        
     190
    191191        return true;
    192192}
     
    209209
    210210        fibril_rwlock_read_lock(&tree->rwlock);
    211        
     211
    212212        fun_node_t *fun = tree->root_node;
    213213        fun_add_ref(fun);
     
    219219        char *next_path_elem = NULL;
    220220        bool cont = (rel_path[1] != '\0');
    221        
     221
    222222        while (cont && fun != NULL) {
    223223                next_path_elem  = get_path_elem_end(rel_path + 1);
     
    228228                        cont = false;
    229229                }
    230                
     230
    231231                fun_node_t *cfun = find_node_child(tree, fun, rel_path + 1);
    232232                fun_del_ref(fun);
    233233                fun = cfun;
    234                
     234
    235235                if (cont) {
    236236                        /* Restore the original path. */
     
    239239                rel_path = next_path_elem;
    240240        }
    241        
     241
    242242        fibril_rwlock_read_unlock(&tree->rwlock);
    243        
     243
    244244        return fun;
    245245}
     
    299299{
    300300        dev_node_t *dev;
    301        
     301
    302302        fibril_rwlock_write_lock(&device_tree.rwlock);
    303        
     303
    304304        if (fun->state == FUN_ON_LINE) {
    305305                fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    308308                return EOK;
    309309        }
    310        
     310
    311311        if (fun->ftype == fun_inner) {
    312312                dev = create_dev_node();
     
    315315                        return ENOMEM;
    316316                }
    317                
     317
    318318                insert_dev_node(&device_tree, dev, fun);
    319319                dev_add_ref(dev);
    320320        }
    321        
     321
    322322        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
    323        
     323
    324324        if (fun->ftype == fun_inner) {
    325325                dev = fun->child;
    326326                assert(dev != NULL);
    327                
     327
    328328                /* Give one reference over to assign_driver_fibril(). */
    329329                dev_add_ref(dev);
    330                
     330
    331331                /*
    332332                 * Try to find a suitable driver and assign it to the device.  We do
     
    347347        } else
    348348                loc_register_tree_function(fun, &device_tree);
    349        
     349
    350350        fun->state = FUN_ON_LINE;
    351351        fibril_rwlock_write_unlock(&device_tree.rwlock);
    352        
     352
    353353        return EOK;
    354354}
     
    357357{
    358358        errno_t rc;
    359        
     359
    360360        fibril_rwlock_write_lock(&device_tree.rwlock);
    361        
     361
    362362        if (fun->state == FUN_OFF_LINE) {
    363363                fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    366366                return EOK;
    367367        }
    368        
     368
    369369        if (fun->ftype == fun_inner) {
    370370                log_msg(LOG_DEFAULT, LVL_DEBUG, "Offlining inner function %s.",
    371371                    fun->pathname);
    372                
     372
    373373                if (fun->child != NULL) {
    374374                        dev_node_t *dev = fun->child;
    375375                        device_state_t dev_state;
    376                        
     376
    377377                        dev_add_ref(dev);
    378378                        dev_state = dev->state;
    379                        
     379
    380380                        fibril_rwlock_write_unlock(&device_tree.rwlock);
    381381
     
    388388                                }
    389389                        }
    390                        
     390
    391391                        /* Verify that driver removed all functions */
    392392                        fibril_rwlock_read_lock(&device_tree.rwlock);
     
    396396                                return EIO;
    397397                        }
    398                        
     398
    399399                        driver_t *driver = dev->drv;
    400400                        fibril_rwlock_read_unlock(&device_tree.rwlock);
    401                        
     401
    402402                        if (driver)
    403403                                detach_driver(&device_tree, dev);
    404                        
     404
    405405                        fibril_rwlock_write_lock(&device_tree.rwlock);
    406406                        remove_dev_node(&device_tree, dev);
    407                        
     407
    408408                        /* Delete ref created when node was inserted */
    409409                        dev_del_ref(dev);
     
    419419                        return EIO;
    420420                }
    421                
     421
    422422                fun->service_id = 0;
    423423        }
    424        
     424
    425425        fun->state = FUN_OFF_LINE;
    426426        fibril_rwlock_write_unlock(&device_tree.rwlock);
    427        
     427
    428428        return EOK;
    429429}
  • uspace/srv/devman/loc.c

    r3061bc1 ra35b458  
    4343        char *loc_pathname = NULL;
    4444        char *loc_name = NULL;
    45        
     45
    4646        assert(fibril_rwlock_is_locked(&tree->rwlock));
    47        
     47
    4848        asprintf(&loc_name, "%s", fun->pathname);
    4949        if (loc_name == NULL)
    5050                return;
    51        
     51
    5252        replace_char(loc_name, '/', LOC_SEPARATOR);
    53        
     53
    5454        asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE,
    5555            loc_name);
     
    5858                return;
    5959        }
    60        
     60
    6161        loc_service_register(loc_pathname, &fun->service_id);
    62        
     62
    6363        tree_add_loc_function(tree, fun);
    64        
     64
    6565        free(loc_name);
    6666        free(loc_pathname);
     
    7777{
    7878        fun_node_t *fun = NULL;
    79        
     79
    8080        fibril_rwlock_read_lock(&tree->rwlock);
    8181        ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);
     
    8585        }
    8686        fibril_rwlock_read_unlock(&tree->rwlock);
    87        
     87
    8888        return fun;
    8989}
     
    9292{
    9393        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    94        
     94
    9595        hash_table_insert(&tree->loc_functions, &fun->loc_fun);
    9696}
     
    9999{
    100100        assert(fibril_rwlock_is_write_locked(&tree->rwlock));
    101        
     101
    102102        hash_table_remove(&tree->loc_functions, &fun->service_id);
    103103}
  • uspace/srv/devman/main.c

    r3061bc1 ra35b458  
    7171        devman_handle_t handle = IPC_GET_ARG2(*icall);
    7272        dev_node_t *dev = NULL;
    73        
     73
    7474        fun_node_t *fun = find_fun_node(&device_tree, handle);
    7575        if (fun == NULL) {
     
    7777        } else {
    7878                fibril_rwlock_read_lock(&device_tree.rwlock);
    79                
     79
    8080                dev = fun->dev;
    8181                if (dev != NULL)
    8282                        dev_add_ref(dev);
    83                
     83
    8484                fibril_rwlock_read_unlock(&device_tree.rwlock);
    8585        }
    86        
     86
    8787        /*
    8888         * For a valid function to connect to we need a device. The root
     
    9797                goto cleanup;
    9898        }
    99        
     99
    100100        if (fun == NULL) {
    101101                log_msg(LOG_DEFAULT, LVL_ERROR, NAME ": devman_forward error - cannot "
     
    105105                goto cleanup;
    106106        }
    107        
     107
    108108        fibril_rwlock_read_lock(&device_tree.rwlock);
    109        
     109
    110110        /* Connect to the specified function */
    111111        driver_t *driver = dev->drv;
    112        
     112
    113113        fibril_rwlock_read_unlock(&device_tree.rwlock);
    114        
     114
    115115        if (driver == NULL) {
    116116                log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding refused - " \
     
    119119                goto cleanup;
    120120        }
    121        
     121
    122122        if (!driver->sess) {
    123123                log_msg(LOG_DEFAULT, LVL_ERROR,
     
    126126                goto cleanup;
    127127        }
    128        
     128
    129129        if (fun != NULL) {
    130130                log_msg(LOG_DEFAULT, LVL_DEBUG,
     
    136136                    dev->pfun->pathname, driver->name);
    137137        }
    138        
     138
    139139        async_exch_t *exch = async_exchange_begin(driver->sess);
    140140        async_forward_fast(iid, exch, INTERFACE_DDF_CLIENT, handle, 0, IPC_FF_NONE);
    141141        async_exchange_end(exch);
    142        
     142
    143143cleanup:
    144144        if (dev != NULL)
    145145                dev_del_ref(dev);
    146        
     146
    147147        if (fun != NULL)
    148148                fun_del_ref(fun);
     
    154154        devman_handle_t handle = IPC_GET_ARG2(*icall);
    155155        dev_node_t *dev = NULL;
    156        
     156
    157157        fun_node_t *fun = find_fun_node(&device_tree, handle);
    158158        if (fun == NULL) {
     
    160160        } else {
    161161                fibril_rwlock_read_lock(&device_tree.rwlock);
    162                
     162
    163163                dev = fun->dev;
    164164                if (dev != NULL)
    165165                        dev_add_ref(dev);
    166                
     166
    167167                fibril_rwlock_read_unlock(&device_tree.rwlock);
    168168        }
    169        
     169
    170170        /*
    171171         * For a valid function to connect to we need a device. The root
     
    180180                goto cleanup;
    181181        }
    182        
     182
    183183        driver_t *driver = NULL;
    184        
     184
    185185        fibril_rwlock_read_lock(&device_tree.rwlock);
    186        
     186
    187187        /* Connect to parent function of a device (or device function). */
    188188        if (dev->pfun->dev != NULL)
    189189                driver = dev->pfun->dev->drv;
    190        
     190
    191191        devman_handle_t fun_handle = dev->pfun->handle;
    192        
     192
    193193        fibril_rwlock_read_unlock(&device_tree.rwlock);
    194        
     194
    195195        if (driver == NULL) {
    196196                log_msg(LOG_DEFAULT, LVL_ERROR, "IPC forwarding refused - " \
     
    199199                goto cleanup;
    200200        }
    201        
     201
    202202        if (!driver->sess) {
    203203                log_msg(LOG_DEFAULT, LVL_ERROR,
     
    206206                goto cleanup;
    207207        }
    208        
     208
    209209        if (fun != NULL) {
    210210                log_msg(LOG_DEFAULT, LVL_DEBUG,
     
    216216                    dev->pfun->pathname, driver->name);
    217217        }
    218        
     218
    219219        async_exch_t *exch = async_exchange_begin(driver->sess);
    220220        async_forward_fast(iid, exch, INTERFACE_DDF_DRIVER, fun_handle, 0, IPC_FF_NONE);
    221221        async_exchange_end(exch);
    222        
     222
    223223cleanup:
    224224        if (dev != NULL)
    225225                dev_del_ref(dev);
    226        
     226
    227227        if (fun != NULL)
    228228                fun_del_ref(fun);
     
    233233        iface_t iface = IPC_GET_ARG1(*icall);
    234234        service_id_t service_id = IPC_GET_ARG2(*icall);
    235        
     235
    236236        fun_node_t *fun = find_loc_tree_function(&device_tree, service_id);
    237        
     237
    238238        fibril_rwlock_read_lock(&device_tree.rwlock);
    239        
     239
    240240        if ((fun == NULL) || (fun->dev == NULL) || (fun->dev->drv == NULL)) {
    241241                log_msg(LOG_DEFAULT, LVL_WARN, "devman_forward(): function "
     
    245245                return;
    246246        }
    247        
     247
    248248        dev_node_t *dev = fun->dev;
    249249        driver_t *driver = dev->drv;
    250250        devman_handle_t handle = fun->handle;
    251        
     251
    252252        fibril_rwlock_read_unlock(&device_tree.rwlock);
    253        
     253
    254254        async_exch_t *exch = async_exchange_begin(driver->sess);
    255255        async_forward_fast(iid, exch, iface, handle, 0, IPC_FF_NONE);
    256256        async_exchange_end(exch);
    257        
     257
    258258        log_msg(LOG_DEFAULT, LVL_DEBUG,
    259259            "Forwarding service request for `%s' function to driver `%s'.",
    260260            fun->pathname, driver->name);
    261        
     261
    262262        fun_del_ref(fun);
    263263}
     
    266266{
    267267        client_t *client;
    268        
     268
    269269        client = calloc(1, sizeof(client_t));
    270270        if (client == NULL)
    271271                return NULL;
    272        
     272
    273273        fibril_mutex_initialize(&client->mutex);
    274274        return client;
     
    284284{
    285285        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - looking for available drivers.");
    286        
     286
    287287        /* Initialize list of available drivers. */
    288288        init_driver_list(&drivers_list);
     
    292292                return false;
    293293        }
    294        
     294
    295295        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    296        
     296
    297297        /* Create root device node. */
    298298        if (!init_device_tree(&device_tree, &drivers_list)) {
     
    300300                return false;
    301301        }
    302        
     302
    303303        /*
    304304         * Caution: As the device manager is not a real loc
     
    309309         */
    310310        loc_server_register(NAME);
    311        
     311
    312312        return true;
    313313}
     
    316316{
    317317        printf("%s: HelenOS Device Manager\n", NAME);
    318        
     318
    319319        errno_t rc = log_init(NAME);
    320320        if (rc != EOK) {
     
    322322                return rc;
    323323        }
    324        
     324
    325325        /* Set handlers for incoming connections. */
    326326        async_set_client_data_constructor(devman_client_data_create);
    327327        async_set_client_data_destructor(devman_client_data_destroy);
    328        
     328
    329329        port_id_t port;
    330330        rc = async_create_port(INTERFACE_DDF_DRIVER,
     
    334334                return rc;
    335335        }
    336        
     336
    337337        rc = async_create_port(INTERFACE_DDF_CLIENT,
    338338            devman_connection_client, NULL, &port);
     
    341341                return rc;
    342342        }
    343        
     343
    344344        rc = async_create_port(INTERFACE_DEVMAN_DEVICE,
    345345            devman_connection_device, NULL, &port);
     
    348348                return rc;
    349349        }
    350        
     350
    351351        rc = async_create_port(INTERFACE_DEVMAN_PARENT,
    352352            devman_connection_parent, NULL, &port);
     
    355355                return rc;
    356356        }
    357        
     357
    358358        async_set_fallback_port_handler(devman_forward, NULL);
    359        
     359
    360360        if (!devman_init()) {
    361361                log_msg(LOG_DEFAULT, LVL_ERROR, "Error while initializing service.");
    362362                return -1;
    363363        }
    364        
     364
    365365        /* Register device manager at naming service. */
    366366        rc = service_register(SERVICE_DEVMAN);
     
    369369                return rc;
    370370        }
    371        
     371
    372372        printf("%s: Accepting connections.\n", NAME);
    373373        task_retval(0);
    374374        async_manager();
    375        
     375
    376376        /* Never reached. */
    377377        return 0;
  • uspace/srv/devman/match.c

    r3061bc1 ra35b458  
    6969        link_t *drv_head = &drv->match_ids.ids.head;
    7070        link_t *dev_head = &dev->pfun->match_ids.ids.head;
    71        
     71
    7272        if (list_empty(&drv->match_ids.ids) ||
    7373            list_empty(&dev->pfun->match_ids.ids)) {
    7474                return 0;
    7575        }
    76        
     76
    7777        /*
    7878         * Go through all pairs, return the highest score obtained.
    7979         */
    8080        int highest_score = 0;
    81        
     81
    8282        link_t *drv_link = drv->match_ids.ids.head.next;
    8383        while (drv_link != drv_head) {
     
    8686                        match_id_t *drv_id = list_get_instance(drv_link, match_id_t, link);
    8787                        match_id_t *dev_id = list_get_instance(dev_link, match_id_t, link);
    88                        
     88
    8989                        int score = compute_match_score(drv_id, dev_id);
    9090                        if (score > highest_score) {
     
    9494                        dev_link = dev_link->next;
    9595                }
    96                
     96
    9797                drv_link = drv_link->next;
    9898        }
    99        
     99
    100100        return highest_score;
    101101}
     
    111111        char *res = NULL;
    112112        size_t len = get_nonspace_len(*buf);
    113        
     113
    114114        if (len > 0) {
    115115                res = malloc(len + 1);
     
    119119                }
    120120        }
    121        
     121
    122122        return res;
    123123}
     
    141141        char *id = NULL;
    142142        int ids_read = 0;
    143        
     143
    144144        while (true) {
    145145                /* skip spaces */
     
    151151                        continue;
    152152                }
    153                
     153
    154154                /* read score */
    155155                score = strtoul(buf, &buf, 10);
    156                
     156
    157157                /* skip spaces */
    158158                if (!skip_spaces(&buf))
    159159                        break;
    160                
     160
    161161                /* read id */
    162162                id = read_match_id(&buf);
    163163                if (NULL == id)
    164164                        break;
    165                
     165
    166166                /* create new match_id structure */
    167167                match_id_t *mid = create_match_id();
    168168                mid->id = id;
    169169                mid->score = score;
    170                
     170
    171171                /* add it to the list */
    172172                add_match_id(ids, mid);
    173                
     173
    174174                ids_read++;
    175175        }
    176        
     176
    177177        return ids_read > 0;
    178178}
     
    194194{
    195195        log_msg(LOG_DEFAULT, LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    196        
     196
    197197        bool suc = false;
    198198        char *buf = NULL;
     
    201201        size_t len = 0;
    202202        vfs_stat_t st;
    203        
     203
    204204        errno_t rc = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ, &fd);
    205205        if (rc != EOK) {
     
    209209        }
    210210        opened = true;
    211        
     211
    212212        rc = vfs_stat(fd, &st);
    213213        if (rc != EOK) {
     
    222222                goto cleanup;
    223223        }
    224        
     224
    225225        buf = malloc(len + 1);
    226226        if (buf == NULL) {
     
    229229                goto cleanup;
    230230        }
    231        
     231
    232232        size_t read_bytes;
    233233        rc = vfs_read(fd, (aoff64_t []) {0}, buf, len, &read_bytes);
     
    238238        }
    239239        buf[read_bytes] = 0;
    240        
     240
    241241        suc = parse_match_ids(buf, ids);
    242        
     242
    243243cleanup:
    244244        free(buf);
    245        
     245
    246246        if (opened)
    247247                vfs_put(fd);
    248        
     248
    249249        return suc;
    250250}
  • uspace/srv/devman/util.c

    r3061bc1 ra35b458  
    4141        int base_len = str_size(base_path);
    4242        int size = base_len + 2 * str_size(name) + str_size(ext) + 3;
    43        
     43
    4444        res = malloc(size);
    45        
     45
    4646        if (res) {
    4747                str_cpy(res, size, base_path);
     
    5555                str_append(res, size, ext);
    5656        }
    57        
     57
    5858        return res;
    5959}
     
    8282{
    8383        size_t len = 0;
    84        
     84
    8585        while(*str != '\0' && !isspace(*str)) {
    8686                len++;
Note: See TracChangeset for help on using the changeset viewer.