LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 04-06-2012, 04:31 AM   #1
karan2386
Member
 
Registered: Jan 2012
Posts: 34

Rep: Reputation: Disabled
breaking a buffer into smaller arrays


I am witting a module in which i need a data in a buffer to be divided into smaller arrays. but whenever i run code it gives me an error:
here is the code:

void tx_break(void)
{
char ch;
char tmp[25];
int i =0;
int k=0,j=0;
ch = tx_buffer[0];
while(ch != '\n')
{
//printk(KERN_ALERT"%c",tx_buffer[i]);
ch = tx_buffer[i];
i++;
}
i++;
while(ch != '\0')
{
j=0;
while(ch == ' ')
{
ch = tx_buffer[i];
i++;
}
while(ch != ' ')
{
tmp[j] = ch;
j++;
i++;
ch = tx_buffer[i];
}
tmp[j] = '\0';

memcpy(&info.arr[k][0],tmp,j);
k++;
}
printk(KERN_ALERT"\n proto::%s,add::%s",&info.arr[0][0],&info.arr[1][0]);
// tasklet_schedule(&tx_tasklet);
}

the kernel is panicking and giving me the following bug while doing dmsg::

BUG: unable to handle kernel paging request at f9904000
 
Old 04-08-2012, 07:52 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,716

Rep: Reputation: 634Reputation: 634Reputation: 634Reputation: 634Reputation: 634Reputation: 634
It reads a lot better if you use code tags .. I'm not much of a coder but it seems that the while loop in red will keep reading through and past the end of the tx_break[] buffer until it encounters a '0x20' or generates a seg fault. I think you're expecting your outer while loop (green) to control the inner while loop, but it won't - 'ch' won't get tested against '\0' again until the inner while loops finish. Maybe you could replace the contents of the green while loop with a case statement to test each 'ch' against.

Code:
void tx_break(void)
{
  char ch;
  char tmp[25];
  int i =0;
  int k=0,j=0;
  ch = tx_buffer[0];
  while(ch != '\n')
  {
    //printk(KERN_ALERT"%c",tx_buffer[i]);
    ch = tx_buffer[i];
    i++;
  }
  i++;
  while(ch != '\0')
  {
    j=0;
    while(ch == ' ')
    {
      ch = tx_buffer[i];
      i++;
    }
    while(ch != ' ')
    {
      tmp[j] = ch;
      j++;
      i++;
      ch = tx_buffer[i];
    }
    tmp[j] = '\0';

    memcpy(&info.arr[k][0],tmp,j);
    k++;
  }
  printk(KERN_ALERT"\n proto::%s,add::%s",&info.arr[0][0],&info.arr[1][0]);
  // tasklet_schedule(&tx_tasklet);
}
 
Old 04-09-2012, 03:30 AM   #3
karan2386
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
I had solved that problem now its working fine but after few minutes kernel panicks... Following is the code what I am doing.....

code:
void tx_break(void)
{
char ch;
char tmp[25];
int i =0;
int k=0,j=0,y = 0;

ch = tx_buffer[0];
//runing the while loop while the ch goes to next line from where the real user entries starts
while(ch != '\n')
{
ch = tx_buffer[i];
i++;
}


while(ch != '\0')
{
j=0;
//while loop for blanks in between the user entries
while(ch == ' ' && ch != '\0')
{
i++;
ch = tx_buffer[i];
}
//while loop to put the user defined entries to a temporary tmp which would become an entry of 2d array(info.arr[][])
while(ch != ' ' && ch !='\0')
{
tmp[j] = ch;
j++;
i++;
ch = tx_buffer[i];
}
tmp[j] = '\0';
printk(KERN_ALERT"\n%s\n",tmp);
//putting user entries to an 2d array
for(k=0;tmp[k] != '\0';k++)
info.arr[y][k] = tmp[k];
info.arr[y][k] = '\0';
printk("the 2d::%s",&info.arr[y][0]);
y++;
// memcpy(&info.arr[k][0],tmp,j+1);
// k++;
}
}

Last edited by karan2386; 04-09-2012 at 03:32 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays of Structures to Arrays of Classes knobby67 Programming 1 01-01-2008 01:39 PM
C: convert char buffer received from socket to host endianess buffer kpachopoulos Programming 3 06-07-2007 05:06 PM
What is the difference between the free buffer and buffer in the buffer hash queue? Swagata Linux - Enterprise 0 05-25-2006 11:57 PM
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 05:40 AM
Free disk space in '/' getting smaller and smaller. simjii Suse/Novell 5 12-16-2005 11:24 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration