kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Freeing work_struct memory
@ 2011-11-21 20:55 Kai Meyer
  2011-11-22 17:52 ` Mulyadi Santosa
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Meyer @ 2011-11-21 20:55 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-22 17:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-21 20:55 Freeing work_struct memory Kai Meyer
2011-11-22 17:52 ` Mulyadi Santosa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).