Find the answer to your Linux question:
Results 1 to 2 of 2
I wasted a lot of time this week chasing what I thought was a bug in my driver, but turned out to be something entirely different. I'm writing a char ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO, USA
    Posts
    2

    Open() without driver


    I wasted a lot of time this week chasing what I thought was a bug in my driver, but turned out to be something entirely different. I'm writing a char class PCIE driver and in the interest of hurrying up, I didn't integrate the driver with udev, choosing instead to just mknod the /dev file as needed. I printk the major minor number and use that info as arguments to mknod. For 2 weeks, the kernel was giving me major 252 and minor 0 and I typed it so much I aliased the mknod rmmod and insmod commands. Then, after some changes, it started giving me 251, 0. Something I didn't notice. So now my command is making the wrong dev file.

    The interesting thing is that my test program always succeded on open(), but everything else I tried, my ioctls and read, all returned -1. That is to be expected. What I don't understand is why the open succeed (and that's what made me spend a bunch of time chasing a non-existent bug in my driver).

    So what is the correct behaviour for this? Should open succeed and return a valid file handle for a dev file that has no driver associated with it?

    I'm way past this now, but the behaviour bugs me and wondering what other people think should happen.

    Robert

  2. #2
    Just Joined!
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO, USA
    Posts
    2
    This is freaky because I can't reproduce it. Grrrrrrrrr! I wrote a dumb little opentest program:

    #include <stdio.h>
    #include <fcntl.h>
    int main( int argc, char *argv[] )
    {
    int fd;
    if ( argc > 1 ) {
    fd = open(argv[1], O_RDONLY);
    if ( fd > 0 ) {
    printf("opened ok %d\n", fd);
    close(fd);
    } else {
    printf("open failed\n");
    }
    }
    }


    I must conclude there was some driver at c,252,0, but I have no idea what it was (nor can I think how to find it next time).

    Robert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •