LIST_HEAD macros and family

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

 



Hi all
went through LIST_HEAD macros and family.
Looks a little confusing though but shall learn using them as they are
now used extensively across the kernel.

I have a query reagrding it.
consider the code snippet----

----------------------------In sample.h -----------------------------
 struct B;

  struct A {
     int a,
     void *b;
     struct B *head;
 };

/*i want linked list for struct B not A */
  struct B {
     char b;
     struct list_head next;
     void *buf;
 };

--------------------------sample.c------------------

int fun()
{
    struct A *dev = kmalloc(sizeof(*dev), GFP_KERNEL);
    /*error checking here*/
   ....
   while( some conditon is true) {
       dev->head = kmalloc(sizeof( *(dev->head)), GFP_KERNEL);
      /*error checking here*/
      ....

  }

 /* traverse the list and do something */


}

I want to use the list* family of macros to avoid writing my own
doubly linked list for keeping struct B pointers list in struct A.

A little help here with the MACROS shall be great.

How am i supposed to use them in this case, where an indirect linked
list( of struct B here) is required rather than in the main structure(
struct A here) itself?

Rather i should ask if i need to kmalloc again for each addition to
the list, why use the MACROS? May be they make coding easier but
certainly a little weird it seems to me.

Any help?

Thank you

--
play the game

--
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