Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Nov 2005 10:36:07 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        rashmi ns <nsrashmi@gmail.com>, bugi@lists.redbrick.dcu.ie
Subject:   Re: Driver crashes after unloading a module
Message-ID:  <200511211036.08460.jhb@freebsd.org>
In-Reply-To: <9f9993160511200804w177a521s9cddc6e56afe221e@mail.gmail.com>
References:  <9f9993160511200804w177a521s9cddc6e56afe221e@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sunday 20 November 2005 11:04 am, rashmi ns wrote:
>   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);
>
> }

As a first guess, do this later since you might still get an open request up 
until your call to destroy_dev().  Also, you might need to create a purge 
routine your devsw if threads can block in your devsw routines and wakeup any 
sleepers in your purge handler so that when destroy-dev() returns you know 
that all threads are out of your driver.

>  /*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"

-- 
John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200511211036.08460.jhb>