From: Yong Zhang <yong.zhang0@gmail.com>
To: "Frank Sch�fer" <fschaefer.oss@googlemail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: kernel panic on device removal when using a workqueue and delayed_work
Date: Mon, 31 Oct 2011 11:11:36 +0800 [thread overview]
Message-ID: <20111031031136.GA18057@zhy> (raw)
In-Reply-To: <4EADA32E.6030200@googlemail.com>
On Sun, Oct 30, 2011 at 08:19:10PM +0100, Frank Sch�fer wrote:
> Hi,
>
> with the following simple kernel module, I have a good chance to get
> a kernel panic when I unplug the device:
>
>
> #include <linux/workqueue.h>
> #include <linux/usb.h>
> #include <linux/module.h>
>
> MODULE_AUTHOR("Nobody");
> MODULE_DESCRIPTION("example driver for causing kernel panic");
> MODULE_LICENSE("GPL");
>
> static struct delayed_work poll_work;
>
> static void poll(struct work_struct *work)
> {
> schedule_delayed_work(&poll_work,
> msecs_to_jiffies(100));
> }
>
> static int test_probe(struct usb_interface *intf,
> const struct usb_device_id *id)
> {
> INIT_DELAYED_WORK(&poll_work, poll);
> schedule_delayed_work(&poll_work,
> msecs_to_jiffies(100));
> return 0;
> }
>
> static void test_disconnect(struct usb_interface *intf)
> {
> cancel_delayed_work_sync(&poll_work);
> }
>
> static const struct usb_device_id device_table[] = {
> {USB_DEVICE(0x1234, 0x5678)},
> {}
> };
>
> MODULE_DEVICE_TABLE(usb, device_table);
>
> static struct usb_driver test_driver = {
> .name = "test",
> .id_table = device_table,
> .probe = test_probe,
> .disconnect = test_disconnect,
> };
>
> static int __init test_mod_init(void)
> {
> return usb_register(&test_driver);
> }
>
> static void __exit test_mod_exit(void)
> {
> usb_deregister(&test_driver);
> }
>
> module_init(test_mod_init);
> module_exit(test_mod_exit);
>
>
>
>
> A picture of the backtrace (the machine immediately turns off
> without saving a backtrace) can be found at
>
> http://imageshack.us/photo/my-images/823/img075gv.jpg
>
> Kernel version is 3.1.0.
>
>
> This is the first time I'm using a workqueue, so there is a good
> chance that I missed something...
You should cancel the work you have armed before exit.
See cancel_delayed_work().
> Or is this a kernel bug ?
I don't think so.
Thanks,
Yong
next prev parent reply other threads:[~2011-10-31 3:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-30 19:19 kernel panic on device removal when using a workqueue and delayed_work Frank Schäfer
2011-10-31 3:11 ` Yong Zhang [this message]
2011-10-31 10:26 ` Frank Schäfer
2011-10-31 10:29 ` Oliver Neukum
2011-11-02 20:02 ` Frank Schäfer
2011-11-02 6:31 ` Yong Zhang
2011-11-05 13:32 ` Frank Schäfer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111031031136.GA18057@zhy \
--to=yong.zhang0@gmail.com \
--cc=fschaefer.oss@googlemail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox