LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2009, 02:39 AM   #1
dpattnaik
LQ Newbie
 
Registered: Jan 2009
Posts: 1

Rep: Reputation: 0
Angry 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...
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Write a function that takes an input argument a file and returns the date to stdout 1subject Programming 1 06-17-2009 11:17 AM
Copy_to_user returns a zeroed out string in a scull like driver unitedroad Programming 1 12-25-2008 05:59 AM
c++ function that returns the user ID Hard_Working_ Programming 5 04-06-2007 06:26 PM
C function that returns $HOME cbranje Programming 1 02-12-2005 05:41 PM
open function returns error sudheernair Programming 2 05-07-2004 11:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration