Changeset 0876062 in mainline


Ignore:
Timestamp:
2011-03-30T13:19:28Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fddb55
Parents:
4265fd4
Message:

devman refuse to register same function twice

Location:
uspace/srv/devman
Files:
3 edited

Legend:

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

    r4265fd4 r0876062  
    11651165}
    11661166
     1167/** Find function with a specified name belonging to given device.
     1168 *
     1169 * Device tree rwlock should be held at least for reading.
     1170 *
     1171 * @param dev Device the function belongs to.
     1172 * @param name Function name (not path).
     1173 * @return Function node.
     1174 * @retval NULL No function with given name.
     1175 */
     1176fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name)
     1177{
     1178        assert(dev != NULL);
     1179        assert(name != NULL);
     1180
     1181        fun_node_t *fun;
     1182        link_t *link;
     1183
     1184        for (link = dev->functions.next;
     1185            link != &dev->functions;
     1186            link = link->next) {
     1187                fun = list_get_instance(link, fun_node_t, dev_functions);
     1188
     1189                if (str_cmp(name, fun->name) == 0)
     1190                        return fun;
     1191        }
     1192
     1193        return NULL;
     1194}
     1195
    11671196/** Find child function node with a specified name.
    11681197 *
     
    11751204fun_node_t *find_node_child(fun_node_t *pfun, const char *name)
    11761205{
    1177         fun_node_t *fun;
    1178         link_t *link;
    1179        
    1180         link = pfun->child->functions.next;
    1181        
    1182         while (link != &pfun->child->functions) {
    1183                 fun = list_get_instance(link, fun_node_t, dev_functions);
    1184                
    1185                 if (str_cmp(name, fun->name) == 0)
    1186                         return fun;
    1187                
    1188                 link = link->next;
    1189         }
    1190        
    1191         return NULL;
     1206        return find_fun_node_in_device(pfun->child, name);
    11921207}
    11931208
  • uspace/srv/devman/devman.h

    r4265fd4 r0876062  
    338338extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
    339339extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
     340extern fun_node_t *find_fun_node_in_device(dev_node_t *, const char *);
    340341
    341342/* Device tree */
  • uspace/srv/devman/main.c

    r4265fd4 r0876062  
    243243        }
    244244       
     245        /* Check that function with same name is not there already. */
     246        if (find_fun_node_in_device(pdev, fun_name) != NULL) {
     247                fibril_rwlock_write_unlock(&tree->rwlock);
     248                async_answer_0(callid, EEXISTS);
     249                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
     250                    fun_name);
     251                free(fun_name);
     252                return;
     253        }
     254
    245255        fun_node_t *fun = create_fun_node();
    246256        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
Note: See TracChangeset for help on using the changeset viewer.