title: BUG: Unable to handle kernel paging request at error for the sample kernel module
body: <p>I am writing a sample kernel module which reads data sent through ioctl call from application and prints them.</p>
  
  <p>I am passing structure "ioctl_struct" through ioctl from the application and in the kernel module, I will be printing its member variables.</p>
  
  <p>this works absolutely fine in a few machines. In a few machines </p>
  
  <blockquote>
    <blockquote>
      <p>"BUG: unable to handle kernel paging request at"</p>
    </blockquote>
  </blockquote>
  
  <p>the error is thrown while accessing "name and testStruct's id1 and id2".</p>
  
  <p>I don't think this module is hardware/kernel dependent.
  I am not sure where it's going wrong. any help would be appreciated.
  thanks.</p>
  
  <p>Driver.c kernel module</p>
  
  <pre><code>static const char DEVICE_NAME[]="testipc";
  static struct proc_dir_entry * proc_ipc = NULL;
  
  struct test
  {
          int id1;
          int id2;
  };
  
  struct ioctl_struct
  {
      __user struct test *testStruct;
      __user int * id;
      __user char * name;
          int cmd;
  };
  
  
  static int __init etx_driver_init(void);
  static void __exit etx_driver_exit(void);
  static long etx_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  
  static struct file_operations fops =
  {
          .owner          = THIS_MODULE,
          .read           = etx_read,
          .write          = etx_write,
          .open           = etx_open,
          .unlocked_ioctl = etx_ioctl,
          .release        = etx_release,
          .unlocked_ioctl = etx_ioctl,
  };
  
  
  static long etx_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  {
      printk("reached ioctl....\n");
      struct ioctl_struct   buf;
  
           if (copy_from_user(&amp;buf, (void *)arg, sizeof(buf)))
          return -EFAULT;
  
      printk("succes..2\n");
      printk("id %d\n",buf.id);
      printk("cmd %d\n",buf.cmd);
      printk("filename %s\n",buf.name);
      printk("token %d\n",buf.testStruct-&gt;id1);
      printk("token %d\n",buf.testStruct-&gt;id2);
          return 0;
  }
  
  
  static int __init etx_driver_init(void)
  {
      printk("new test driver loaded..");
          proc_ipc = proc_create(DEVICE_NAME, 0, NULL, &amp;fops);
          if (!proc_ipc)
          {
                  printk(KERN_ALERT "Unable to create /proc/%s\n", DEVICE_NAME);
                  return 1;
          }
  
          return 0;
  
  }
  
  void __exit etx_driver_exit(void)
  {
            if (proc_ipc)
                  proc_remove(proc_ipc);
  
          proc_ipc = NULL;
  
  }
  
  module_init(etx_driver_init);
  module_exit(etx_driver_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("lin");
  MODULE_DESCRIPTION("A simple driver");
  MODULE_VERSION("1.0");
  </code></pre>
  
  <p>and following is my application file</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include&lt;sys/ioctl.h&gt;
  # define __user 
  
  static int fd=NULL;
  
  #define TEST_IOCTL _IOWR('z', 80, struct ioctl_struct)
  
  struct test
  {
      int id1;
      int id2;
  };
  
  struct ioctl_struct
  {
      __user struct test *testStruct;
      __user int * id;
      __user char * name;
      int cmd;
  };
  
  void init()
  {
          printf("\nOpening Driver\n");
          fd = open("/proc/testipc", O_RDWR);
          if(fd &lt; 0) {
                  printf("Cannot open device file...\n");
                  return 0;
          }
  }
  
  void send()
  {
      int id=5;
      int *pid=id;    
      char name[10]={'H','e','l','l','o'};
      struct test testStruct;
      testStruct.id1=44;
      testStruct.id2=33;
  
      struct ioctl_struct request;
      request.name = name ;
      request.id = pid;
      request.cmd = 33;
      request.testStruct = &amp;testStruct;
      ioctl(fd, TEST_IOCTL, &amp;request);
  }
  
  void finish()
  {
          printf("Closing Driver\n");
          close(fd);
  }
  
  int main()
  {
      init();
      send();
      finish();
      return 0;
  }
  </code></pre>
  
  <p>In dmesg, 
  id 5,
  cmd 33,
  Hello,
  44,
  33,
  should be printed</p>