How to add the first element in a list of type struct list_head

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I've another (perhaps the last) problem with the creation of dynamic linked 
list with the <linux/list.h> macros.
I simplify the structures I use to better explain the problem.

struct pages{
 struct list_head list;
 unsigned long address;
};

struct vma{
 ..........
 .........
 struct pages *pages;
}

what's the way I add the first element?
I prove two ways:
WAY 1.
 struct pages *page;

 page = kmalloc(.......);
 INIT_LIST_HEAD (&pages->list);
 for all memory pages P do
   P->address = 0x....;
   list_add(&P->list, &pages->list);

WAY 2.
 struct vma *vm;

 ..............
 
 for all memory pages P do
   if P is the first memory page then
     P->address = 0x...;
     INIT_LIST_HEAD(&(vm->pages)->list);
     list_add(&P->list, &(vm->pages)->list);
   else
     list_add(&P->list, &(vm->pages)->list);

In each of the two ways all elements (pages) but the first one are store in 
the list.
Someone know why?
Thanks.
Vincenzo Mallozzi.

P.S. I hope my description is understandable.

		
___________________________________ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.beta.messenger.yahoo.com


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux