i am using write() function to send string to my driver . it returns EFAULT.
hi ,
i am using write() function to send strings from a 2d array to driver using a repeated loop. it succeeds in its operation .but out of 100 tests at least 1 time it is unable to send the strings to driver & at that time perror in user application returns "Bad address" error. here is the application code chunk: -------------------------------------------------------------------- int sel_menuitem(char (*item)[20],unsigned char max_items,unsigned char onscrn_max_item,unsigned char crsr_xloc ,unsigned char item_xloc,unsigned char item_yloc,unsigned char item_size,unsigned char hold,unsigned char prev_stat) { int i; int status; unsigned char sel_complete=0; int ret = -1; char retry = 0; unsigned long temp = 0; for(i=0;i<max_items;i++) { temp = strlen(item+i)|(item_xloc<<8)|((item_yloc+i)<<16); status = write(lcd_fd, (item+i), temp); printf("item1 %s<%d>\n",(item+i),strlen((item+i))); if(status < 0) perror("Write "); } ---------------------------------------------------------------------- function receives 2d array of cracters . temp is the variable which contains string length ,x location of string to display,y location of string to display. here is the driver write method: ---------------------------------------------------------------------- static int lcd_write(struct file* fd_LCD, const char __user* UserBuff,size_t count,loff_t* off) { char *Driver_Buff; unsigned char Xpos; unsigned char Ypos; int ret; printk(KERN_ERR ".1d<%d>\n",strlen(UserBuff)); if(strlen(UserBuff) != 0) { string_len=(int)(count&0xFF); Xpos=(char)(count>>8)&0xFF; Ypos=(char)(count>>16)&0xFF; if(string_len>20) string_len = 20; /* whether offset is beyond one line */ if((Xpos+string_len)>21) string_len = 21-Xpos; printk(KERN_ERR ".2d<%d>\n",string_len); Driver_Buff = (char*)kmalloc(string_len,GFP_KERNEL); memset(Driver_Buff, 0, sizeof(Driver_Buff)); /* if highlight is not enabled for the data */ if(Line_Highlight!=1) { ret = copy_from_user(Driver_Buff,UserBuff,string_len); printk(KERN_ERR "while read1<%d><%s>\n",ret,Driver_Buff); if(ret) { kfree(Driver_Buff); printk(KERN_ERR "0>!-EFAULT!\n"); return -EFAULT; } // printk(KERN_ERR "driver:received item,count %s <%d>\n",Driver_Buff,string_len); LCD_WRITE_STRING(Driver_Buff,Xpos,Ypos); } ---------------------------------------------------------------------- count contains string length,x location,y location . i am extracting the information & try to write to my lcd any helps are appreciated... |
All times are GMT -5. The time now is 09:47 AM. |