Skip to content

Commit

Permalink
[PATCH] tipar fixes
Browse files Browse the repository at this point in the history
- tipar_open(): fix unsigned comparison

- tipar_open(): don't permit NULL pardevice (probably unneeded given the
  above fix).

- tipar_init_module(): handle the situation where parport_register_driver()
  failed to register any devices (parport_register_driver() drops the ->attach
  return value on the floor).

  This probably makes fixes #1 and #2 unneeded.

- tipar_init_module(): fix various error-path resource leaks.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Andrew Morton authored and Linus Torvalds committed Feb 12, 2006
1 parent ef1bea9 commit 1d30883
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions drivers/char/tipar.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,17 @@ tipar_open(struct inode *inode, struct file *file)
{
unsigned int minor = iminor(inode) - TIPAR_MINOR;

if (minor > tp_count - 1)
if (tp_count == 0 || minor > tp_count - 1)
return -ENXIO;

if (test_and_set_bit(minor, &opened))
return -EBUSY;

if (!table[minor].dev) {
printk(KERN_ERR "%s: NULL device for minor %u\n",
__FUNCTION__, minor);
return -ENXIO;
}
parport_claim_or_block(table[minor].dev);
init_ti_parallel(minor);
parport_release(table[minor].dev);
Expand Down Expand Up @@ -510,16 +515,20 @@ tipar_init_module(void)
err = PTR_ERR(tipar_class);
goto out_chrdev;
}
if (parport_register_driver(&tipar_driver)) {
if (parport_register_driver(&tipar_driver) || tp_count == 0) {
printk(KERN_ERR "tipar: unable to register with parport\n");
err = -EIO;
goto out;
goto out_class;
}

err = 0;
goto out;

out_class:
class_destroy(tipar_class);

out_chrdev:
devfs_remove("ticables/par");
unregister_chrdev(TIPAR_MAJOR, "tipar");
out:
return err;
Expand Down

0 comments on commit 1d30883

Please sign in to comment.