LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-21-2016, 03:21 PM   #1
lbontron
LQ Newbie
 
Registered: Nov 2016
Posts: 8

Rep: Reputation: Disabled
Misunderstandings with the function printk


Hello everybody,
I continue my driver development and I have a small problem (not important)

My program :
Quote:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/fs.h>
#include <asm/uaccess.h> // for put_user //

#define DEVICE_NAME "GPIO_RaspberryPi2"
#define LICENSE "GPL"
#define AUTHOR "Ludovic BONTRON"
#define GPIO_BASE ((unsigned long)0x3f200000)
#define GPIO_SIZE ((unsigned long)0x00004096)

MODULE_LICENSE(LICENSE);
MODULE_AUTHOR(AUTHOR);

static ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t * offset);
static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t * off);
static int device_open(struct inode *inode, struct file *file);
static int device_release(struct inode *inode, struct file *file);

static int Major = 0;
struct resource *s_res = NULL;

static struct file_operations fops =
{

.owner = THIS_MODULE,
.open = device_open,
.release = device_release,
.read = device_read,
.write = device_write
};

int init_module(void)
{

int iRet = 0;
Major = register_chrdev(0, DEVICE_NAME, &fops);

if (0 > Major)
{

printk(KERN_ALERT "Registering char device failed with %d\n", Major);
iRet = Major;
}
else
{

printk(KERN_INFO "My major number is %d\n", Major);
s_res = request_mem_region(GPIO_BASE, GPIO_SIZE, DEVICE_NAME);
printk(KERN_INFO "test");
if (NULL == s_res)
{

printk(KERN_INFO "Module can access at the memory between %lu and %lu", GPIO_BASE, GPIO_BASE + GPIO_SIZE);
}
else
{

printk(KERN_INFO "Access confirmed");
}
}
return iRet;
}

void cleanup_module(void)
{

if (NULL != s_res)
{

release_mem_region(GPIO_BASE, GPIO_SIZE);
}
printk(KERN_INFO "Module deleted");
unregister_chrdev(Major, DEVICE_NAME);
}

static int device_open(struct inode *inode, struct file *file)
{

printk(KERN_INFO "device_open() \n");
return -EINVAL;
}

static int device_release(struct inode *inode, struct file *file)
{

printk(KERN_INFO "device_release() \n");
return -EINVAL;
}

static ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t * offset)
{

printk(KERN_INFO "device_read() \n");
return -EINVAL;
}

static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{

printk(KERN_INFO "device_write() \n");
return -EINVAL;
}
My Makefile :
Quote:
ifndef KERNELDIR

KERNELDIR := /lib/modules/$(shell uname -r)/build
endif

obj-m += myfirstdriver.o

all:
# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
After compilation I insert my module with :
$ insmod mydriver.ko
And I execute the command dmesg for analyse the behavior
$ dmesg -c
The result is :
[1130280.724078] My major number is 243
[1130280.737180] test
[1130280.739104] Module can access at the memory between 1059061760 and 1059078294

It's normal...
But when I remove my module I have an problem
$ rmmod mydriver
$ dmesg -c
The buffer is empty.
When I insert my module, so I have the information that the module was deleted
$ insmod mydriver.ko
$ dmesg -c
Resultat :
[1130559.978404] Module deleted
[1130571.107927] My major number is 243
[1130571.121103] test
[1130571.123037] Module can access at the memory between 1059061760 and 1059078294

My question is why I don't have this message before ???
 
Old 11-22-2016, 02:28 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Add a newline to "Module deleted"
 
1 members found this post helpful.
Old 11-22-2016, 03:27 PM   #3
lbontron
LQ Newbie
 
Registered: Nov 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
Add a newline to "Module deleted"
Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ZFS: Myths and Misunderstandings (by Jesse Smith) cwizardone Slackware 36 05-18-2016 04:00 PM
DMESG does not display the kernel driver function PRINTK message David Li Linux - Newbie 1 04-07-2010 09:21 PM
LXer: Eight common misunderstandings about GPLv3 LXer Syndicated Linux News 0 05-11-2007 07:16 AM
printk(KERN_DEBUG ...) vs printk(...) Sergei Lavrov Linux - Kernel 2 03-25-2007 04:41 PM
LXer: 10 common misunderstandings about the GPL LXer Syndicated Linux News 0 08-29-2006 12:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 06:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration