IS_ERR() macro in Linux

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:

majorNumber = register_chrdev(0, DEVICE_NAME, &fops);

if (majorNumber<0)
{
    printk(KERN_ALERT "Failed to register a major numbern");
    return majorNumber;
}
printk(KERN_INFO "Registered correctly with major number %dn", 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 classn");
  return PTR_ERR(ebbcharClass);          
}


Source: c#

Leave a Reply