Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error compiling kernel module for simple device driver

I've got such a function:

void cleanup_module(void)
{
    /* 
     * Unregister the device 
     */
    if(unregister_chrdev(Major, DEVICE_NAME)<0) 
        printk(KERN_ALERT "Error in unregister_chrdev:\n");
}

and error:

/home/student/kernel/hello.c: In function ‘cleanup_module’:
/home/student/kernel/hello.c:39:2: error: void value not ignored as it ought to be

This line is the one with if statement. Do you know what I'm doing wrong?

like image 460
Wojciech Reszelewski Avatar asked Jul 04 '26 04:07

Wojciech Reszelewski


2 Answers

This means that unregister_chrdev doesn't have a return value (it's void), but you have put it in an if. That is, you are using a void value which should have been ignored. Hence the error message.

Check out this question which asks why the return value was changed to void.

like image 59
Shahbaz Avatar answered Jul 06 '26 17:07

Shahbaz


Based on this unregister_chrdev() used to return an int but its return type was changed to void as the returned value was meaningless. Remove the if entirely from the posted code:

unregister_chrdev(Major, DEVICE_NAME);
like image 26
hmjd Avatar answered Jul 06 '26 18:07

hmjd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!