0

这是我的 linux 内核代码当我尝试将 char* 名称的 val 设置为我的结构中的一个字段时,我得到 null stuct 中的值始终为 null,但是如果我明确设置 person->key_day = "11"; 我没有得到空值。我想以某种方式从 char *day 和 char *name 中获取价值以分配给 person->key_day 和 person->value_name 。请帮助

     typedef struct _birthday {
     char *key_day;
     char *value_name;
        struct list_head list;
    }birthday;

    birthday *person;

    /* Declare and init the head of the linked list. */

    LIST_HEAD(birthday_list);

    void mymap(char *day , char *name)
    {

            /* Request malloc to the kernel. */
            person = kmalloc(sizeof(*person), GFP_KERNEL);

            /* Assign value to the struct. */
            person->key_day =  day;
            person->value_name = name;

            /* Init the list within the struct. */
            INIT_LIST_HEAD(&person->list);

            /* Add this struct to the tail of the list. */
            list_add_tail(&person->list, &birthday_list);

            //This print statement gives me null value.
            printk("\n New Entry %s , %s" , person->key_day , person->value_name );
    }
4

0 回答 0