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
struct data{
struct data *next;
struct msghdr *msg;
size_t len;
}
I make a head as global variable.
struct data *head = NULL;
I have a add_to_end function
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->next!=NULL) {
temp1 = temp->next;
}
temp1->next = newData;
}
}
in one of my functions, I use add_to_end like this
struct data *temp;
temp = (struct data *)kmalloc(sizeof(struct data),GFP_KERNEL);
temp->next = NULL;
temp->msg = (struct msghdr *)kmalloc(sizeof(struct msghdr),GFP_KERNEL);
temp->msg = message;
temp->len = length;
add_to_end(temp);
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.
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?