title: How to check for existing argument on ioctl
body: <p>I want to try out how to use i/o-controls of a loadable kernel module, here a character device.
  The question is: How to check if the <code>ioctl</code> call on userspace side has an argument or not. I found that on <code>ioctl</code> an argument is optional.</p>
  
  <p>Inside the userspace function:</p>
  
  <pre><code>// set a parameter - this is a proper call
  if( ioctl(fd, IOCTL_SET_PARAM1, 5)&lt;0 )
  {
    fprintf(stderr,"Error while ioctl: %s\n", strerror(errno));
  }
  
  // call a setter without argument - this should cause an error
  if( ioctl(fd, IOCTL_SET_PARAM1)&lt;0 )
  {
    fprintf(stderr,"Error while ioctl: %s\n", strerror(errno));
  }
  </code></pre>
  
  <p>The corresponding kernel module handler:</p>
  
  <pre><code>long
  fops_unlocked_ioctl (struct file    *p_file,
                       unsigned int    cmd,
                       unsigned long   arg)
  {
    switch(cmd)
    {
    case IOCTL_SET_PARAM1:
      printk(KERN_INFO "IOCTL called with IOCTL_SET_PARAM1\n");
      if( /* how to check for the argument here? */ )
      {
        printk(KERN_WARNING "Missing argument\n");
        return -EINVAL;
      }
      param1 = (unsigned short) arg;
      printk(KERN_INFO "param1 set to %d\n",param1);
      break;
    default:
      printk(KERN_WARNING "IOCTL called with wrong request code.\n");
      return -EINVAL;
    }
    return 0;
  }
  </code></pre>
  
  <p>Regards,
  Alex</p>