title: IS_ERR() macro in Linux
body: <p>While getting to know how to write device drivers I came across IS_ERR() macro. But I couldn't find how is it working. I have include the code below:</p>
  
  <pre><code>majorNumber = register_chrdev(0, DEVICE_NAME, &amp;fops);
  
  if (majorNumber&lt;0)
  {
      printk(KERN_ALERT "Failed to register a major number\n");
      return majorNumber;
  }
  printk(KERN_INFO "Registered correctly with major number %d\n", majorNumber);
  
  // Register the device class
  ebbcharClass = class_create(THIS_MODULE, CLASS_NAME);
  
  if (IS_ERR(ebbcharClass))
  {               
    unregister_chrdev(majorNumber, DEVICE_NAME);
    printk(KERN_ALERT "Failed to register device class\n");
    return PTR_ERR(ebbcharClass);          
  }
  </code></pre>
  
  <p>So what does the IS_ERR() macro expand to and how it gets executed.</p>