Welcome! Log In Create A New Profile

Advanced

questions from an ultra-newbie

Posted by mzimmers 
questions from an ultra-newbie
June 22, 2017 04:19PM
Hi -

I'm trying to make the example on this page work. I've gotten the LKM to build and load successfully, but when I try to talk to it via the test program, I get a spewage of output:

mzimmers@beaglebone:~/exploringBB/extras/kernel/ebbchar$ sudo ./test
[sudo] password for mzimmers:
Starting device test code example...
Type in a short string to send to the kernel module:
xxx
Writing message to the device [xxx].
mzimmers@beaglebone:~/exploringBB/extras/kernel/ebbchar$
Message from syslogd@beaglebone at Jun 22 14:13:01 ...
kernel:[268951.426166] Internal error: : 1b [#22] SMP ARM

Message from syslogd@beaglebone at Jun 22 14:13:01 ...
kernel:[268951.546090] Process test (pid: 8565, stack limit = 0xdc488218)

Message from syslogd@beaglebone at Jun 22 14:13:01 ...
kernel:[268951.552054] Stack: (0xdc489f10 to 0xdc48a000)


and on and on.

I modified this routine as follows:

static ssize_t dev_write(struct file *filep, const char *buffer, size_t len, loff_t *offset){
printk(KERN_INFO "EBBChar: entering dev_write().\n"winking smiley;
printk(KERN_INFO "EBBChar: buffer address is %p.\n", (void *) buffer);
printk(KERN_INFO "EBBChar: buffer[0] is %c\n.", buffer[0]);
printk(KERN_INFO "EBBChar: buffer size is %d\n.", sizeof(buffer));
printk(KERN_INFO "EBBChar: len is %d\n.", len);
printk(KERN_INFO "EBBChar: offset is %d\n.", (int) *offset);
sprintf(message, "%s(%zu letters)", buffer, len); // appending received string with its length
printk(KERN_INFO "EBBChar: sprintf() completed.\n"winking smiley;
size_of_message = strlen(message); // store the length of the stored message
printk(KERN_INFO "EBBChar: Received %zu characters from the user\n", len);
return len;
}

I never see the output of the third printk. I have no way of knowing whether the address I'm getting is valid, but the program's behavior makes me suspect that it isn't.

Also, in the test program (the one that runs in user space), I get a segmentation fault on the write to the driver. Somehow I feel these are related.

So, my questions:

    [*] based on my printks, does it seem that a bad buffer address is the culprit?
    [*] why is this manifesting in both kernel and user space?
    [*] is there a better way to debug kernel kode than using all these printk() statements?

Thank you for any help. This is challenging, but it's also exciting and fun, so I look forward to learning more.
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 9 plus 24?
Message: