2009-04-27 06:03:20 Read call from userspace fails in the chararcter driver
ThangarJ P (INDIA)
Message: 73274
Hi All,
I am working with uClinux 2008R1.5-RC3 distribution and BF533 Ezkit board.
i have wriiten a character driver for some purpose.
but i am facing an issue with read() call from usrespace at some times.
the read( ) call from userspace returns -1 sometimes. At the same time write and ioctl calls are working fine.
The read call from the usersapce wont call the kernal API which is mapped into the read in the fops table.It just returning -1 without call the kernal API.
The parameters in the read API are perfect and opening the driver also sucess with some id. the same id is passed to write and ioctl calls.they are working fine.
once the read API returns -1 then further read also gives always -1.It will work only after reboot the kernal.
With Regards
Thangaraj
QuoteReplyEditDelete
2009-04-27 07:28:43 Re: Read call from userspace fails in the chararcter driver
Robin Getz (UNITED STATES)
Message: 73281
Thangarj:
It could be any number of things. Did you check out:
https://docs.blackfin.uclinux.org/doku.php?id=driver_development
https://docs.blackfin.uclinux.org/doku.php?id=basic_read_write_functions
to test things out?
-Robin
QuoteReplyEditDelete
2009-04-28 02:24:38 Re: Read call from userspace fails in the chararcter driver
ThangarJ P (INDIA)
Message: 73337
Hi Robin,
ya..i have checked .
it is not happening consistently.some times its working proberly.
sometimes only i am facing this issue.
At that time it wont call the kernal API which is mapped to read api in the fops table.
if any other error means it should return from the API.
But here it never calls the kernal API.but it returning -1.
please provide your suggestions.
QuoteReplyEditDelete
2009-04-28 02:36:11 Re: Read call from userspace fails in the chararcter driver
Mike Frysinger (UNITED STATES)
Message: 73340
are you sure your userspace code is correct and is actually operating on an open file descriptor ? you really should review the standard methods for checking errors (like errno) instead of hunting down possibly bogus bugs.
you can also run things through strace
QuoteReplyEditDelete
2009-04-28 09:08:16 Re: Read call from userspace fails in the chararcter driver
ThangarJ P (INDIA)
Message: 73364
Dear Mike,
ya..I am sure the userspace code is correct and is operarting on open file descriptor.
because the same code is working most of the time.
some times only i am facing this issue.
ok. i will check through strace.
Thanks for your suggestions.
With Regards,
Thangaraj
QuoteReplyEditDelete
2009-04-29 01:46:08 Re: Read call from userspace fails in the chararcter driver
ThangarJ P (INDIA)
Message: 73401
Dear Mike,
Please find out my observations while run through strace.
SUCCESS CASE:
ret = read(s32_dvd_fd,pc_MsgBuf,ps16_NBytes) --> This is the call from userspace
s32_dvd_fd = 5; pc_MsgBuf = 0x74db4d; ps16_NBytes = 0x74db7c;
the sysem call for this read from strace command --> read(5, "\376r\6\2\0x\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 7658364) = 100.
FAILURE CASE:
ret = read(s32_dvd_fd,pc_MsgBuf,ps16_NBytes) --> This is the call from userspace
s32_dvd_fd = 5; pc_MsgBuf = 0x1eabb4d; ps16_NBytes=0x1eabb7c;
the sysem call for this read from strace command --> read(5, 0x1eabb4d, 32160636) = -1 EFAULT (Bad address).
In the Failure case also we are passing the valid address and correct device id.
please clarify why this is fail in this case?
With Regards,
Thangaraj.P
QuoteReplyEditDelete
2009-04-29 02:31:33 Re: Read call from userspace fails in the chararcter driver
Mike Frysinger (UNITED STATES)
Message: 73402
the 3rd argument to read() is a length, not an id. you cannot overload the read() function to do random things.
0x1eabb4d + 32160636 is 0x3d576c9 (or almost 64megs) ... you didnt post your kernel memory map, but i'm guessing that 0x3d576c9 is not a valid address thus the kernel is operating correctly.
QuoteReplyEditDelete
2009-04-29 02:50:24 Re: Read call from userspace fails in the chararcter driver
ThangarJ P (INDIA)
Message: 73403
Dear Mike,
The 3rd argument in the read is also a one pointer not a length.
The 32160636 is equal to 0x1eabb7c which is equal to the third argument.Thats a one pointer.
can we pass the third argument as a pointer in the read API?
QuoteReplyEditDelete
2009-04-29 02:59:09 Re: Read call from userspace fails in the chararcter driver
Mike Frysinger (UNITED STATES)
Message: 73404
no, every one of my previous statement still stands. the 3rd arg to read() is *always* a length against the 2nd arg which is a pointer.
QuoteReplyEditDelete
2009-04-29 04:40:39 Re: Read call from userspace fails in the chararcter driver
ThangarJ P (INDIA)
Message: 73419
Dear Mike,
please find out the memory map below
Kernel Managed Memory: 32MB
Memory map:
text = 0x00004000-0x001122a0
rodata = 0x00113000-0x001615c4
data = 0x00162000-0x00172000
stack = 0x00162000-0x00164000
init = 0x00172000-0x004d4000
bss = 0x004d4000-0x004e2824
available = 0x004e2824-0x01eff000
DMA Zone = 0x01f00000-0x02000000
read(5, 0x4acba9, 4901848) = -1 EFAULT (Bad address)
In the above call 0x4acba9+ 4901848 = 0x959781(almost equal to 9megs).here also its retrning error..
QuoteReplyEditDelete
2009-04-29 13:10:28 Re: Read call from userspace fails in the chararcter driver
Mike Frysinger (UNITED STATES)
Message: 73441
i'm assuming you have no actual question since you've been told the source of your problem