Results 1 to 3 of 3
Hello,
I've got a problem with printk() function. Im trying to print some buffor char by char like:
Code:
for(i=0;i<=len;i++)
printk(KERN_ALERT "%c", k_space[i]);
But then i see in /var/log/syslog something ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-07-2004 #1Just Joined!
- Join Date
- Aug 2004
- Posts
- 5
LKM programming - problem with printk();
Hello,
I've got a problem with printk() function. Im trying to print some buffor char by char like:
But then i see in /var/log/syslog something like:Code:for(i=0;i<=len;i++) printk(KERN_ALERT "%c", k_space[i]);
Aug 7 11:52:01 dstool kernel: i<1>n<1>s<1>m<1>o<1>d<1><1><1>
Aug 7 11:52:01 dstool kernel: e<1>.<1>o<1><1><1>
With some extra "<1>". Why it appears? When i print k_space as one string i don't have this "<1>". At first i though it was some problem with user space <-> kernel space but it transformed orginall buffor to k_space like:
And it didnt solve the problem. Any ideas what to do with this ?Code:if ((k_space=(char *)kmalloc(len, GFP_KERNEL))==NULL) return -1; memcpy_fromfs((void *)k_space, (void *)argv[argc], len);
- 08-07-2004 #2
I think printk maybe atdds some message count. And as you're printing the message char by char I think that's why you get it after each char.
Isn't k_space a 0-terminated string? if so somply do:
or you could do this:Code:printk(KERN_ALERT "%s", k_space);
either way try to unroll the loop - it's faster. (loops contains jumps, and jumps are 'realativle slow' - speaking about lowlevel stuff as branch prediction, the cosst of a jump (predicted or misspredited, etc) ).Code:char tem_char; temp_char=k_space[len]; // maybe you could do botthia and above on one line. k_space[len]='\0'; // terminate the string printk(KERN_ALERT "%s", k_space); k_space[len]=temp_char; // restore the char we replaced with a 0-terminator
Regards Scienitca (registered user #335819 - http://counter.li.org )
--
A master is nothing more than a student who knows something of which he can teach to other students.
- 08-07-2004 #3Just Joined!
- Join Date
- Aug 2004
- Posts
- 5
Hello,
I wrote that if i prinkt it as a one string (same as you wrote) there is no extra crap like "<1>".Isn't k_space a 0-terminated string? if so somply do:
It is important for to have access to simple char. I think "<1>" is connected in some way with this char becouse it doesnt appears only with printk. It doesnt allow me to compare it with other simple chars.
Any idea?


Reply With Quote
