From my previous question: How to build external modules in ubuntu? I thought I cannot load module due to loading out-of-tree
or tainting kernel
, but to my scull_init_module
(source below) I have added printk
so I know I get loaded from kern log. But I did not (no output in the log -- the log is the same as from the link).
uname -a
== 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2 (2020-04-29) x86_64 GNU/Linux
(no use of ubuntu - as from the link).
scull_init_module
:
#ifndef scull_major
#define scull_major 0
#endif
#ifndef scull_nr_devs
#define scull_nr_devs 4
#endif
struct scull_dev *scull_devices; /*array of active devices */
static void scull_setup_cdev(struct scull_dev *, int); /*helper function (internal) */
int scull_minor = 0;
int scull_init_module(void) {
int i;
dev_t dev = 0;
/* register devices */
int result = 1;
result = alloc_chrdev_region(&dev, scull_minor, scull_nr_devs, "scull"); /**comment later**/
printk(KERN_ALERT"Passed %s %d \n in scull_init_module\n", __FUNCTION__, __LINE__);
if(result < 0){
printk(KERN_WARNING "scull: can't get major %d\n", scull_major);
return result;
}
/* allocate space for devices */
scull_devices = kmalloc(sizeof(struct scull_dev) * scull_nr_devs, GFP_KERNEL);
if(!scull_devices){
result = -1;
goto fail;
}
/*initilization of devices */
for(i=0; i<scull_nr_devs;i++){
scull_devices[i].quantum = scull_quantum;
scull_devices[i].qset = scull_qset;
scull_setup_cdev(&scull_devices[i], i);
}
return 0;
fail:
scull_cleanup_module();
return result;
}
module_init(scull_init_module);
It is basically from Linux Device Drivers, Third Edition, chapter3. But I hand-write it (no copy/paste). alloc_chrdev_region
is called properly, so is scull_setup_cdev
, then where could be problem?
EDIT (output from dmesg):
From dmesg
it looks like it does load the module:
[ 2765.707018] scull: loading out-of-tree module taints kernel.
[ 2765.707106] scull: module verification failed: signature and/or required key missing - tainting kernel
[ 2765.707929] Passed scull_init_module 41
in scull_init_module
But then still the node in /dev/scull0
gives No such device or address
#mknod /dev/scull0 c 241 0
#cat /dev/scull0
cat: /dev/scull0: No such device or address
So if the device is properly registered (see dmesg) and I create node in /dev hierarchy, then what does mean no device or address
? And why I am getting it?
EDIT2 (function scull_setup_cdev):
static void scull_setup_cdev(struct scull_dev *dev, int index){
int err, devno=MKDEV(scull_major, scull_minor + index);
cdev_init(&dev->cdev, &scull_fops);
dev->cdev.owner = THIS_MODULE;
dev->cdev.ops = &scull_fops; /**comment later**/
err = cdev_add(&dev->cdev, devno, 1);
if (err)
printk(KERN_NOTICE "Error %d adding scull%d", err, index);
}