title: Error-handling in a kernel module
body: <p>I'm writing a kernel module that communicates with a user application via <code>ioctl</code>. The communication is one-way only - that is, under normal circumstances no output is required. My question is - how should I report errors to the user application?</p>
  
  <p>For example, my module accepts a process ID as an input. Let's say the PID is invalid. I've found no matching error code in <code>errno.h</code>, so I need an alternative way of reporting this. I can think of several ways:</p>
  
  <ol>
  <li>Define a (positive) constant <code>INVALID_PID</code> in a common header file, return <code>-INVALID_PID</code> as the return value of the <code>ioctl</code> call, and handle it in the user application</li>
  <li>Print a meaningful message to the kernel log and return a generic error code</li>
  <li>The <code>ioctl</code> receives an argument from the user application - I can store the error message there</li>
  <li>Establish some two-way communication with the user application</li>
  </ol>
  
  <p>What is the standard way of doing this?</p>
  
  <p>Thanks!</p>