Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / char / tipar.c
index 0c5ba9d..079db5a 100644 (file)
@@ -90,7 +90,7 @@ static int timeout = TIMAXTIME;       /* timeout in tenth of seconds     */
 static unsigned int tp_count;  /* tipar count */
 static unsigned long opened;   /* opened devices */
 
-static struct class_simple *tipar_class;
+static struct class *tipar_class;
 
 /* --- macros for parport access -------------------------------------- */
 
@@ -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);
@@ -396,7 +401,7 @@ static struct file_operations tipar_fops = {
 static int __init
 tipar_setup(char *str)
 {
-       int ints[2];
+       int ints[3];
 
        str = get_options(str, ARRAY_SIZE(ints), ints);
 
@@ -436,7 +441,7 @@ tipar_register(int nr, struct parport *port)
                goto out;
        }
 
-       class_simple_device_add(tipar_class, MKDEV(TIPAR_MAJOR,
+       class_device_create(tipar_class, NULL, MKDEV(TIPAR_MAJOR,
                        TIPAR_MINOR + nr), NULL, "par%d", nr);
        /* Use devfs, tree: /dev/ticables/par/[0..2] */
        err = devfs_mk_cdev(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr),
@@ -458,8 +463,8 @@ tipar_register(int nr, struct parport *port)
        goto out;
 
 out_class:
-       class_simple_device_remove(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr));
-       class_simple_destroy(tipar_class);
+       class_device_destroy(tipar_class, MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr));
+       class_destroy(tipar_class);
 out:
        return err;
 }
@@ -505,7 +510,7 @@ tipar_init_module(void)
        /* Use devfs with tree: /dev/ticables/par/[0..2] */
        devfs_mk_dir("ticables/par");
 
-       tipar_class = class_simple_create(THIS_MODULE, "ticables");
+       tipar_class = class_create(THIS_MODULE, "ticables");
        if (IS_ERR(tipar_class)) {
                err = PTR_ERR(tipar_class);
                goto out_chrdev;
@@ -513,13 +518,17 @@ tipar_init_module(void)
        if (parport_register_driver(&tipar_driver)) {
                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;     
@@ -539,10 +548,10 @@ tipar_cleanup_module(void)
                if (table[i].dev == NULL)
                        continue;
                parport_unregister_device(table[i].dev);
-               class_simple_device_remove(MKDEV(TIPAR_MAJOR, i));
+               class_device_destroy(tipar_class, MKDEV(TIPAR_MAJOR, i));
                devfs_remove("ticables/par/%d", i);
        }
-       class_simple_destroy(tipar_class);
+       class_destroy(tipar_class);
        devfs_remove("ticables/par");
 
        pr_info("tipar: module unloaded\n");