title: Removal of a linux kernel module
body: <p>I've created a module which utilizes the linux kernel macros. The problem is that I install the module but I cannot remove the module. What I need help with is the removal of the module.   </p>
  
  <pre><code>#include &lt;linux/init.h&gt;  
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/module.h&gt;
  #include &lt;linux/types.h&gt;
  #include &lt;linux/slab.h&gt;
  #include &lt;linux/random.h&gt;
  
  struct birthday {
      int day;
      int month;
      int year;
      struct list_head list;
  };
  
  struct birthday *my_bday, *tmp, *ptr;
  struct list_head *pos;
  
  int simple_init(void)
  {
      int i, day,month,year;
      my_bday = kmalloc(sizeof(*my_bday), GFP_KERNEL);
      my_bday-&gt;day = 30;
      my_bday-&gt;month=5;
      my_bday-&gt;year=1984;
  
      /* set my_bday to head of list*/
  
      INIT_LIST_HEAD(&amp;(my_bday-&gt;list));
      printk(KERN_INFO "Loading Module\n");
      for(i=0; i&lt;5; ++i){
          ptr = kmalloc(sizeof(*ptr), GFP_KERNEL);    
          //random birthday variables
      get_random_bytes(&amp;day, 1);
      ptr-&gt;day = day % 31;
      if(ptr-&gt;day &lt; 0)
          ptr-&gt;day = ptr-&gt;day * -1;
  
      get_random_bytes(&amp;month, 1);
      ptr-&gt;month = month % 12;
  
      if(ptr-&gt;month &lt; 0)
          ptr-&gt;month = ptr-&gt;month * -1;
  
      get_random_bytes(&amp;year, 1);
      ptr-&gt;year = (year % 2000)+1900;
  
      if(ptr-&gt;year &lt; 0)
          ptr-&gt;year = ptr-&gt;year * -1;
  
      list_add(&amp;(ptr-&gt;list), &amp;(my_bday-&gt;list));
      }
  
      printk(KERN_INFO "traversing the list using list_for_each()\n");
      list_for_each(pos, &amp;(my_bday-&gt;list)){
          tmp = list_entry(pos, struct birthday, list);
          printk("day = %d month = %d year = %d\n", tmp-&gt;day, tmp-&gt;month, tmp-&gt;year);
      }
      return 0;
  }
  
  void simple_exit(void)
  {
      printk(KERN_INFO "Removing Module\n");  
      list_for_each(pos, &amp;(my_bday-&gt;list)){
          tmp = list_entry(pos, struct birthday, list);
          list_del(&amp;tmp-&gt;list);
          kfree(tmp);
      }
  
  }
  
  module_init(simple_init);
  
  module_exit(simple_exit);
  </code></pre>
  
  <p><b>The dmesg buffer reads the following:</b></p>
  
  <pre><code>[  477.267204] birthday: module license 'unspecified' taints kernel.
  [  477.267296] Disabling lock debugging due to kernel taint
  [  477.317017] Loading Module
  [  477.317480] traversing the list using list_for_each()
  [  477.317593] day = 7 month = 2 year = 2049
  [  477.317630] day = 29 month = 9 year = 2135
  [  477.317637] day = 2 month = 11 year = 2070
  [  477.317642] day = 14 month = 2 year = 2081
  [  477.317647] day = 9 month = 7 year = 1912
  [  505.151618] Removing Module
  [  505.152957] BUG: unable to handle kernel paging request at 00100104
  [  505.154584] IP: [&lt;f9dd8236&gt;] cleanup_module+0x36/0xe00 [birthday]
  [  505.155878] *pdpt = 0000000009f2c001 *pde = 0000000000000000 
  [  505.156251] Oops: 0002 [#1] SMP 
  [  505.156802] Modules linked in: birthday(POF-) nls_utf8 isofs vmxnet(OF)    snd_ens1371   snd_ac97_codec ac97_bus gameport snd_pcm snd_page_alloc snd_seq_midi  snd_seq_midi_event vmw_balloon snd_rawmidi snd_seq serio_raw snd_seq_device vmwgfx snd_timer joydev snd ttm rfcomm bnep drm bluetooth soundcore vmw_vmci i2c_piix4 shpchp parport_pc ppdev mac_hid lp parport hid_generic psmouse pcnet32 mptspi mptscsih mii mptbase floppy vmw_pvscsi vmxnet3 usbhid hid
  [  505.157903] CPU: 0 PID: 3289 Comm: rmmod Tainted: PF O 3.13.0-32-generic #57-Ubuntu
  [  505.157978] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop        Reference Platform, BIOS 6.00 07/02/2012
  [  505.158266] task: d0a419e0 ti: f68ac000 task.ti: f68ac000
  [  505.158514] EIP: 0060:[&lt;f9dd8236&gt;] EFLAGS: 00010287 CPU: 0
  [  505.158653] EIP is at cleanup_module+0x36/0xe00 [birthday]
  [  505.158812] EAX: cd874820 EBX: f9dda000 ECX: 00200200 EDX: 00100100
  [  505.158864] ESI: 00000800 EDI: 00000000 EBP: f68adf3c ESP: f68adf38
  [  505.158921]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
  [  505.159041] CR0: 8005003b CR2: 00100104 CR3: 0d9f5000 CR4: 000007f0
  [  505.159474] Stack:
  [  505.159598]  f9dd9036 f68adfac c10c21e8 c008adb8 c008ad80 00000014 00000000 f9dda000
  [  505.159906]  00000800 f68adf50 74726962 79616468 00000000 f690d010 c0911380 00000000
  [  505.159921]  d0a419e0 d0a41ddc f68adf88 c117a75d f68adf9c c107239e 00000002 f68adfb4
  [  505.160059] Call Trace:
  [  505.161077]  [&lt;c10c21e8&gt;] SyS_delete_module+0x148/0x1e0
  [  505.161190]  [&lt;c117a75d&gt;] ? ____fput+0xd/0x10
  [  505.161219]  [&lt;c107239e&gt;] ? task_work_run+0x7e/0xb0
  [  505.161239]  [&lt;c165efcd&gt;] sysenter_do_call+0x12/0x28
  [  505.161368] Code: c7 04 24 36 90 dd f9 e8 ab 45 87 c7 a1 90 a1 dd f9 8b 50 0c 8d  48   0c 39 ca 89 15 80 a1 dd f9 75 07 eb 3e 66 90 8b 50 0c 8b 48 10 &lt;89&gt; 4a 04 89 11 c7 40   0c 00 01 10 00 c7 40 10 00 02 20 00 a1 90
  [  505.161890] EIP: [&lt;f9dd8236&gt;] cleanup_module+0x36/0xe00 
  [birthday] SS:ESP 0068:f68adf38
  [  505.162043] CR2: 0000000000100104
  [  505.163080] ---[ end trace 660008f657d67eb5 ]---
  </code></pre>