Changeset a35b458 in mainline for uspace/lib/drv/generic/driver.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/driver.c

    r3061bc1 ra35b458  
    9797{
    9898        assert(fibril_mutex_is_locked(&devices_mutex));
    99        
     99
    100100        list_foreach(devices, link, ddf_dev_t, dev) {
    101101                if (dev->handle == handle)
    102102                        return dev;
    103103        }
    104        
     104
    105105        return NULL;
    106106}
     
    109109{
    110110        assert(fibril_mutex_is_locked(&functions_mutex));
    111        
     111
    112112        list_foreach(functions, link, ddf_fun_t, fun) {
    113113                if (fun->handle == handle)
    114114                        return fun;
    115115        }
    116        
     116
    117117        return NULL;
    118118}
     
    122122        devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
    123123        devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
    124        
     124
    125125        char *dev_name = NULL;
    126126        errno_t rc = async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
     
    129129                return;
    130130        }
    131        
     131
    132132        fibril_rwlock_read_lock(&stopping_lock);
    133133
     
    137137                return;
    138138        }
    139        
     139
    140140        ddf_dev_t *dev = create_device();
    141141        if (!dev) {
     
    145145                return;
    146146        }
    147        
     147
    148148        /* Add one reference that will be dropped by driver_dev_remove() */
    149149        dev_add_ref(dev);
    150150        dev->handle = dev_handle;
    151151        dev->name = dev_name;
    152        
     152
    153153        /*
    154154         * Currently not used, parent fun handle is stored in context
     
    156156         */
    157157        (void) parent_fun_handle;
    158        
     158
    159159        errno_t res = driver->driver_ops->dev_add(dev);
    160        
     160
    161161        if (res != EOK) {
    162162                fibril_rwlock_read_unlock(&stopping_lock);
     
    165165                return;
    166166        }
    167        
     167
    168168        fibril_mutex_lock(&devices_mutex);
    169169        list_append(&dev->link, &devices);
    170170        fibril_mutex_unlock(&devices_mutex);
    171171        fibril_rwlock_read_unlock(&stopping_lock);
    172        
     172
    173173        async_answer_0(iid, res);
    174174}
     
    177177{
    178178        devman_handle_t devh = IPC_GET_ARG1(*icall);
    179        
     179
    180180        fibril_mutex_lock(&devices_mutex);
    181181        ddf_dev_t *dev = driver_get_device(devh);
     
    183183                dev_add_ref(dev);
    184184        fibril_mutex_unlock(&devices_mutex);
    185        
     185
    186186        if (dev == NULL) {
    187187                async_answer_0(iid, ENOENT);
    188188                return;
    189189        }
    190        
     190
    191191        errno_t rc;
    192        
     192
    193193        if (driver->driver_ops->dev_remove != NULL)
    194194                rc = driver->driver_ops->dev_remove(dev);
    195195        else
    196196                rc = ENOTSUP;
    197        
     197
    198198        if (rc == EOK) {
    199199                fibril_mutex_lock(&devices_mutex);
     
    202202                dev_del_ref(dev);
    203203        }
    204        
     204
    205205        dev_del_ref(dev);
    206206        async_answer_0(iid, rc);
     
    210210{
    211211        devman_handle_t devh = IPC_GET_ARG1(*icall);
    212        
     212
    213213        fibril_mutex_lock(&devices_mutex);
    214214        ddf_dev_t *dev = driver_get_device(devh);
     
    216216                dev_add_ref(dev);
    217217        fibril_mutex_unlock(&devices_mutex);
    218        
     218
    219219        if (dev == NULL) {
    220220                async_answer_0(iid, ENOENT);
    221221                return;
    222222        }
    223        
     223
    224224        errno_t rc;
    225        
     225
    226226        if (driver->driver_ops->dev_gone != NULL)
    227227                rc = driver->driver_ops->dev_gone(dev);
    228228        else
    229229                rc = ENOTSUP;
    230        
     230
    231231        if (rc == EOK) {
    232232                fibril_mutex_lock(&devices_mutex);
     
    235235                dev_del_ref(dev);
    236236        }
    237        
     237
    238238        dev_del_ref(dev);
    239239        async_answer_0(iid, rc);
     
    243243{
    244244        devman_handle_t funh = IPC_GET_ARG1(*icall);
    245        
     245
    246246        /*
    247247         * Look the function up. Bump reference count so that
     
    250250         */
    251251        fibril_mutex_lock(&functions_mutex);
    252        
     252
    253253        ddf_fun_t *fun = driver_get_function(funh);
    254254        if (fun != NULL)
    255255                fun_add_ref(fun);
    256        
     256
    257257        fibril_mutex_unlock(&functions_mutex);
    258        
     258
    259259        if (fun == NULL) {
    260260                async_answer_0(iid, ENOENT);
    261261                return;
    262262        }
    263        
     263
    264264        /* Call driver entry point */
    265265        errno_t rc;
    266        
     266
    267267        if (driver->driver_ops->fun_online != NULL)
    268268                rc = driver->driver_ops->fun_online(fun);
    269269        else
    270270                rc = ENOTSUP;
    271        
     271
    272272        fun_del_ref(fun);
    273        
     273
    274274        async_answer_0(iid, rc);
    275275}
     
    278278{
    279279        devman_handle_t funh = IPC_GET_ARG1(*icall);
    280        
     280
    281281        /*
    282282         * Look the function up. Bump reference count so that
     
    285285         */
    286286        fibril_mutex_lock(&functions_mutex);
    287        
     287
    288288        ddf_fun_t *fun = driver_get_function(funh);
    289289        if (fun != NULL)
    290290                fun_add_ref(fun);
    291        
     291
    292292        fibril_mutex_unlock(&functions_mutex);
    293        
     293
    294294        if (fun == NULL) {
    295295                async_answer_0(iid, ENOENT);
    296296                return;
    297297        }
    298        
     298
    299299        /* Call driver entry point */
    300300        errno_t rc;
    301        
     301
    302302        if (driver->driver_ops->fun_offline != NULL)
    303303                rc = driver->driver_ops->fun_offline(fun);
    304304        else
    305305                rc = ENOTSUP;
    306        
     306
    307307        async_answer_0(iid, rc);
    308308}
     
    342342        /* Accept connection */
    343343        async_answer_0(iid, EOK);
    344        
     344
    345345        while (true) {
    346346                ipc_call_t call;
    347347                ipc_callid_t callid = async_get_call(&call);
    348                
     348
    349349                if (!IPC_GET_IMETHOD(call))
    350350                        break;
    351                
     351
    352352                switch (IPC_GET_IMETHOD(call)) {
    353353                case DRIVER_DEV_ADD:
     
    394394                fun_add_ref(fun);
    395395        fibril_mutex_unlock(&functions_mutex);
    396        
     396
    397397        if (fun == NULL) {
    398398                printf("%s: driver_connection_gen error - no function with handle"
     
    401401                return;
    402402        }
    403        
     403
    404404        if (fun->conn_handler != NULL) {
    405405                /* Driver has a custom connection handler. */
     
    408408                return;
    409409        }
    410        
     410
    411411        /*
    412412         * TODO - if the client is not a driver, check whether it is allowed to
    413413         * use the device.
    414414         */
    415        
     415
    416416        errno_t ret = EOK;
    417417        /* Open device function */
    418418        if (fun->ops != NULL && fun->ops->open != NULL)
    419419                ret = (*fun->ops->open)(fun);
    420        
     420
    421421        async_answer_0(iid, ret);
    422422        if (ret != EOK) {
     
    424424                return;
    425425        }
    426        
     426
    427427        while (true) {
    428428                ipc_callid_t callid;
     
    430430                callid = async_get_call(&call);
    431431                sysarg_t method = IPC_GET_IMETHOD(call);
    432                
     432
    433433                if (!method) {
    434434                        /* Close device function */
     
    439439                        return;
    440440                }
    441                
     441
    442442                /* Convert ipc interface id to interface index */
    443                
     443
    444444                int iface_idx = DEV_IFACE_IDX(method);
    445                
     445
    446446                if (!is_valid_iface_idx(iface_idx)) {
    447447                        remote_handler_t *default_handler =
     
    451451                                continue;
    452452                        }
    453                        
     453
    454454                        /*
    455455                         * Function has no such interface and
     
    462462                        continue;
    463463                }
    464                
     464
    465465                /* Calling one of the function's interfaces */
    466                
     466
    467467                /* Get the interface ops structure. */
    468468                void *ops = function_get_ops(fun, iface_idx);
     
    474474                        continue;
    475475                }
    476                
     476
    477477                /*
    478478                 * Get the corresponding interface for remote request
     
    481481                const remote_iface_t *rem_iface = get_remote_iface(iface_idx);
    482482                assert(rem_iface != NULL);
    483                
     483
    484484                /* get the method of the remote interface */
    485485                sysarg_t iface_method_idx = IPC_GET_ARG1(call);
     
    493493                        continue;
    494494                }
    495                
     495
    496496                /*
    497497                 * Call the remote interface's method, which will
     
    624624{
    625625        assert(dev->driver_data == NULL);
    626        
     626
    627627        void *data = calloc(1, size);
    628628        if (data == NULL)
    629629                return NULL;
    630        
     630
    631631        dev->driver_data = data;
    632632        return data;
     
    732732        if (fun == NULL)
    733733                return NULL;
    734        
     734
    735735        /* Add one reference that will be dropped by ddf_fun_destroy() */
    736736        fun->dev = dev;
    737737        fun_add_ref(fun);
    738        
     738
    739739        fun->bound = false;
    740740        fun->ftype = ftype;
    741        
     741
    742742        if (name != NULL) {
    743743                fun->name = str_dup(name);
     
    747747                }
    748748        }
    749        
     749
    750750        return fun;
    751751}
     
    756756        assert(fun->bound == false);
    757757        assert(fun->driver_data == NULL);
    758        
     758
    759759        void *data = calloc(1, size);
    760760        if (data == NULL)
    761761                return NULL;
    762        
     762
    763763        fun->driver_data = data;
    764764        return data;
     
    792792{
    793793        assert(fun->bound == false);
    794        
     794
    795795        /*
    796796         * Drop the reference added by ddf_fun_create(). This will deallocate
     
    807807        if (fun->ops == NULL)
    808808                return NULL;
    809        
     809
    810810        return fun->ops->interfaces[idx];
    811811}
     
    830830        assert(fun->name != NULL);
    831831        assert(fun->dev != NULL);
    832        
     832
    833833        add_to_functions_list(fun);
    834834        errno_t res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
     
    838838                return res;
    839839        }
    840        
     840
    841841        fun->bound = true;
    842842        return res;
     
    856856{
    857857        assert(fun->bound == true);
    858        
     858
    859859        errno_t res = devman_remove_function(fun->handle);
    860860        if (res != EOK)
    861861                return res;
    862        
     862
    863863        remove_from_functions_list(fun);
    864        
     864
    865865        fun->bound = false;
    866866        return EOK;
     
    877877{
    878878        assert(fun->bound == true);
    879        
     879
    880880        errno_t res = devman_drv_fun_online(fun->handle);
    881881        if (res != EOK)
    882882                return res;
    883        
     883
    884884        return EOK;
    885885}
     
    895895{
    896896        assert(fun->bound == true);
    897        
     897
    898898        errno_t res = devman_drv_fun_offline(fun->handle);
    899899        if (res != EOK)
    900900                return res;
    901        
     901
    902902        return EOK;
    903903}
     
    921921        assert(fun->bound == false);
    922922        assert(fun->ftype == fun_inner);
    923        
     923
    924924        match_id_t *match_id = create_match_id();
    925925        if (match_id == NULL)
    926926                return ENOMEM;
    927        
     927
    928928        match_id->id = str_dup(match_id_str);
    929929        match_id->score = match_score;
    930        
     930
    931931        add_match_id(&fun->match_ids, match_id);
    932932        return EOK;
     
    967967        assert(fun->bound == true);
    968968        assert(fun->ftype == fun_exposed);
    969        
     969
    970970        return devman_add_device_to_category(fun->handle, cat_name);
    971971}
     
    978978         */
    979979        driver = drv;
    980        
     980
    981981        /*
    982982         * Register driver with device manager using generic handler for
     
    990990                return rc;
    991991        }
    992        
     992
    993993        rc = async_create_port(INTERFACE_DDF_DEVMAN, driver_connection_devman,
    994994            NULL, &port);
     
    997997                return rc;
    998998        }
    999        
     999
    10001000        async_set_fallback_port_handler(driver_connection_client, NULL);
    1001        
     1001
    10021002        rc = devman_driver_register(driver->name);
    10031003        if (rc != EOK) {
     
    10051005                    "(%s).\n", (rc == EEXIST) ? "driver already started" :
    10061006                    str_error(rc));
    1007                
     1007
    10081008                return rc;
    10091009        }
    1010        
     1010
    10111011        /* Return success from the task since server has started. */
    10121012        rc = task_retval(0);
     
    10151015                return rc;
    10161016        }
    1017        
     1017
    10181018        async_manager();
    1019        
     1019
    10201020        /* Never reached. */
    10211021        return EOK;
Note: See TracChangeset for help on using the changeset viewer.