Adding new driver in Linux 2.6 - read fails with -1

Jenkins, Clive Clive.Jenkins at xerox.com
Sat Jan 19 07:15:46 EST 2008


> From: Ramkumar J [mailto:ramkumarj2000 at gmail.com] 
> Sent: 18 January 2008 12:29
> To: Jenkins, Clive
> Cc: linuxppc-embedded at ozlabs.org
> Subject: Re: Adding new driver in Linux 2.6 - read fails with -1
> [...]
> 
> Hi,
> 
> Thanks a lot for replying. I will try using the perror() function and
> modify the  busy-loop through wait-for functions. Also, the way I have
> accessed the memory  mapped IO, is to ioremap() the physical address
> and then use readl() functions.  Is this correct. 
> 
> Following is the link to the driver file,
> http://www.geocities.com/ramkumarj_2000/impulse-stream.c
> http://www.geocities.com/ramkumarj_2000/1.txt as impulse-stream.h
>
> This is intermediate layer and part of my application space,
> http://www.geocities.com/ramkumarj_2000/co_stream_linux.c
> 
> The application is,
> http://www.geocities.com/ramkumarj_2000/HelloWorld.c
> http://www.geocities.com/ramkumarj_2000/HelloWorld_sw.c
> 
> Logs at,
> http://www.geocities.com/ramkumarj_2000/logs.txt
> http://www.geocities.com/ramkumarj_2000/kernellog.txt
> 
> My apologies for the dirty code. To add some background, it starts
> from the main() in HelloWorld.c and it proceeds calling the
> hear_hello() in HelloWorld_sw.c . The co_stream_* functions are
> defined in intermediate layer co_stream_linux.c and co_stream_open
> is defined to nothing in one header file. The open and ioctl call
> ( modified a little in the driver now for debugging) map from
> co_stream_attach. 
> co_stream_read is read and co_stream_write is the write to driver.
 
> Though the logs indicate the call of release function before the
> read, I m not quite sure about this as the read not being called
> have failed to get inside the kernel messages.

I still can't see everything because the header files are not shown.

But anyway, it is getting too complex. I think you need to cut the code
down to the mininum that causes the error if you want help from the
list.

A couple of hints regarding the driver's read method:
1. If you really want to copy different data sizes into the same
variable
then use a union.
2. *(char*)buffer=x puts x where buffer points to; I think you wanted
to put x into the variable buffer: *(char*)&buffer = x, but this is
not very clear -- better to use a union.
3. copy_{to,from)_user() return values that should be checked. Always
check function return values (except maybe printf and printk), and
display all error information.

Clive


More information about the Linuxppc-embedded mailing list