Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > LKM programming - problem with printk();

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 08-07-2004   #1 (permalink)
Just 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:
Code:
for(i=0;i<=len;i++) 
     printk(KERN_ALERT "%c", k_space[i]);
But then i see in /var/log/syslog something like:
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:
Code:
if ((k_space=(char *)kmalloc(len, GFP_KERNEL))==NULL)
                        return -1;
memcpy_fromfs((void *)k_space, (void *)argv[argc], len);
And it didnt solve the problem. Any ideas what to do with this ?
apacz is offline  



Reply With Quote
Old 08-07-2004   #2 (permalink)
Linux Enthusiast
 
scientica's Avatar
 
Join Date: Sep 2003
Location: South- or "Mid-" Sweden
Posts: 742
Send a message via ICQ to scientica
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:
Code:
printk(KERN_ALERT "%s", k_space);
or you could do this:
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
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) ).
__________________
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.
scientica is offline   Reply With Quote
Old 08-07-2004   #3 (permalink)
Just Joined!
 
Join Date: Aug 2004
Posts: 5
Hello,
Quote:
Isn't k_space a 0-terminated string? if so somply do:
I wrote that if i prinkt it as a one string (same as you wrote) there is no extra crap like "<1>".
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?
apacz is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.
subscribe
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 08:13 AM.






© 2000 - - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.1