From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/gntdev: switch from char-dev to misc-dev Date: Thu, 19 Jan 2012 12:33:54 +0000 Message-ID: <4F181BC2020000780006DA89@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part90BECAA2.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part90BECAA2.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 --- a/drivers/xen/gntdev/gntdev.c +++ b/drivers/xen/gntdev/gntdev.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,9 +30,6 @@ #include #include #include -#include - -#include #include =20 =20 @@ -156,11 +153,6 @@ static struct vm_operations_struct gntde .zap_pte =3D gntdev_clear_pte }; =20 -/* Global variables. */ - -/* The driver major number, for use when unregistering the driver. */ -static int gntdev_major; - #define GNTDEV_NAME "gntdev" =20 /* Memory mapping functions @@ -371,42 +363,27 @@ nomem_out: =20 /* Interface functions. */ =20 +static struct miscdevice gntdev_miscdev =3D { + .minor =3D MISC_DYNAMIC_MINOR, + .name =3D GNTDEV_NAME, + .fops =3D &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; =20 if (!is_running_on_xen()) { printk(KERN_ERR "You must be running Xen to use gntdev\n");= return -ENODEV; } =20 - gntdev_major =3D register_chrdev(0, GNTDEV_NAME, &gntdev_fops); - if (gntdev_major < 0) + err =3D 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 =3D get_xen_class()) =3D=3D NULL) { - printk(KERN_ERR "Error setting up xen_class\n"); - printk(KERN_ERR "gntdev created with major number =3D = %d\n",=20 - gntdev_major); - return 0; - } - - device =3D 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 =3D = %d\n", - gntdev_major); - return 0; + return err; } =20 return 0; @@ -416,10 +393,7 @@ static int __init gntdev_init(void) */ static void __exit gntdev_exit(void) { - struct class *class; - if ((class =3D get_xen_class()) !=3D NULL) - class_device_destroy(class, MKDEV(gntdev_major, 0)); - unregister_chrdev(gntdev_major, GNTDEV_NAME); + misc_deregister(&gntdev_miscdev); } =20 /* Called when the device is opened. */ --=__Part90BECAA2.0__= Content-Type: text/plain; name="xen-gntdev-miscdev.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-gntdev-miscdev.patch" gntdev: switch from char-dev to misc-dev=0A=0ARather than consuming a = major (using just a single minor under it)=0Aregister a dynamic-minor = misc-dev (as has been the case in the pv-ops=0Acode from the very = beginning).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/drivers/xen/gntdev/gntdev.c=0A+++ b/drivers/xen/gntdev/gntdev.c=0A@@ = -21,7 +21,7 @@=0A #include =0A #include =0A = #include =0A-#include =0A+#include =0A #include =0A #include =0A #include = =0A@@ -30,9 +30,6 @@=0A #include =0A = #include =0A #include =0A-#include =0A-=0A-#include =0A #include = =0A =0A =0A@@ -156,11 +153,6 @@ static struct vm_operations_struct = gntde=0A .zap_pte =3D gntdev_clear_pte=0A };=0A =0A-/* Global = variables. */=0A-=0A-/* The driver major number, for use when unregistering= the driver. */=0A-static int gntdev_major;=0A-=0A #define GNTDEV_NAME = "gntdev"=0A =0A /* Memory mapping functions=0A@@ -371,42 +363,27 @@ = nomem_out:=0A =0A /* Interface functions. */=0A =0A+static struct = miscdevice gntdev_miscdev =3D {=0A+ .minor =3D MISC_DYNAMIC_MINO= R,=0A+ .name =3D GNTDEV_NAME,=0A+ .fops =3D = &gntdev_fops,=0A+};=0A+=0A /* Initialises the driver. Called when the = module is loaded. */=0A static int __init gntdev_init(void)=0A {=0A- = struct class *class;=0A- struct class_device *device;=0A+ = int err;=0A =0A if (!is_running_on_xen()) {=0A printk(KERN= _ERR "You must be running Xen to use gntdev\n");=0A return = -ENODEV;=0A }=0A =0A- gntdev_major =3D register_chrdev(0, = GNTDEV_NAME, &gntdev_fops);=0A- if (gntdev_major < 0)=0A+ err =3D = misc_register(&gntdev_miscdev);=0A+ if (err)=0A {=0A = printk(KERN_ERR "Could not register gntdev device\n");=0A- = return -ENOMEM;=0A- }=0A-=0A- /* Note that if the sysfs code = fails, we will still initialise the=0A- * device, and output the major = number so that the device can be=0A- * created manually using = mknod.=0A- */=0A- if ((class =3D get_xen_class()) =3D=3D NULL) {=0A- = printk(KERN_ERR "Error setting up xen_class\n");=0A- = printk(KERN_ERR "gntdev created with major number =3D %d\n", =0A- = gntdev_major);=0A- return 0;=0A- }=0A-=0A- = device =3D class_device_create(class, NULL, MKDEV(gntdev_major, 0),=0A- = NULL, GNTDEV_NAME);=0A- if (IS_ERR(device)) {=0A- = printk(KERN_ERR "Error creating gntdev device in xen_class\n");=0A-= printk(KERN_ERR "gntdev created with major number =3D = %d\n",=0A- gntdev_major);=0A- return = 0;=0A+ return err;=0A }=0A =0A return 0;=0A@@ -416,10 = +393,7 @@ static int __init gntdev_init(void)=0A */=0A static void __exit = gntdev_exit(void)=0A {=0A- struct class *class;=0A- if ((class = =3D get_xen_class()) !=3D NULL)=0A- class_device_destroy(class,= MKDEV(gntdev_major, 0));=0A- unregister_chrdev(gntdev_major, GNTDEV_NAME= );=0A+ misc_deregister(&gntdev_miscdev);=0A }=0A =0A /* Called when the = device is opened. */=0A --=__Part90BECAA2.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part90BECAA2.0__=--