[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] linux-2.6.18/gntdev: switch from char-dev to misc-dev



Rather than consuming a major (using just a single minor under it)
register a dynamic-minor misc-dev (as has been the case in the pv-ops
code from the very beginning).

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/drivers/xen/gntdev/gntdev.c
+++ b/drivers/xen/gntdev/gntdev.c
@@ -21,7 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/fs.h>
-#include <linux/device.h>
+#include <linux/miscdevice.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
 #include <asm/uaccess.h>
@@ -30,9 +30,6 @@
 #include <asm/hypervisor.h>
 #include <xen/balloon.h>
 #include <xen/evtchn.h>
-#include <xen/driver_util.h>
-
-#include <linux/types.h>
 #include <xen/public/gntdev.h>
 
 
@@ -156,11 +153,6 @@ static struct vm_operations_struct gntde
        .zap_pte = gntdev_clear_pte
 };
 
-/* Global variables. */
-
-/* The driver major number, for use when unregistering the driver. */
-static int gntdev_major;
-
 #define GNTDEV_NAME "gntdev"
 
 /* Memory mapping functions
@@ -371,42 +363,27 @@ nomem_out:
 
 /* Interface functions. */
 
+static struct miscdevice gntdev_miscdev = {
+       .minor        = MISC_DYNAMIC_MINOR,
+       .name         = GNTDEV_NAME,
+       .fops         = &gntdev_fops,
+};
+
 /* Initialises the driver. Called when the module is loaded. */
 static int __init gntdev_init(void)
 {
-       struct class *class;
-       struct class_device *device;
+       int err;
 
        if (!is_running_on_xen()) {
                printk(KERN_ERR "You must be running Xen to use gntdev\n");
                return -ENODEV;
        }
 
-       gntdev_major = register_chrdev(0, GNTDEV_NAME, &gntdev_fops);
-       if (gntdev_major < 0)
+       err = misc_register(&gntdev_miscdev);
+       if (err)
        {
                printk(KERN_ERR "Could not register gntdev device\n");
-               return -ENOMEM;
-       }
-
-       /* Note that if the sysfs code fails, we will still initialise the
-        * device, and output the major number so that the device can be
-        * created manually using mknod.
-        */
-       if ((class = get_xen_class()) == NULL) {
-               printk(KERN_ERR "Error setting up xen_class\n");
-               printk(KERN_ERR "gntdev created with major number = %d\n", 
-                      gntdev_major);
-               return 0;
-       }
-
-       device = class_device_create(class, NULL, MKDEV(gntdev_major, 0),
-                                    NULL, GNTDEV_NAME);
-       if (IS_ERR(device)) {
-               printk(KERN_ERR "Error creating gntdev device in xen_class\n");
-               printk(KERN_ERR "gntdev created with major number = %d\n",
-                      gntdev_major);
-               return 0;
+               return err;
        }
 
        return 0;
@@ -416,10 +393,7 @@ static int __init gntdev_init(void)
  */
 static void __exit gntdev_exit(void)
 {
-       struct class *class;
-       if ((class = get_xen_class()) != NULL)
-               class_device_destroy(class, MKDEV(gntdev_major, 0));
-       unregister_chrdev(gntdev_major, GNTDEV_NAME);
+       misc_deregister(&gntdev_miscdev);
 }
 
 /* Called when the device is opened. */



Attachment: xen-gntdev-miscdev.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.