Ignore:
File:
1 edited

Legend:

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

    r33fc3ae r9d58539  
    245245       
    246246        fibril_rwlock_write_lock(&device_tree.rwlock);
    247        
     247
    248248        if (fun->state == FUN_ON_LINE) {
    249249                fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    259259                        return ENOMEM;
    260260                }
    261                
     261
    262262                insert_dev_node(&device_tree, dev, fun);
    263263                dev_add_ref(dev);
     
    272272                /* Give one reference over to assign_driver_fibril(). */
    273273                dev_add_ref(dev);
    274                
    275274                /*
    276275                 * Try to find a suitable driver and assign it to the device.  We do
     
    289288                }
    290289                fibril_add_ready(assign_fibril);
    291         } else
     290        } else {
    292291                loc_register_tree_function(fun, &device_tree);
     292        }
    293293       
    294294        fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    419419       
    420420        /* Check that function with same name is not there already. */
    421         fun_node_t *tfun = find_fun_node_in_device(tree, pdev, fun_name);
    422         if (tfun) {
    423                 fun_del_ref(tfun);      /* drop the new unwanted reference */
     421        if (find_fun_node_in_device(tree, pdev, fun_name) != NULL) {
    424422                fibril_rwlock_write_unlock(&tree->rwlock);
    425423                dev_del_ref(pdev);
     
    857855}
    858856
    859 /** Get function driver name. */
    860 static void devman_fun_get_driver_name(ipc_callid_t iid, ipc_call_t *icall)
    861 {
    862         devman_handle_t handle = IPC_GET_ARG1(*icall);
    863 
    864         fun_node_t *fun = find_fun_node(&device_tree, handle);
    865         if (fun == NULL) {
    866                 async_answer_0(iid, ENOMEM);
    867                 return;
    868         }
    869 
    870         ipc_callid_t data_callid;
    871         size_t data_len;
    872         if (!async_data_read_receive(&data_callid, &data_len)) {
    873                 async_answer_0(iid, EINVAL);
    874                 fun_del_ref(fun);
    875                 return;
    876         }
    877 
    878         void *buffer = malloc(data_len);
    879         if (buffer == NULL) {
    880                 async_answer_0(data_callid, ENOMEM);
    881                 async_answer_0(iid, ENOMEM);
    882                 fun_del_ref(fun);
    883                 return;
    884         }
    885 
    886         fibril_rwlock_read_lock(&device_tree.rwlock);
    887 
    888         /* Check function state */
    889         if (fun->state == FUN_REMOVED) {
    890                 fibril_rwlock_read_unlock(&device_tree.rwlock);
    891                 free(buffer);
    892 
    893                 async_answer_0(data_callid, ENOENT);
    894                 async_answer_0(iid, ENOENT);
    895                 fun_del_ref(fun);
    896                 return;
    897         }
    898 
    899         /* Check whether function has a driver */
    900         if (fun->child == NULL || fun->child->drv == NULL) {
    901                 fibril_rwlock_read_unlock(&device_tree.rwlock);
    902                 free(buffer);
    903 
    904                 async_answer_0(data_callid, EINVAL);
    905                 async_answer_0(iid, EINVAL);
    906                 fun_del_ref(fun);
    907                 return;
    908         }
    909 
    910         size_t sent_length = str_size(fun->child->drv->name);
    911         if (sent_length > data_len) {
    912                 sent_length = data_len;
    913         }
    914 
    915         async_data_read_finalize(data_callid, fun->child->drv->name,
    916             sent_length);
    917         async_answer_0(iid, EOK);
    918 
    919         fibril_rwlock_read_unlock(&device_tree.rwlock);
    920         fun_del_ref(fun);
    921         free(buffer);
    922 }
    923857
    924858/** Get device path. */
     
    11491083                        devman_fun_get_name(callid, &call);
    11501084                        break;
    1151                 case DEVMAN_FUN_GET_DRIVER_NAME:
    1152                         devman_fun_get_driver_name(callid, &call);
    1153                         break;
    11541085                case DEVMAN_FUN_GET_PATH:
    11551086                        devman_fun_get_path(callid, &call);
     
    12181149                if (dev->pfun->dev != NULL)
    12191150                        driver = dev->pfun->dev->drv;
    1220                
    12211151                fwd_h = dev->pfun->handle;
    12221152        } else if (dev->state == DEVICE_USABLE) {
     
    12241154                driver = dev->drv;
    12251155                assert(driver != NULL);
    1226                
     1156
    12271157                fwd_h = handle;
    12281158        }
     
    12511181
    12521182        if (fun != NULL) {
    1253                 log_msg(LVL_DEBUG,
     1183                log_msg(LVL_DEBUG, 
    12541184                    "Forwarding request for `%s' function to driver `%s'.",
    12551185                    fun->pathname, driver->name);
    12561186        } else {
    1257                 log_msg(LVL_DEBUG,
     1187                log_msg(LVL_DEBUG, 
    12581188                    "Forwarding request for `%s' device to driver `%s'.",
    12591189                    dev->pfun->pathname, driver->name);
     
    12631193        async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE);
    12641194        async_exchange_end(exch);
    1265        
     1195
    12661196cleanup:
    12671197        if (dev != NULL)
    12681198                dev_del_ref(dev);
    1269        
    12701199        if (fun != NULL)
    12711200                fun_del_ref(fun);
     
    13701299                return false;
    13711300        }
    1372        
     1301
    13731302        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    1374        
     1303
    13751304        /* Create root device node. */
    13761305        if (!init_device_tree(&device_tree, &drivers_list)) {
     
    13781307                return false;
    13791308        }
    1380        
     1309
    13811310        /*
    13821311         * Caution: As the device manager is not a real loc
     
    13931322int main(int argc, char *argv[])
    13941323{
    1395         printf("%s: HelenOS Device Manager\n", NAME);
    1396        
    1397         int rc = log_init(NAME, LVL_WARN);
    1398         if (rc != EOK) {
    1399                 printf("%s: Error initializing logging subsystem.\n", NAME);
    1400                 return rc;
     1324        printf(NAME ": HelenOS Device Manager\n");
     1325
     1326        if (log_init(NAME, LVL_WARN) != EOK) {
     1327                printf(NAME ": Error initializing logging subsystem.\n");
     1328                return -1;
    14011329        }
    14021330       
     
    14051333        async_set_client_data_destructor(devman_client_data_destroy);
    14061334        async_set_client_connection(devman_connection);
    1407        
     1335
    14081336        if (!devman_init()) {
    14091337                log_msg(LVL_ERROR, "Error while initializing service.");
    14101338                return -1;
    14111339        }
    1412        
     1340
    14131341        /* Register device manager at naming service. */
    1414         rc = service_register(SERVICE_DEVMAN);
    1415         if (rc != EOK) {
     1342        if (service_register(SERVICE_DEVMAN) != EOK) {
    14161343                log_msg(LVL_ERROR, "Failed registering as a service.");
    1417                 return rc;
    1418         }
    1419        
    1420         printf("%s: Accepting connections.\n", NAME);
     1344                return -1;
     1345        }
     1346
     1347        printf(NAME ": Accepting connections.\n");
    14211348        task_retval(0);
    14221349        async_manager();
    1423        
     1350
    14241351        /* Never reached. */
    14251352        return 0;
Note: See TracChangeset for help on using the changeset viewer.