1

So I am learning to write device drivers and wrote this simple one:

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>

static int __init gotemp_init(void)
{
        printk(KERN_DEBUG "Hello world");
        return 0;
}

static void __exit gotemp_exit(void)
{
}

module_init(gotemp_init);
module_exit(gotemp_exit);

MODULE_AUTHOR("Abhinav Jain");
MODULE_DESCRIPTION("Simple driver");
MODULE_LICENSE("GPL");

And the makefile is this:

obj-m := hello.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD       := $(shell pwd)

all:
        $(MAKE) -C $(KERNELDIR) M=$(PWD)

But the output of dmesg does not print the "Hello world". I also tried KERN_INFO but still the same results although the lsmod shows the module hello being loaded.

So why is the message not being logged?

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
Crazy Psychild
  • 552
  • 5
  • 16

1 Answers1

5

It should work just fine. Sometimes, messages might arrive late due to buffering. Adding a newline character at the end of the string is then required to flush the buffer. Try doing:

printk(KERN_DEBUG "Hello world\n");
Andrzej Pronobis
  • 33,828
  • 17
  • 76
  • 92