Re: [linux-parport] Re: [PARPORT] open on non existing ppdev device

From: stef (svoltz@wanadoo.fr)
Date: Sat Oct 04 2003 - 10:44:37 EDT

  • Next message: John Miskinis: "[PARPORT] ripping CDs with parallel port CDRW?"

    On Fri, Oct 03, 2003 at 01:26:01PM +0100, Tim Waugh wrote:
    > On Fri, Oct 03, 2003 at 01:57:23PM +0000, stef wrote:
    >
    > > Hello,
    > >
    > > it is possible to succeesfully open a /dev/parport device which does not
    > > have an underlying port. I'd expect to get ENODEV or ENOXIO. We can only notice
    > > that the device is invalid when we claim it.
    > >
    > > Is it the expected behaviour ?
    >
    > No, I don't think that's intentional.
    >
    > Perhaps pp_open ought to do something like:
    >
    > port = parport_find_number (minor);
    > if (!port) {
    > printk (KERN_WARNING "%s: no associated port!\n", name);
    > kfree (name);
    > return -ENXIO;
    > }
    >
    > like register_device does.
    >
    > Tim.
    > */

            Hello,

            based on your suggestion, here's a patch that makes non existent ppdev
    devices to return ENODEV on open:

    --- linux-2.4.22/drivers/char/ppdev.c 2002-08-03 00:39:43.000000000 +0000
    +++ linux-2.4.23-pre5/drivers/char/ppdev.c 2003-10-04 14:31:22.000000000 +0000
    @@ -643,6 +643,7 @@
     {
            unsigned int minor = MINOR (inode->i_rdev);
            struct pp_struct *pp;
    + struct parport *port;
     
            if (minor >= PARPORT_MAX)
                    return -ENXIO;
    @@ -665,6 +666,14 @@
            pp->pdev = NULL;
            file->private_data = pp;
     
    + /* check there is an associated port */
    + port = parport_find_number (minor);
    + if (!port) {
    + printk (KERN_WARNING "%s%x: no associated port!\n", CHRDEV,
    + minor);
    + return -ENODEV;
    + }
    +
            return 0;
     }

    Regards,
            Stef

    -- To unsubscribe, send mail to: linux-parport-request@torque.net --
    -- with the single word "unsubscribe" in the body of the message. --



    This archive was generated by hypermail 2b29 : Sat Oct 04 2003 - 08:55:39 EDT