Craig Yang
Craig Yang

Reputation: 340

why some ioctl cases always fails?

Recently, I am practicing a simple ioctl driver with three commands: print,get,set

In the ioctl switch statement, it looks like this pseudo-code:

switch (cmd) {
case "print":
    break;
case "get":
    break;
case "set":
    break;
default:
    break;
}

But, the print case can be correctly executed whereas get and set case are not. therefore, I get the output

[ 2682.940000] mymem_ioctl: <---Switch Command =27395--->
[ 2682.940000] getdata=80046b01 80046b01setdata=40046b02 40046b02print=6b03 6b03
[ 2682.950000] <---ORG IOCPRINT :test_var=-1095999702--->
[ 2682.960000] <---IOCPRINT complete:test_var=111--->
cmd:6b03, arg=10 success
SETDATA cmd:40046b02
ioctl_setdata error
GETDATA cmd:80046b01
ioctl_getdata error

I tried to decode the ioctl command, but everything looks good.

getdata=0x80046b01 => 1000 0000 0000 0100 ....
setdata=0x40046b02 => 0100 0000 0000 0100 ....
print=0x6b03

0100 is size of int 
6b is my magic number 'k'
01,02,03 is the number of function(get,set,print)

I don't know why... anyone can help on that?

the kernel version is 2.6.38, and below is my code

Upvotes: 0

Views: 2286

Answers (1)

talshorer
talshorer

Reputation: 692

@line 14

_IOC_NR(cmd)!=MYMEMDEV_IOC_MAXNR

should probably be check

_IOC_NR(cmd) <= MYMEMDEV_IOC_MAXNR

Also, I beg you, follow the kernel coding style. It would make it so much easier for us to help that way.
http://lxr.free-electrons.com/source/Documentation/CodingStyle

Upvotes: 1

Related Questions