All of lore.kernel.org
 help / color / mirror / Atom feed
From: kai@gnukai.com (Kai Meyer)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Freeing work_struct memory
Date: Mon, 21 Nov 2011 13:55:38 -0700	[thread overview]
Message-ID: <4ECABACA.7030701@gnukai.com> (raw)

I've got a bug I'm having trouble identifying. It seems like it could be 
related to my work_struct usage. I essentially have this:

struct my_worker {
         work_struct work;
         /* some other data */
};

void worker_fn(struct work_struct *work)
{
         struct my_worker *worker = container_of(work, struct my_worker, 
work);
         /* ... do some stuff ... */
         kfree(worker);
}

void worker_caller()
{
         struct my_worker *worker = kmalloc(sizeof(*worker), GFP_KERNEL);
         INIT_WORK(&worker->work, worker_fn);
         /* ... add some other stuff to *worker ... */
         schedule_work(&worker->work);
}

I frequently get a kernel panic with a specific test, but the stack 
trace is rarely the same, which seems to indicate to me that I'm 
corrupting data somewhere. So my question is:

Can I free the memory for "struct my_worker *worker" inside worker_fn? 
Or does the work_queue stuff need to continue to use the "struct 
work_struct work" member after the end of worker_fn?

-Kai Meyer

             reply	other threads:[~2011-11-21 20:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-21 20:55 Kai Meyer [this message]
2011-11-22 17:52 ` Freeing work_struct memory Mulyadi Santosa

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=4ECABACA.7030701@gnukai.com \
    --to=kai@gnukai.com \
    --cc=kernelnewbies@lists.kernelnewbies.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.