Results 1 to 6 of 6
I work with scull driver from Book
“Linux Device Drivers, Third Edition“
I wrote in each function in scull module
printk(“<0> Function name Begin”);
printk(“<0> Function name End”);
I have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-07-2005 #1Just Joined!
- Join Date
- Sep 2005
- Posts
- 20
printk ISO C90 forbids mixed declaration and code
I work with scull driver from Book
“Linux Device Drivers, Third Edition“
I wrote in each function in scull module
printk(“<0> Function name Begin”);
printk(“<0> Function name End”);
I have got many warnings:
ISO C90 forbids mixed declaration and code
When I put this code in init and clean up functions only no warnings are generated
I run this module test it works fine
But no messages are generated
printk(“<0> Function name Begin”);
printk(“<0> Function name End”);
Guys How do you think?
What is a problem ?
Any help will be appreciated
- 09-07-2005 #2
I may be showing my inexperience with device drivers, but is there a reason you're using "printk" rather than "printf" for a simple output statement?
Registered Linux user #270181
TechieMoe's Tech Rants
- 09-07-2005 #3Just Joined!
- Join Date
- Sep 2005
- Posts
- 20
When I want to print some info or warning etc to log messages fro kernel module I should use printk not printf.
I used in functions of my module printk
printf for user mode prgrams
for kernel modeles printk should beused
Am I wrong???
- 09-07-2005 #4Probably not, I was just curious since I've never seen that function before.
Originally Posted by Igor007
Registered Linux user #270181
TechieMoe's Tech Rants
- 09-07-2005 #5Just Joined!
- Join Date
- Sep 2005
- Posts
- 20
Sample of code
Sample is
#define FUNCDEBUG
//.....
ssize_t scull_read(struct file* flip, char __user *buf, size_t count, loff_t* f_pos){
#ifdef FUNCDEBUG
printk("<0> scull_read begin\n");
#endif//FUNCDEBUG
struct scull_dev* dev=flip->private_data;
struct scull_qset* dptr;
int quantum=dev->quantum,qset=dev->qset;
int itemsize=quantum*qset;
int item,s_pos,q_pos,rest;
ssize_t retval=0;
if (down_interruptible(&dev->sem))
return -ERESTARTSYS;
if (*f_pos > dev->size)
goto out;
if(*f_pos+count>dev->size)
count=dev->size-*f_pos;
item=(long)*f_pos / itemsize;
rest=(long)*f_pos % itemsize;
s_pos=rest / quantum;q_pos=rest % quantum;
dptr = scull_follow(dev,item);
if(dptr==NULL || !dptr->data || !dptr->data[s_pos])
goto out;
if(count > quantum-q_pos)
count=quantum-q_pos;
if(copy_to_user(buf,dptr->data[s_pos]+q_pos,count)){
retval=-EFAULT;
goto out;
}
*f_pos+=count;
retval=count;
out:
up(&dev->sem);
#ifdef FUNCDEBUG
printk("<0> scull_read end\n");
#endif//FUNCDEBUG
return retval;
}
ssize_t scull_write(struct file *filp,const char __user *buf,size_t count,loff_t *f_pos){
#ifdef FUNCDEBUG
printk("<0> scull_write begin\n");
#endif//FUNCDEBUG
struct scull_dev *dev =filp->private_data;
struct scull_qset *dptr;
int quantum=dev->quantum, qset=dev->qset;
int itemsize=quantum * qset;
int item, s_pos, q_pos, rest;
ssize_t retval= -ENOMEM;
if(down_interruptible(&dev->sem))
return -ERESTARTSYS;
item=(long)*f_pos/itemsize;
rest=(long)*f_pos%itemsize;
s_pos=rest/quantum;q_pos=rest%quantum;
dptr=scull_follow(dev,item);
if(dptr==NULL)
goto out;
if(dptr->data==NULL){
dptr->data=kmalloc(qset*sizeof(char *),GFP_KERNEL);
if(dptr->data==NULL)
goto out;
memset(dptr->data,0,qset*sizeof(char *));
}
if(!dptr->data[s_pos]){
dptr->data[s_pos]=kmalloc(quantum,GFP_KERNEL);
if(!dptr->data[s_pos])
goto out;
}
if (count> quantum-q_pos)
count=quantum-q_pos;
if(copy_from_user(dptr->data[s_pos]+q_pos,buf,count)){
retval=-EFAULT;
goto out;
}
*f_pos=+count;
retval=count;
if(dev->size < *f_pos)
dev->size=*f_pos;
out:
up(&dev->sem);
#ifdef FUNCDEBUG
printk("<0> scull_write begin\n");
#endif//FUNCDEBUG
return retval;
}
__________________
Linux is ...
- 09-08-2005 #6Linux User
- Join Date
- Oct 2004
- Location
- /dev/random
- Posts
- 404
Have you included the required header for the declaration of printk()?I wrote in each function in scull module
printk(“<0> Function name Begin”);
printk(“<0> Function name End”);
I have got many warnings:
ISO C90 forbids mixed declaration and code
http://lxr.linux.no/source/include/linux/kernel.h#L105
Also, for this to work, the macro __KERNEL__ has to be defined.
It depends on the default console loglevel.When I put this code in init and clean up functions only no warnings are generated
I run this module test it works fine
But no messages are generated
printk(“<0> Function name Begin”);
printk(“<0> Function name End”);
If it's not displayed on the console, it would appear in syslog.
Do a dmesg or cat /var/log/messages, it should appear there.The Unforgiven
Registered Linux User #358564


Reply With Quote
