Skip to contentSkip to conversation

linux-2.6.18/gntdev: switch from char-dev to misc-dev

PATCH New Jan Beulich 1 participant 1 message Jan 19, 2012 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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).

drivers/xen/gntdev/gntdev.c +12 -38
@@ -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. */

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).

drivers/xen/gntdev/gntdev.c +12 -38

91 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel