Driver crashes after unloading a module

From: rashmi ns (nsrashmi_at_gmail.com)
Date: 11/20/05

  • Next message: Yong Ma: "Re: a puzzle about FreeBSD"
    Date: Sun, 20 Nov 2005 21:34:29 +0530
    To: bugi@lists.redbrick.dcu.ie, freebsd-hackers@freebsd.org
    
    

      Hello List ,

    Thanks for the help you given me .

     We have written driver for hdlc controller .The kernel is crashing
    after unloading
    the module with trap 12 fault .here is the order in which we release the
    resources while detaching the device.

    1. stop polling timer(if polling mode)

    2. destroy_dev()

    3. disable the device

    4. free Tx and Rx structures

    5. deallocate allocated dma memory

    6. bus_deactivate_resource(irq)

    7. release all bus resources

    here is the piece of code

    /*release bus resources*/

    static void hdlc_release(struct hdlc_softc *sc)

    {

     dbgprint("Entering");

     bus_generic_detach(sc->dev);

    /*Release the resources held*/

    if (sc->irq){

     bus_teardown_intr(sc->dev, sc->irq,sc->int_handler_tag);

    sc->int_handler_tag = NULL;

      bus_release_resource(sc->dev, SYS_RES_IRQ,sc->irq_rid, sc->irq);

    dbgprint("deallocated irq res irq_rid = %d\n",sc->irq_rid);

    }

     if (sc->mem){

    bus_release_resource (sc->dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem);

    dbgprint("deallocated bus res\n");

    }

    if(&sc->sc_mtx)

    mtx_destroy(&sc->sc_mtx);

    }

     /*detach function*/

    static int hdlc_detach(device_t dev)

    {

     struct hdlc_softc *sc = device_get_softc(dev);

    int s;

     dbgprint("Entering\n");

    s=splimp();

     /*If drv is in poll mode then stop the poll timer */

    if(sc->intr_mode == 0)

    hdlc_clear_poll_mode(sc);

     if(!(sc->hdlc_cdev == NULL) ){

    destroy_dev(sc->hdlc_cdev);

    }

     /*stop the controller */

    hdlc_hw_reset(sc);

       /*free hdlc Tx and Rx structures */

    hdlc_stop(sc);

     /*deallocate allocated dma memory*/

    hdlc_free_descriptors(sc);

     bus_deactivate_resource(sc->dev,SYS_RES_IRQ,sc->irq_rid,sc->irq);

    splx(s);

    /*free bus resources*/

    hdlc_release(sc);

    uprintf("Detached\n");

    return 0;

     }

        After unloading the module the it gives the debug print "Module
    unloaded" kld_loader function from and kernel crashes with trap 12 .Kindly
    let me know does the order of releasing the resources is the reason for
    this.

      Thanks and regards,

    Rashmi.n.s
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Yong Ma: "Re: a puzzle about FreeBSD"

    Relevant Pages