Changeset de16f89 in mainline


Ignore:
Timestamp:
2014-09-05T08:52:51Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
089901e
Parents:
3fec817
Message:

Add cleanup code to error paths.

Location:
uspace/drv/audio/hdaudio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/hdaudio/hdactl.c

    r3fec817 rde16f89  
    217217        return EOK;
    218218error:
     219        if (hda->ctl->corb_virt != NULL)
     220                dmamem_unmap_anonymous(&hda->ctl->corb_virt);
    219221        return EIO;
     222}
     223
     224/** Tear down the CORB */
     225static void hda_corb_fini(hda_t *hda)
     226{
     227        uint8_t ctl;
     228
     229        /* Stop CORB */
     230        ctl = hda_reg8_read(&hda->regs->corbctl);
     231        hda_reg8_write(&hda->regs->corbctl, ctl & ~BIT_V(uint8_t, corbctl_run));
     232
     233        if (hda->ctl->corb_virt != NULL)
     234                dmamem_unmap_anonymous(&hda->ctl->corb_virt);
    220235}
    221236
     
    290305        return EOK;
    291306error:
     307        if (hda->ctl->rirb_virt != NULL)
     308                dmamem_unmap_anonymous(&hda->ctl->rirb_virt);
    292309        return EIO;
     310}
     311
     312/** Tear down the RIRB */
     313static void hda_rirb_fini(hda_t *hda)
     314{
     315        uint8_t ctl;
     316
     317        /* Stop RIRB and disable RIRB interrupt */
     318        ctl = hda_reg8_read(&hda->regs->rirbctl);
     319        hda_reg8_write(&hda->regs->rirbctl, ctl &
     320            ~(BIT_V(uint8_t, rirbctl_run) | BIT_V(uint8_t, rirbctl_int)));
     321
     322        if (hda->ctl->rirb_virt != NULL)
     323                dmamem_unmap_anonymous(&hda->ctl->rirb_virt);
    293324}
    294325
     
    571602        return ctl;
    572603error:
     604        hda_rirb_fini(hda);
     605        hda_corb_fini(hda);
    573606        free(ctl);
    574607        hda->ctl = NULL;
    575608        return NULL;
     609}
     610
     611void hda_ctl_fini(hda_ctl_t *ctl)
     612{
     613        ddf_msg(LVL_NOTE, "hda_ctl_fini()");
     614        hda_rirb_fini(ctl->hda);
     615        hda_corb_fini(ctl->hda);
     616        free(ctl);
    576617}
    577618
     
    595636
    596637        return EOK;
    597 }
    598 
    599 void hda_ctl_fini(hda_ctl_t *ctl)
    600 {
    601         ddf_msg(LVL_NOTE, "hda_ctl_fini()");
    602         free(ctl);
    603638}
    604639
  • uspace/drv/audio/hdaudio/hdaudio.c

    r3fec817 rde16f89  
    150150static int hda_dev_add(ddf_dev_t *dev)
    151151{
    152         ddf_fun_t *fun_pcm;
     152        ddf_fun_t *fun_pcm = NULL;
    153153        hda_t *hda = NULL;
    154154        hw_res_list_parsed_t res;
    155155        irq_code_t irq_code;
    156         irq_cmd_t *cmds;
     156        irq_cmd_t *cmds = NULL;
    157157        size_t ncmds_base;
    158158        size_t ncmds_sdesc;
    159159        size_t ncmds;
    160160        int i;
    161         void *regs;
     161        void *regs = NULL;
    162162        int rc;
    163163
    164164        ddf_msg(LVL_NOTE, "hda_dev_add()");
     165        hw_res_list_parsed_init(&res);
    165166
    166167        hda = ddf_dev_data_alloc(dev, sizeof(hda_t));
     
    181182
    182183        ddf_msg(LVL_NOTE, "get HW res list");
    183         hw_res_list_parsed_init(&res);
    184184        rc = hw_res_get_list_parsed(hda->parent_sess, &res, 0);
    185185        if (rc != EOK) {
     
    270270        }
    271271
     272        free(cmds);
     273        cmds = NULL;
     274
    272275        if (hda_ctl_init(hda) == NULL) {
    273276                rc = EIO;
     
    295298
    296299        ddf_fun_add_to_category(fun_pcm, "audio-pcm");
     300
     301        hw_res_list_parsed_clean(&res);
    297302        return EOK;
    298303error:
     304        if (fun_pcm != NULL)
     305                ddf_fun_destroy(fun_pcm);
    299306        if (hda != NULL) {
    300307                if (hda->ctl != NULL)
    301308                        hda_ctl_fini(hda->ctl);
    302309        }
     310        free(cmds);
     311        // pio_disable(regs);
     312        hw_res_list_parsed_clean(&res);
    303313
    304314        ddf_msg(LVL_NOTE, "Failing hda_dev_add() -> %d", rc);
     
    323333        }
    324334
     335        hda_ctl_fini(hda->ctl);
     336        // pio_disable(regs);
    325337        return EOK;
    326338}
Note: See TracChangeset for help on using the changeset viewer.