Issue using kernel linked list in user space

Gunjan Mehta gunjanmehta08 at gmail.com
Sat Sep 19 12:56:34 EDT 2015


I have a linked list like this http://pastebin.com/bwF3jLb6 . The problem i
am facing is i have initialized the list head and
 then i am doing malloc for that struct object. What i need is i want to
make struct abc_st *r as head of linked list and other nodes after it.

typedef struct abc {
char client_id[18];
    char mac[18];
    st_list_head list;
}abc_st;

abc_st* check_fields (abc_st *ptr)
{
    char cmd[500];
    MYSQL_RES *result;
    MYSQL_ROW row;
    int num_rows;
    abc_st *r=NULL,*temp=NULL;
    INIT_LIST_HEAD(&r->list);   // i have intialized the head here

    sprintf(cmd, "SELECT * FROM ABCD_TABLE WHERE MAC = %.4x", ptr->mac);
        /* Running the sql query to check for fields with value in database
*/
    if (mysql_query(abc_db.db_handle, cmd)) {
        num_rows = -1;
        goto done;
    }
    result = mysql_store_result(abc_db.db_handle);
    if (result == NULL) {
        num_rows = -1;
        goto done;
    }
    num_rows = mysql_num_rows(result);

    while ((row = mysql_fetch_row(result)))
    {
        r= (abc_st *)malloc(sizeof(abc_st));
        memcpy(r->mac,row[1],strlen(row[1])+1);
        memcpy(r->client_id,row[0],strlen(row[0])+1);
How should i use list_add ?
        //list_add(struct list_head *new, struct list_head *head)
 //prototype of list_add
       // list_add(&temp->list,&r->list);  //it will go wrong here, i want
to make r(structure r as head and then add other strutcure objects)
     //   r->link = NULL;
        //list_add(r, ptr);

    }
done:
    mysql_free_result(result);

    return r;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150919/a1854c7c/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list.h
Type: text/x-chdr
Size: 1970 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150919/a1854c7c/attachment.bin 


More information about the Kernelnewbies mailing list