Date: Mon, 12 Jan 2009 15:00:20 +0100 From: Hans Petter Selasky <hselasky@c2i.net> To: freebsd-hackers@freebsd.org, Alexej Sokolov <bsd.quest@googlemail.com> Subject: Re: panic by unlocking of mutex in KLD Message-ID: <200901121500.21657.hselasky@c2i.net> In-Reply-To: <20090112134726.GA2988@debian.samsung.router> References: <20090112134726.GA2988@debian.samsung.router>
next in thread | previous in thread | raw e-mail | index | archive | help
On Monday 12 January 2009, Alexej Sokolov wrote:
> Hello,
>
> by unloading of folowing module I have kernel panic.
>
> I would like to get any explanation about my mistake.
>
> #include <sys/param.h>
> #include <sys/module.h>
> #include <sys/kernel.h>
> #include <sys/systm.h>
> #include <sys/queue.h>
> #include <sys/kernel.h>
> #include <sys/kobj.h>
> #include <sys/malloc.h>
> #include <sys/types.h>
> #include <sys/lock.h>
> #include <sys/mutex.h>
>
>
> struct mtx my_mtx;
>
>
> /* Load handler */
> static int
> load(struct module *mod, int cmd, void *arg)
> {
> int error = 0;
> switch(cmd) {
> case MOD_LOAD:
> printf("Start! Addres of mutex = 0x%X \n",
> &my_mtx);
> mtx_init(&my_mtx, "My mutex name", "My mutex
> type", MTX_DEF);
>
> mtx_lock(&my_mtx);
> break;
> case MOD_UNLOAD:
> printf("Stop! Addres of mutex = 0x%X \n",
> &my_mtx);
> mtx_unlock(&my_mtx);
> break;
> default:
> error = EOPNOTSUPP;
> break;
> }
>
> return (error);
> }
>
> /* Module structure */
> static moduledata_t mod_data = {
> "mymod",
> load,
> NULL
> };
> MODULE_VERSION (kld, 1);
> DECLARE_MODULE (kld, mod_data, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
>
>
> Thanx
Hi,
You cannot do like this. Remember, two different threads are doing the
load/unload. The mutex is associated with a thread. Print out "curthread"
aswell and you will see. The mutex can only be unlocked by the same thread
that locked it.
--HPS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901121500.21657.hselasky>
