Changeset eadaeae8 in mainline for uspace/drv/char


Ignore:
Timestamp:
2018-03-21T20:58:49Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3be9d10
Parents:
874381a
Message:

Make capability handles type-safe

Define distinct pointer types for the handles of the supported
capability types and use them instead of integer handles. This makes it
virtually impossible to pass a non-handle or a handle of different type
instead of the proper handle. Also turn cap_handle_t into an "untyped"
capability handle that can be assigned to and from the "typed" handles.

This commit also fixes a bug in msim-con driver, which wrongly used the
IRQ number instead of the IRQ capability handle to unregister the IRQ.

This commit also fixes the wrong use of the capability handle instead
of error code in libusbhost.

Location:
uspace/drv/char
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/i8042/i8042.c

    r874381a readaeae8  
    281281        };
    282282
    283         int irq_kbd_cap;
     283        cap_irq_handle_t kbd_ihandle;
    284284        rc = register_interrupt_handler(ddf_dev, irq_kbd,
    285             i8042_irq_handler, &irq_code, &irq_kbd_cap);
     285            i8042_irq_handler, &irq_code, &kbd_ihandle);
    286286        if (rc != EOK) {
    287287                ddf_msg(LVL_ERROR, "Failed set handler for kbd: %s.",
     
    290290        }
    291291
    292         int irq_mouse_cap;
     292        cap_irq_handle_t mouse_ihandle;
    293293        rc = register_interrupt_handler(ddf_dev, irq_mouse,
    294             i8042_irq_handler, &irq_code, &irq_mouse_cap);
     294            i8042_irq_handler, &irq_code, &mouse_ihandle);
    295295        if (rc != EOK) {
    296296                ddf_msg(LVL_ERROR, "Failed set handler for mouse: %s.",
  • uspace/drv/char/msim-con/msim-con.c

    r874381a readaeae8  
    8383{
    8484        ddf_fun_t *fun = NULL;
    85         bool subscribed = false;
    8685        irq_cmd_t *msim_cmds = NULL;
    8786        errno_t rc;
     
    9089        fibril_mutex_initialize(&con->buf_lock);
    9190        fibril_condvar_initialize(&con->buf_cv);
     91
     92        con->irq_handle = CAP_NIL;
    9293
    9394        msim_cmds = malloc(sizeof(msim_cmds_proto));
     
    125126        con->irq_code.cmds = msim_cmds;
    126127
    127         async_irq_subscribe(res->irq, msim_irq_handler, con, &con->irq_code, NULL);
    128         subscribed = true;
     128        rc = async_irq_subscribe(res->irq, msim_irq_handler, con,
     129            &con->irq_code, &con->irq_handle);
     130        if (rc != EOK) {
     131                ddf_msg(LVL_ERROR, "Error registering IRQ code.");
     132                goto error;
     133        }
    129134
    130135        chardev_srvs_init(&con->cds);
     
    142147        return EOK;
    143148error:
    144         if (subscribed)
    145                 async_irq_unsubscribe(res->irq);
     149        if (CAP_HANDLE_VALID(con->irq_handle))
     150                async_irq_unsubscribe(con->irq_handle);
    146151        if (fun != NULL)
    147152                ddf_fun_destroy(fun);
  • uspace/drv/char/msim-con/msim-con.h

    r874381a readaeae8  
    6868        fibril_condvar_t buf_cv;
    6969        ioport8_t *out_reg;
     70        cap_irq_handle_t irq_handle;
    7071} msim_con_t;
    7172
  • uspace/drv/char/ns8250/ns8250.c

    r874381a readaeae8  
    165165        int irq;
    166166        /** IRQ capability handle */
    167         int irq_cap;
     167        cap_irq_handle_t irq_handle;
    168168        /** The base i/o address of the devices registers. */
    169169        uintptr_t io_addr;
     
    804804 */
    805805static inline errno_t ns8250_register_interrupt_handler(ns8250_t *ns,
    806     cap_handle_t *handle)
     806    cap_irq_handle_t *ihandle)
    807807{
    808808        return register_interrupt_handler(ns->dev, ns->irq,
    809             ns8250_interrupt_handler, NULL, handle);
     809            ns8250_interrupt_handler, NULL, ihandle);
    810810}
    811811
     
    816816static inline errno_t ns8250_unregister_interrupt_handler(ns8250_t *ns)
    817817{
    818         return unregister_interrupt_handler(ns->dev, ns->irq_cap);
     818        return unregister_interrupt_handler(ns->dev, ns->irq_handle);
    819819}
    820820
     
    876876
    877877        /* Register interrupt handler. */
    878         rc = ns8250_register_interrupt_handler(ns, &ns->irq_cap);
     878        ns->irq_handle = CAP_NIL;
     879        rc = ns8250_register_interrupt_handler(ns, &ns->irq_handle);
    879880        if (rc != EOK) {
    880881                ddf_msg(LVL_ERROR, "Failed to register interrupt handler.");
  • uspace/drv/char/pl050/pl050.c

    r874381a readaeae8  
    213213        pl050->regs = regs;
    214214
    215         int irq_cap;
     215        cap_irq_handle_t ihandle;
    216216        rc = register_interrupt_handler(pl050->dev,
    217             res.irqs.irqs[0], pl050_interrupt, &pl050_irq_code, &irq_cap);
     217            res.irqs.irqs[0], pl050_interrupt, &pl050_irq_code, &ihandle);
    218218        if (rc != EOK) {
    219219                ddf_msg(LVL_ERROR, "Failed registering interrupt handler. (%s)",
Note: See TracChangeset for help on using the changeset viewer.