我正在制作一个模块,在其中我从用户那里获取一些条目并将它们分解成更小的字符串并将它们存储到一个数组中。逻辑工作正常,但几分钟后内核恐慌。下面我给出了将条目从用户空间放入 /proc 文件的代码,然后是模块中的编码。
FILE *fp;
fp =fopen("/proc/tx_info","w");
fprintf(fp,"protocol address tos payload interface");
fprintf(fp,"\n %3s %6s %7d %5d %6s\n",prot,addr,tos,pld,inter);
fclose(fp);
现在是模块中的代码
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++;
}
}