title: making a linked list in kernel module
body: <p>I was trying to make a linked list working for my module, I am not using the build-in kernel linked list( I don't know that thing exist at the moment when I started making my module). 
  here is my struct</p>
  
  <pre><code>struct data{
      struct data *next;
      struct msghdr *msg;
      size_t len;
  }
  </code></pre>
  
  <p>I make a head as global variable.</p>
  
  <pre><code>struct data *head = NULL;
  </code></pre>
  
  <p>I have a add_to_end function </p>
  
  <pre><code>void add_to_end(struct data *newData){
      struct data *temp1;
      if (head == NULL){
          head = (struct data *)kmalloc(sizeof(struct data),GFP_KERNEL);
          head = newData;
      } else {
          temp1 = (struct data *)kmalloc(sizeof(struct data),GFP_KERNEL);
          temp1 = head;
          while(temp1-&gt;next!=NULL) {
              temp1 = temp-&gt;next;
          }
          temp1-&gt;next = newData;
      }
  }
  </code></pre>
  
  <p>in one of my functions, I use add_to_end like this</p>
  
  <pre><code>struct data *temp;
  
  temp = (struct data *)kmalloc(sizeof(struct data),GFP_KERNEL);
  temp-&gt;next = NULL;
  temp-&gt;msg = (struct msghdr *)kmalloc(sizeof(struct msghdr),GFP_KERNEL);
  temp-&gt;msg = message;
  temp-&gt;len = length;
  add_to_end(temp);
  </code></pre>
  
  <p>but when I am trying to use the msg in this linked list, error happens. The kernel print some trace thing to the terminal.
  What I want to do is copy the message into my linked list, but as a separate copy, not just copying the pointer that point to the address. I have read some examples that when copying two struct, they actually using the same address, when changing one of them, both of them got changed. I don't want that kind of copy, I want a separate copy with its own address.</p>
  
  <p>I am guessing that the way that I copy the two struct is not right and maybe my linked list is not right too, can someone help me please?</p>