Subject: Can not write to device driver

From: umesh <[email-masked]>
Date: Sat, 24 Jun 2000 16:32:15 +0530

Hi,

I have an audio device driver installed on my Cirrus Logic EP-7212
evaluation board.
My application program tries to write to the device driver,
but returns with an error. errno is set to EBADF in this case.

I found out further that this is becasue of the f_mode bit in the
'file' structure. it returns a value of 1 which indicates that there
are no read/wrte permissions.

I have set the device driver's permission as 664. Even setting them
to 777 does not help.

The application program and the device driver's UID and GID are
ientical, i.e. 0:0.

Could someone tell me how to tackle this?

Thanks.

Umesh Puranik

unsubscribe: body of `unsubscribe linux-arm' to [email-masked]
++        Please use [email-masked] for           ++
++                        kernel-related discussions.                      ++

---

From: Russell King - ARM Linux Admin <[email-masked]>
Date: Sat, 24 Jun 2000 12:15:17 +0100 (BST)

> are no read/wrte permissions.

Please give an example of the strace output from running your test
program.
   _____
  |_____| ------------------------------------------------- ---+---+-
  |   |        Russell King       [email-masked]      --- ---
  | | | |            http://www.arm.linux.org.uk/            /  /  |
  | +-+-+                                                     --- -+-
  /   |               THE developer of ARM Linux              |+| /|\
 /  | | |                                                     ---  |
    +-+-+ -------------------------------------------------  /\\\  |

---

From: umesh <[email-masked]>
Date: Sat, 24 Jun 2000 18:30:58 +0530

I am sorry that I am not clear about the strace..
I am giving here all the details, few of which could be irrelevant.
I have also attached the source code for the device driver (audio_7212.c)
and
the application code (au2.c)
1) The directory entry for the driver looks like this:
    crw-rw-r--    1    0    0    254,    0    Jun24  2000    audio_7212
2) directory entry for the application program:
    -rwxr-xr-x    1    0    0    225192     Jun24  2000    au2

When I execute the application program, I see the following:
------------------------------------------------------------
>./au2

Device audio_7212 opened successfully
...
... (Messages printed from au2.c,)
...
write(fp) returned: 9

Closed audio_7212 device.
----------------------------------------------------------

write(fp) returns errono = 9, i.e. EBADF.
This I traced by doing a printk from fs/read_write.c. It comes out
because of the FMODE (mode_f) bit.

I am running this from initrd. I create the initrd on my Linux PC and
download it with the kernel image (arch/arm/boot/Image).
While creating initrd, I do 'mknod /dev/audio_7212 c 254 0' to create the
device driver entry. Then I do a 'chmod 664 /dev/audio_7212' to grant
permissions.
After that I copy au2 to the initrd image.

Thanks....

Umesh Puranik

---

From: Russell King - ARM Linux Admin <[email-masked]>
Date: Sat, 24 Jun 2000 17:07:13 +0100 (BST)

> I am sorry that I am not clear about the strace..

On your nearest Linux box, type "man strace" for more information.
It's a program that allows you to trace the interaction between
the user program and the kernel.

Looking at the source code, it appears that you have made up the
arguments to the open(), read() and write() methods in your kernel
module.  You can't do this - you *must* follow the prototypes if
you wish your driver to work.

The correct arguments and return type are:

ssize_t xxx_write(struct file *file, const char *buf,
		  size_t count, loff_t *ppos);
ssize_t xxx_read(struct file * file, char * buf,
		 size_t count, loff_t *ppos);
int xxx_open(struct inode * inode, struct file * filp);

whereas you're using:

int audio_7212_write(char *buffer, int count);
void audio_7212_read(void);
int audio_7212_open(void);
   _____
  |_____| ------------------------------------------------- ---+---+-
  |   |        Russell King       [email-masked]      --- ---
  | | | |            http://www.arm.linux.org.uk/            /  /  |
  | +-+-+                                                     --- -+-
  /   |               THE developer of ARM Linux              |+| /|\
 /  | | |                                                     ---  |
    +-+-+ -------------------------------------------------  /\\\  |