Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    LKM programming - problem with printk();

    I've got a problem with printk() function. Im trying to print some buffor char by char like:
         printk&#40;KERN_ALERT "%c", k_space&#91;i&#93;&#41;;
    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:
    if &#40;&#40;k_space=&#40;char *&#41;kmalloc&#40;len, GFP_KERNEL&#41;&#41;==NULL&#41;
                            return -1;
    memcpy_fromfs&#40;&#40;void *&#41;k_space, &#40;void *&#41;argv&#91;argc&#93;, len&#41;;
    And it didnt solve the problem. Any ideas what to do with this ?

  2. #2
    Linux Enthusiast scientica's Avatar
    Join Date
    Sep 2003
    South- or "Mid-" Sweden
    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:
    printk&#40;KERN_ALERT "%s", k_space&#41;;
    or you could do this:
    char tem_char;
    temp_char=k_space&#91;len&#93;;  // maybe you could do botthia and above on one line.
    k_space&#91;len&#93;='\0'; // terminate the string
    printk&#40;KERN_ALERT "%s", k_space&#41;;
    k_space&#91;len&#93;=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 - )
    A master is nothing more than a student who knows something of which he can teach to other students.

  3. #3
    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?

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts