Ignore:
File:
1 edited

Legend:

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

    r77ad86c r9d58539  
    125125static void driver_dev_add(ipc_callid_t iid, ipc_call_t *icall)
    126126{
     127        char *dev_name = NULL;
     128        int res;
     129       
    127130        devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
    128131        devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
    129132       
    130133        ddf_dev_t *dev = create_device();
    131        
     134
    132135        /* Add one reference that will be dropped by driver_dev_remove() */
    133136        dev_add_ref(dev);
    134137        dev->handle = dev_handle;
    135        
    136         char *dev_name = NULL;
     138
    137139        async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
    138140        dev->name = dev_name;
    139        
     141
    140142        /*
    141143         * Currently not used, parent fun handle is stored in context
     
    144146        (void) parent_fun_handle;
    145147       
    146         int res = driver->driver_ops->dev_add(dev);
     148        res = driver->driver_ops->dev_add(dev);
    147149       
    148150        if (res != EOK) {
     
    161163static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall)
    162164{
    163         devman_handle_t devh = IPC_GET_ARG1(*icall);
     165        devman_handle_t devh;
     166        ddf_dev_t *dev;
     167        int rc;
     168       
     169        devh = IPC_GET_ARG1(*icall);
    164170       
    165171        fibril_mutex_lock(&devices_mutex);
    166         ddf_dev_t *dev = driver_get_device(devh);
     172        dev = driver_get_device(devh);
    167173        if (dev != NULL)
    168174                dev_add_ref(dev);
     
    173179                return;
    174180        }
    175        
    176         int rc;
    177181       
    178182        if (driver->driver_ops->dev_remove != NULL)
     
    189193static void driver_dev_gone(ipc_callid_t iid, ipc_call_t *icall)
    190194{
    191         devman_handle_t devh = IPC_GET_ARG1(*icall);
     195        devman_handle_t devh;
     196        ddf_dev_t *dev;
     197        int rc;
     198       
     199        devh = IPC_GET_ARG1(*icall);
    192200       
    193201        fibril_mutex_lock(&devices_mutex);
    194         ddf_dev_t *dev = driver_get_device(devh);
     202        dev = driver_get_device(devh);
    195203        if (dev != NULL)
    196204                dev_add_ref(dev);
     
    201209                return;
    202210        }
    203        
    204         int rc;
    205211       
    206212        if (driver->driver_ops->dev_gone != NULL)
     
    217223static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall)
    218224{
    219         devman_handle_t funh = IPC_GET_ARG1(*icall);
     225        devman_handle_t funh;
     226        ddf_fun_t *fun;
     227        int rc;
     228       
     229        funh = IPC_GET_ARG1(*icall);
    220230       
    221231        /*
     
    226236        fibril_mutex_lock(&functions_mutex);
    227237       
    228         ddf_fun_t *fun = driver_get_function(funh);
     238        fun = driver_get_function(funh);
    229239        if (fun != NULL)
    230240                fun_add_ref(fun);
     
    238248       
    239249        /* Call driver entry point */
    240         int rc;
    241        
    242250        if (driver->driver_ops->fun_online != NULL)
    243251                rc = driver->driver_ops->fun_online(fun);
     
    252260static void driver_fun_offline(ipc_callid_t iid, ipc_call_t *icall)
    253261{
    254         devman_handle_t funh = IPC_GET_ARG1(*icall);
     262        devman_handle_t funh;
     263        ddf_fun_t *fun;
     264        int rc;
     265       
     266        funh = IPC_GET_ARG1(*icall);
    255267       
    256268        /*
     
    261273        fibril_mutex_lock(&functions_mutex);
    262274       
    263         ddf_fun_t *fun = driver_get_function(funh);
     275        fun = driver_get_function(funh);
    264276        if (fun != NULL)
    265277                fun_add_ref(fun);
     
    273285       
    274286        /* Call driver entry point */
    275         int rc;
    276        
    277287        if (driver->driver_ops->fun_offline != NULL)
    278288                rc = driver->driver_ops->fun_offline(fun);
     
    587597void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
    588598{
     599        void *data;
     600
    589601        assert(dev->driver_data == NULL);
    590        
    591         void *data = calloc(1, size);
     602
     603        data = calloc(1, size);
    592604        if (data == NULL)
    593605                return NULL;
    594        
     606
    595607        dev->driver_data = data;
    596608        return data;
     
    622634ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
    623635{
    624         ddf_fun_t *fun = create_function();
     636        ddf_fun_t *fun;
     637
     638        fun = create_function();
    625639        if (fun == NULL)
    626640                return NULL;
    627        
     641
    628642        /* Add one reference that will be dropped by ddf_fun_destroy() */
    629643        fun->dev = dev;
    630644        fun_add_ref(fun);
    631        
     645
    632646        fun->bound = false;
    633647        fun->ftype = ftype;
    634        
     648
    635649        fun->name = str_dup(name);
    636650        if (fun->name == NULL) {
     
    638652                return NULL;
    639653        }
    640        
     654
    641655        return fun;
    642656}
     
    645659void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
    646660{
     661        void *data;
     662
    647663        assert(fun->bound == false);
    648664        assert(fun->driver_data == NULL);
    649        
    650         void *data = calloc(1, size);
     665
     666        data = calloc(1, size);
    651667        if (data == NULL)
    652668                return NULL;
    653        
     669
    654670        fun->driver_data = data;
    655671        return data;
     
    661677 * must not be bound.
    662678 *
    663  * @param fun Function to destroy
    664  *
     679 * @param fun           Function to destroy
    665680 */
    666681void ddf_fun_destroy(ddf_fun_t *fun)
    667682{
    668683        assert(fun->bound == false);
    669        
     684
    670685        /*
    671686         * Drop the reference added by ddf_fun_create(). This will deallocate
     
    682697        if (fun->ops == NULL)
    683698                return NULL;
    684        
    685699        return fun->ops->interfaces[idx];
    686700}
     
    695709 * the same name.
    696710 *
    697  * @param fun Function to bind
    698  *
    699  * @return EOK on success or negative error code
    700  *
     711 * @param fun           Function to bind
     712 * @return              EOK on success or negative error code
    701713 */
    702714int ddf_fun_bind(ddf_fun_t *fun)
     
    705717        assert(fun->name != NULL);
    706718       
     719        int res;
     720       
    707721        add_to_functions_list(fun);
    708         int res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
     722        res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
    709723            fun->dev->handle, &fun->handle);
    710724        if (res != EOK) {
     
    722736 * the function invisible to the system.
    723737 *
    724  * @param fun Function to unbind
    725  *
    726  * @return EOK on success or negative error code
    727  *
     738 * @param fun           Function to unbind
     739 * @return              EOK on success or negative error code
    728740 */
    729741int ddf_fun_unbind(ddf_fun_t *fun)
    730742{
     743        int res;
     744       
    731745        assert(fun->bound == true);
    732746       
    733         int res = devman_remove_function(fun->handle);
     747        res = devman_remove_function(fun->handle);
    734748        if (res != EOK)
    735749                return res;
    736        
     750
    737751        remove_from_functions_list(fun);
    738752       
     
    743757/** Online function.
    744758 *
    745  * @param fun Function to online
    746  *
    747  * @return EOK on success or negative error code
    748  *
     759 * @param fun           Function to online
     760 * @return              EOK on success or negative error code
    749761 */
    750762int ddf_fun_online(ddf_fun_t *fun)
    751763{
     764        int res;
     765       
    752766        assert(fun->bound == true);
    753767       
    754         int res = devman_drv_fun_online(fun->handle);
     768        res = devman_drv_fun_online(fun->handle);
    755769        if (res != EOK)
    756770                return res;
     
    761775/** Offline function.
    762776 *
    763  * @param fun Function to offline
    764  *
    765  * @return EOK on success or negative error code
    766  *
     777 * @param fun           Function to offline
     778 * @return              EOK on success or negative error code
    767779 */
    768780int ddf_fun_offline(ddf_fun_t *fun)
    769781{
     782        int res;
     783       
    770784        assert(fun->bound == true);
    771785       
    772         int res = devman_drv_fun_offline(fun->handle);
     786        res = devman_drv_fun_offline(fun->handle);
    773787        if (res != EOK)
    774788                return res;
     
    782796 * Cannot be called when the function node is bound.
    783797 *
    784  * @param fun          Function
    785  * @param match_id_str Match string
    786  * @param match_score  Match score
    787  *
    788  * @return EOK on success.
    789  * @return ENOMEM if out of memory.
    790  *
     798 * @param fun                   Function
     799 * @param match_id_str          Match string
     800 * @param match_score           Match score
     801 * @return                      EOK on success, ENOMEM if out of memory.
    791802 */
    792803int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
    793804    int match_score)
    794805{
     806        match_id_t *match_id;
     807       
    795808        assert(fun->bound == false);
    796809        assert(fun->ftype == fun_inner);
    797810       
    798         match_id_t *match_id = create_match_id();
     811        match_id = create_match_id();
    799812        if (match_id == NULL)
    800813                return ENOMEM;
     
    818831 *
    819832 * Must only be called when the function is bound.
    820  *
    821833 */
    822834int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name)
     
    830842int ddf_driver_main(driver_t *drv)
    831843{
     844        int rc;
     845
    832846        /*
    833847         * Remember the driver structure - driver_ops will be called by generic
     
    844858         */
    845859        async_set_client_connection(driver_connection);
    846         int rc = devman_driver_register(driver->name);
     860        rc = devman_driver_register(driver->name);
    847861        if (rc != EOK) {
    848862                printf("Error: Failed to register driver with device manager "
     
    850864                    str_error(rc));
    851865               
    852                 return rc;
     866                return 1;
    853867        }
    854868       
     
    856870        rc = task_retval(0);
    857871        if (rc != EOK)
    858                 return rc;
    859        
     872                return 1;
     873
    860874        async_manager();
    861875       
    862876        /* Never reached. */
    863         return EOK;
     877        return 0;
    864878}
    865879
Note: See TracChangeset for help on using the changeset viewer.