Ex 5.1


when do we get to this IF????

int drv_init_module(void)
  if (major_num) 


    printk(KERN_WARNING "init_module(): major = %d\n", major_num);

    dev = MKDEV(major_num, minor_num);  

    result = register_chrdev_region(dev, 1, "old char device");


As far as I understand

Asked on September 28, 2019 in Linux Kernel.
Add Comment
2 Answer(s)
Best answer

you are right because “module_param” macro is missing. in order to get the ability to get inside the if code block you have adding to your driver “module_param” macro (with the right values).

as there is arguments to main in c there is something similar to it with the module.

as long as you use the “module_param” macro inside your driver with the right values, at the time you upload the module with insmod you can (not forced) to initialize the global variable “major_num” with a value which is different from zero and then you will able to get inside the if code block you are talking about.

Answered on September 28, 2019.
Add Comment

Adi is quite right,

But please Notice the “char.h”  header file, MAJOR is configured there currently to 0,

but this could change .

Answered on September 29, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.