[pso] list_head si kfree()
Andrei Costin
pso@cursuri.cs.pub.ro
Sat, 27 Mar 2004 09:50:49 -0800 (PST)
Salut.
.... eu cred ca nu mai stiu sa deloc list_head-ul asta...
In module_init am ceva de genul (OBS: source code pentru test, nu are legatura DIRECTA!!!
cu source code pentru tema)
(mai am declarata globala "static LIST_HEAD(the_list);")
-----------------------------------------------------
...
struct my_use *mu;
struct list_head *tmp;
...
mu = kmalloc(sizeof(*mu), GFP_KERNEL);
if (!mu)
{
printk ( "kmalloc() no mem\n" );
return -ENOMEM;
}
kfree(mu); <------- KFREE-ul asta nu da segmentation fault
// Populez lista
for (i=0; i<100; i++)
{
if ( !(mu = kmalloc(sizeof(*mu), GFP_KERNEL)) )
{
printk( "-ENOMEM\n" );
// Trebuie sa eliberez ce am alocat anterior, dar aici nu asta
conteaza, oricum kmalloc-u aici merge ok
return -ENOMEM;
}
memset(mu, 0, sizeof(*mu));
mu->mu_i = i;
list_add(&(mu->mu_list), &the_list);
}
list_for_each(tmp, &the_list)
{
mu = list_entry(tmp, struct monitor_unit, mu_list);
printk( "i=(%d)\n", mu->mu_i );
list_del( &(mu->mu_list) ); <------- Da mereu segmentation fault
kfree(mu); <------- Da mereu segmentation fault
}
-------------------------------------------------------------------------------------------
Modulul dupa asta da un OPPS...
Best regards & respect,
Andrei Costin (mailto:zveriu_biz@yahoo.com)
___________________________________________
Manifest - ".M D - My Domain!" - by .Zveriu.
y o
m
a
i
n
__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html