title: When writing kernel modules, how do you assign a char pointer a string value?
body: <p>I'm working on a practice project and have hit a bump. I'm trying to write a simple kernel module that creates several birthday records and prints their values to the kernel log buffer. I am having difficulty figuring out how to assign string values to char pointers in the record. This is my code:</p>
  
  <pre><code>#include &lt;linux/string.h&gt;
  #include &lt;linux/init.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/list.h&gt;
  #include &lt;linux/slab.h&gt;
  
  struct birthday{
      int day;
      int month;
      int year;
      char *name;
      struct list_head list;
  };
  static LIST_HEAD(birthday_list);
  
  /*this fn is called when the module is loaded*/
  int simple_init(void){
      struct birthday *ptr;
      struct birthday *person;
      person = kmalloc(sizeof(*person), GFP_KERNEL);
      person-&gt;day=22;
      person-&gt;month=7;
      person-&gt;year=1990;
      strcpy(person-&gt;name, "Jane");
  
      struct birthday *person2;
      person2 = kmalloc(sizeof(*person2), GFP_KERNEL);
      person2-&gt;day=4;
      person2-&gt;month=3;
      person2-&gt;year=1990;
      strcpy(person-&gt;name, "Michael");
  
      struct birthday *person3;
      person3 = kmalloc(sizeof(*person3), GFP_KERNEL);
      person3-&gt;day=4;
      person3-&gt;month=3;
      person3-&gt;year=1990;
      strcpy(person-&gt;name, "Tom");
  
      struct birthday *person4;
      person4 = kmalloc(sizeof(*person4), GFP_KERNEL);
      person4-&gt;day=4;
      person4-&gt;month=4;
      person4-&gt;year=1990;
      strcpy(person-&gt;name, "Lacey");
  
      struct birthday *person5;
      person5 = kmalloc(sizeof(*person5), GFP_KERNEL);
      person5-&gt;day=4;
      person5-&gt;month=5;
      person5-&gt;year=1990;
      strcpy(person-&gt;name, "Ruth");
  
  
      INIT_LIST_HEAD(&amp;person-&gt;list);
      list_add_tail(&amp;person-&gt;list, &amp;birthday_list);
      list_add_tail(&amp;person2-&gt;list, &amp;birthday_list);
      list_add_tail(&amp;person3-&gt;list, &amp;birthday_list);
      list_add_tail(&amp;person4-&gt;list, &amp;birthday_list);
      list_add_tail(&amp;person5-&gt;list, &amp;birthday_list);
  
      printk(KERN_INFO "Module initialized");
      list_for_each_entry(ptr,&amp;birthday_list, list){
          printk(KERN_INFO "Name: %s, Birthday: %d/%d/%d\n",ptr-&gt;name,ptr-&gt;month,ptr-&gt;day,ptr-&gt;year);
      }
      return 0;
  }
  
  /*this fn is called when the module is removed*/
  void simple_exit(void){
      struct birthday *ptr, *next;
  
      list_for_each_entry_safe(ptr, next, &amp;birthday_list, list){
          list_del(&amp;ptr-&gt;list);
          kfree(ptr);
      }
  
      printk(KERN_INFO "Removing module\n");
  }
  /*macros for registering module entrance and exit points*/
  module_init(simple_init);
  module_exit(simple_exit);
  </code></pre>
  
  <p>The code compiles and works when I get rid of the string attribute and all instructions associated with it. As is, the code compiles but when I run it the system freezes. Thanks folks!</p>