]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/misc/phantom.c
Merge branch 'llseek' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/bkl
[linux-2.6.git] / drivers / misc / phantom.c
index 71d1c84e2fa8e4ed918461a702d2e50e2d4b3ccd..4197a3cb26ba42d674ef7d0935207adee0d70be1 100644 (file)
@@ -6,7 +6,7 @@
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
- *  You need an userspace library to cooperate with this driver. It (and other
+ *  You need a userspace library to cooperate with this driver. It (and other
  *  info) may be obtained here:
  *  http://www.fi.muni.cz/~xslaby/phantom.html
  *  or alternatively, you might use OpenHaptics provided by Sensable.
 #include <linux/poll.h>
 #include <linux/interrupt.h>
 #include <linux/cdev.h>
+#include <linux/slab.h>
 #include <linux/phantom.h>
+#include <linux/sched.h>
+#include <linux/mutex.h>
 
 #include <asm/atomic.h>
 #include <asm/io.h>
@@ -35,6 +38,7 @@
 #define PHB_RUNNING            1
 #define PHB_NOT_OH             2
 
+static DEFINE_MUTEX(phantom_mutex);
 static struct class *phantom_class;
 static int phantom_major;
 
@@ -212,13 +216,17 @@ static int phantom_open(struct inode *inode, struct file *file)
        struct phantom_device *dev = container_of(inode->i_cdev,
                        struct phantom_device, cdev);
 
+       mutex_lock(&phantom_mutex);
        nonseekable_open(inode, file);
 
-       if (mutex_lock_interruptible(&dev->open_lock))
+       if (mutex_lock_interruptible(&dev->open_lock)) {
+               mutex_unlock(&phantom_mutex);
                return -ERESTARTSYS;
+       }
 
        if (dev->opened) {
                mutex_unlock(&dev->open_lock);
+               mutex_unlock(&phantom_mutex);
                return -EINVAL;
        }
 
@@ -229,7 +237,7 @@ static int phantom_open(struct inode *inode, struct file *file)
        atomic_set(&dev->counter, 0);
        dev->opened++;
        mutex_unlock(&dev->open_lock);
-
+       mutex_unlock(&phantom_mutex);
        return 0;
 }
 
@@ -266,12 +274,13 @@ static unsigned int phantom_poll(struct file *file, poll_table *wait)
        return mask;
 }
 
-static struct file_operations phantom_file_ops = {
+static const struct file_operations phantom_file_ops = {
        .open = phantom_open,
        .release = phantom_release,
        .unlocked_ioctl = phantom_ioctl,
        .compat_ioctl = phantom_compat_ioctl,
        .poll = phantom_poll,
+       .llseek = no_llseek,
 };
 
 static irqreturn_t phantom_isr(int irq, void *data)
@@ -394,8 +403,9 @@ static int __devinit phantom_probe(struct pci_dev *pdev,
                goto err_irq;
        }
 
-       if (IS_ERR(device_create(phantom_class, &pdev->dev, MKDEV(phantom_major,
-                       minor), "phantom%u", minor)))
+       if (IS_ERR(device_create(phantom_class, &pdev->dev,
+                                MKDEV(phantom_major, minor), NULL,
+                                "phantom%u", minor)))
                dev_err(&pdev->dev, "can't create device\n");
 
        pci_set_drvdata(pdev, pht);
@@ -490,12 +500,7 @@ static struct pci_driver phantom_pci_driver = {
        .resume = phantom_resume
 };
 
-static ssize_t phantom_show_version(struct class *cls, char *buf)
-{
-       return sprintf(buf, PHANTOM_VERSION "\n");
-}
-
-static CLASS_ATTR(version, 0444, phantom_show_version, NULL);
+static CLASS_ATTR_STRING(version, 0444, PHANTOM_VERSION);
 
 static int __init phantom_init(void)
 {
@@ -508,7 +513,7 @@ static int __init phantom_init(void)
                printk(KERN_ERR "phantom: can't register phantom class\n");
                goto err;
        }
-       retval = class_create_file(phantom_class, &class_attr_version);
+       retval = class_create_file(phantom_class, &class_attr_version.attr);
        if (retval) {
                printk(KERN_ERR "phantom: can't create sysfs version file\n");
                goto err_class;
@@ -534,7 +539,7 @@ static int __init phantom_init(void)
 err_unchr:
        unregister_chrdev_region(dev, PHANTOM_MAX_MINORS);
 err_attr:
-       class_remove_file(phantom_class, &class_attr_version);
+       class_remove_file(phantom_class, &class_attr_version.attr);
 err_class:
        class_destroy(phantom_class);
 err:
@@ -547,7 +552,7 @@ static void __exit phantom_exit(void)
 
        unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS);
 
-       class_remove_file(phantom_class, &class_attr_version);
+       class_remove_file(phantom_class, &class_attr_version.attr);
        class_destroy(phantom_class);
 
        pr_debug("phantom: module successfully removed\n");
@@ -557,6 +562,6 @@ module_init(phantom_init);
 module_exit(phantom_exit);
 
 MODULE_AUTHOR("Jiri Slaby <jirislaby@gmail.com>");
-MODULE_DESCRIPTION("Sensable Phantom driver");
+MODULE_DESCRIPTION("Sensable Phantom driver (PCI devices)");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(PHANTOM_VERSION);