Changeset a35b458 in mainline for kernel/generic/src/sysinfo/sysinfo.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
  • kernel/generic/src/sysinfo/sysinfo.c

    r3061bc1 ra35b458  
    6464{
    6565        sysinfo_item_t *item = (sysinfo_item_t *) obj;
    66        
     66
    6767        item->name = NULL;
    6868        item->val_type = SYSINFO_VAL_UNDEFINED;
     
    7070        item->subtree.table = NULL;
    7171        item->next = NULL;
    72        
     72
    7373        return EOK;
    7474}
     
    8484{
    8585        sysinfo_item_t *item = (sysinfo_item_t *) obj;
    86        
     86
    8787        if (item->name != NULL)
    8888                free(item->name);
    89        
     89
    9090        return 0;
    9191}
     
    101101            sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
    102102            sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
    103        
     103
    104104        mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);
    105105}
     
    127127{
    128128        assert(subtree != NULL);
    129        
     129
    130130        sysinfo_item_t *cur = subtree;
    131        
     131
    132132        /* Walk all siblings */
    133133        while (cur != NULL) {
    134134                size_t i = 0;
    135                
     135
    136136                /* Compare name with path */
    137137                while ((cur->name[i] != 0) && (name[i] == cur->name[i]))
    138138                        i++;
    139                
     139
    140140                /* Check for perfect name and path match */
    141141                if ((name[i] == 0) && (cur->name[i] == 0))
    142142                        return cur;
    143                
     143
    144144                /* Partial match up to the delimiter */
    145145                if ((name[i] == '.') && (cur->name[i] == 0)) {
     
    155155                                        **ret = cur->subtree.generator.fn(name + i + 1,
    156156                                            dry_run, cur->subtree.generator.data);
    157                                
     157
    158158                                return NULL;
    159159                        default:
     
    161161                                if (ret != NULL)
    162162                                        *ret = NULL;
    163                                
     163
    164164                                return NULL;
    165165                        }
    166166                }
    167                
     167
    168168                cur = cur->next;
    169169        }
    170        
     170
    171171        /* Not found, no data generated */
    172172        if (ret != NULL)
    173173                *ret = NULL;
    174        
     174
    175175        return NULL;
    176176}
     
    193193{
    194194        assert(psubtree != NULL);
    195        
     195
    196196        if (*psubtree == NULL) {
    197197                /* No parent */
    198                
     198
    199199                size_t i = 0;
    200                
     200
    201201                /* Find the first delimiter in name */
    202202                while ((name[i] != 0) && (name[i] != '.'))
    203203                        i++;
    204                
     204
    205205                *psubtree =
    206206                    (sysinfo_item_t *) slab_alloc(sysinfo_item_cache, 0);
    207207                assert(*psubtree);
    208                
     208
    209209                /* Fill in item name up to the delimiter */
    210210                (*psubtree)->name = str_ndup(name, i);
    211211                assert((*psubtree)->name);
    212                
     212
    213213                /* Create subtree items */
    214214                if (name[i] == '.') {
     
    217217                            &((*psubtree)->subtree.table));
    218218                }
    219                
     219
    220220                /* No subtree needs to be created */
    221221                return *psubtree;
    222222        }
    223        
     223
    224224        sysinfo_item_t *cur = *psubtree;
    225        
     225
    226226        /* Walk all siblings */
    227227        while (cur != NULL) {
    228228                size_t i = 0;
    229                
     229
    230230                /* Compare name with path */
    231231                while ((cur->name[i] != 0) && (name[i] == cur->name[i]))
    232232                        i++;
    233                
     233
    234234                /* Check for perfect name and path match
    235235                 * -> item is already present.
     
    237237                if ((name[i] == 0) && (cur->name[i] == 0))
    238238                        return cur;
    239                
     239
    240240                /* Partial match up to the delimiter */
    241241                if ((name[i] == '.') && (cur->name[i] == 0)) {
     
    257257                        }
    258258                }
    259                
     259
    260260                /* No match and no more siblings to check
    261261                 * -> create a new sibling item.
     
    266266                        while ((name[i] != 0) && (name[i] != '.'))
    267267                                i++;
    268                        
     268
    269269                        sysinfo_item_t *item =
    270270                            (sysinfo_item_t *) slab_alloc(sysinfo_item_cache, 0);
    271271                        assert(item);
    272                        
     272
    273273                        cur->next = item;
    274                        
     274
    275275                        /* Fill in item name up to the delimiter */
    276276                        item->name = str_ndup(name, i);
    277277                        assert(item->name);
    278                        
     278
    279279                        /* Create subtree items */
    280280                        if (name[i] == '.') {
     
    283283                                    &(item->subtree.table));
    284284                        }
    285                        
     285
    286286                        /* No subtree needs to be created */
    287287                        return item;
    288288                }
    289                
     289
    290290                cur = cur->next;
    291291        }
    292        
     292
    293293        /* Unreachable */
    294294        assert(false);
     
    309309        /* Protect sysinfo tree consistency */
    310310        mutex_lock(&sysinfo_lock);
    311        
     311
    312312        if (root == NULL)
    313313                root = &global_root;
    314        
     314
    315315        sysinfo_item_t *item = sysinfo_create_path(name, root);
    316316        if (item != NULL) {
     
    318318                item->val.val = val;
    319319        }
    320        
     320
    321321        mutex_unlock(&sysinfo_lock);
    322322}
     
    340340        /* Protect sysinfo tree consistency */
    341341        mutex_lock(&sysinfo_lock);
    342        
     342
    343343        if (root == NULL)
    344344                root = &global_root;
    345        
     345
    346346        sysinfo_item_t *item = sysinfo_create_path(name, root);
    347347        if (item != NULL) {
     
    350350                item->val.data.size = size;
    351351        }
    352        
     352
    353353        mutex_unlock(&sysinfo_lock);
    354354}
     
    368368        /* Protect sysinfo tree consistency */
    369369        mutex_lock(&sysinfo_lock);
    370        
     370
    371371        if (root == NULL)
    372372                root = &global_root;
    373        
     373
    374374        sysinfo_item_t *item = sysinfo_create_path(name, root);
    375375        if (item != NULL) {
     
    378378                item->val.gen_val.data = data;
    379379        }
    380        
     380
    381381        mutex_unlock(&sysinfo_lock);
    382382}
     
    401401        /* Protect sysinfo tree consistency */
    402402        mutex_lock(&sysinfo_lock);
    403        
     403
    404404        if (root == NULL)
    405405                root = &global_root;
    406        
     406
    407407        sysinfo_item_t *item = sysinfo_create_path(name, root);
    408408        if (item != NULL) {
     
    411411                item->val.gen_data.data = data;
    412412        }
    413        
     413
    414414        mutex_unlock(&sysinfo_lock);
    415415}
     
    426426        /* Protect sysinfo tree consistency */
    427427        mutex_lock(&sysinfo_lock);
    428        
     428
    429429        if (root == NULL)
    430430                root = &global_root;
    431        
     431
    432432        sysinfo_item_t *item = sysinfo_create_path(name, root);
    433433        if (item != NULL)
    434434                item->val_type = SYSINFO_VAL_UNDEFINED;
    435        
     435
    436436        mutex_unlock(&sysinfo_lock);
    437437}
     
    451451        /* Protect sysinfo tree consistency */
    452452        mutex_lock(&sysinfo_lock);
    453        
     453
    454454        if (root == NULL)
    455455                root = &global_root;
    456        
     456
    457457        sysinfo_item_t *item = sysinfo_create_path(name, root);
    458        
     458
    459459        /* Change the type of the subtree only if it is not already
    460460           a fixed subtree */
     
    464464                item->subtree.generator.data = data;
    465465        }
    466        
     466
    467467        mutex_unlock(&sysinfo_lock);
    468468}
     
    492492        for (sysinfo_item_t *cur = root; cur; cur = cur->next) {
    493493                size_t length;
    494                
     494
    495495                if (spaces == 0) {
    496496                        printf("%s", cur->name);
     
    501501                        length = str_length(cur->name) + 1;
    502502                }
    503                
     503
    504504                sysarg_t val;
    505505                size_t size;
    506                
     506
    507507                /* Display node value and type */
    508508                switch (cur->val_type) {
     
    531531                        printf("+ %s [unknown]\n", cur->name);
    532532                }
    533                
     533
    534534                /* Recursivelly nest into the subtree */
    535535                switch (cur->subtree_type) {
     
    562562           while we are dumping it */
    563563        mutex_lock(&sysinfo_lock);
    564        
     564
    565565        if (root == NULL)
    566566                sysinfo_dump_internal(global_root, 0);
    567567        else
    568568                sysinfo_dump_internal(root, 0);
    569        
     569
    570570        mutex_unlock(&sysinfo_lock);
    571571}
     
    590590        if (root == NULL)
    591591                root = &global_root;
    592        
     592
    593593        /* Try to find the item or generate data */
    594594        sysinfo_return_t ret;
     
    596596        sysinfo_item_t *item = sysinfo_find_item(name, *root, &ret_ptr,
    597597            dry_run);
    598        
     598
    599599        if (item != NULL) {
    600600                /* Item found in the fixed sysinfo tree */
    601                
     601
    602602                ret.tag = item->val_type;
    603603                switch (item->val_type) {
     
    625625                }
    626626        }
    627        
     627
    628628        return ret;
    629629}
     
    645645        sysinfo_return_t ret;
    646646        ret.tag = SYSINFO_VAL_UNDEFINED;
    647        
     647
    648648        if (size > SYSINFO_MAX_PATH)
    649649                return ret;
    650        
     650
    651651        char *path = (char *) malloc(size + 1, 0);
    652652        assert(path);
    653        
     653
    654654        if ((copy_from_uspace(path, ptr, size + 1) == 0) &&
    655655            (path[size] == 0)) {
     
    662662                mutex_unlock(&sysinfo_lock);
    663663        }
    664        
     664
    665665        free(path);
    666666        return ret;
     
    686686        if (root == NULL)
    687687                root = &global_root;
    688        
     688
    689689        sysinfo_item_t *subtree = NULL;
    690        
     690
    691691        if (name[0] != 0) {
    692692                /* Try to find the item */
     
    698698        } else
    699699                subtree = *root;
    700        
     700
    701701        sysinfo_return_t ret;
    702702        ret.tag = SYSINFO_VAL_UNDEFINED;
    703        
     703
    704704        if (subtree != NULL) {
    705705                /*
     
    709709                for (sysinfo_item_t *cur = subtree; cur; cur = cur->next)
    710710                        size += str_size(cur->name) + 1;
    711                
     711
    712712                if (dry_run) {
    713713                        ret.tag = SYSINFO_VAL_DATA;
     
    719719                        if (names == NULL)
    720720                                return ret;
    721                        
     721
    722722                        size_t pos = 0;
    723723                        for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) {
     
    725725                                pos += str_size(cur->name) + 1;
    726726                        }
    727                        
     727
    728728                        /* Correct return value */
    729729                        ret.tag = SYSINFO_VAL_DATA;
     
    732732                }
    733733        }
    734        
     734
    735735        return ret;
    736736}
     
    754754        ret.data.data = NULL;
    755755        ret.data.size = 0;
    756        
     756
    757757        if (size > SYSINFO_MAX_PATH)
    758758                return ret;
    759        
     759
    760760        char *path = (char *) malloc(size + 1, 0);
    761761        assert(path);
    762        
     762
    763763        if ((copy_from_uspace(path, ptr, size + 1) == 0) &&
    764764            (path[size] == 0)) {
     
    771771                mutex_unlock(&sysinfo_lock);
    772772        }
    773        
     773
    774774        free(path);
    775775        return ret;
     
    794794{
    795795        errno_t rc;
    796        
     796
    797797        /*
    798798         * Get the keys.
     
    803803        sysinfo_return_t ret =
    804804            sysinfo_get_keys_uspace(path_ptr, path_size, true);
    805        
     805
    806806        /* Check return data tag */
    807807        if (ret.tag == SYSINFO_VAL_DATA)
     
    810810        else
    811811                rc = EINVAL;
    812        
     812
    813813        return (sys_errno_t) rc;
    814814}
     
    842842{
    843843        errno_t rc;
    844        
     844
    845845        /* Get the keys */
    846846        sysinfo_return_t ret = sysinfo_get_keys_uspace(path_ptr, path_size,
    847847            false);
    848        
     848
    849849        /* Check return data tag */
    850850        if (ret.tag == SYSINFO_VAL_DATA) {
     
    853853                if (rc == EOK)
    854854                        rc = copy_to_uspace(size_ptr, &size, sizeof(size));
    855                
     855
    856856                free(ret.data.data);
    857857        } else
    858858                rc = EINVAL;
    859        
     859
    860860        return (sys_errno_t) rc;
    861861}
     
    882882         */
    883883        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    884        
     884
    885885        /*
    886886         * Map generated value types to constant types (user space does
     
    891891        else if (ret.tag == SYSINFO_VAL_FUNCTION_DATA)
    892892                ret.tag = SYSINFO_VAL_DATA;
    893        
     893
    894894        return (sysarg_t) ret.tag;
    895895}
     
    913913{
    914914        errno_t rc;
    915        
     915
    916916        /*
    917917         * Get the item.
     
    921921         */
    922922        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    923        
     923
    924924        /* Only constant or generated numerical value is returned */
    925925        if ((ret.tag == SYSINFO_VAL_VAL) || (ret.tag == SYSINFO_VAL_FUNCTION_VAL))
     
    927927        else
    928928                rc = EINVAL;
    929        
     929
    930930        return (sys_errno_t) rc;
    931931}
     
    949949{
    950950        errno_t rc;
    951        
     951
    952952        /*
    953953         * Get the item.
     
    957957         */
    958958        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    959        
     959
    960960        /* Only the size of constant or generated binary data is considered */
    961961        if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA))
     
    964964        else
    965965                rc = EINVAL;
    966        
     966
    967967        return (sys_errno_t) rc;
    968968}
     
    999999{
    10001000        errno_t rc;
    1001        
     1001
    10021002        /* Get the item */
    10031003        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size,
    10041004            false);
    1005        
     1005
    10061006        /* Only constant or generated binary data is considered */
    10071007        if ((ret.tag == SYSINFO_VAL_DATA) ||
     
    10131013        } else
    10141014                rc = EINVAL;
    1015        
     1015
    10161016        /* N.B.: The generated binary data should be freed */
    10171017        if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL))
    10181018                free(ret.data.data);
    1019        
     1019
    10201020        return (sys_errno_t) rc;
    10211021}
Note: See TracChangeset for help on using the changeset viewer.