From 9ebbed0c2f1e5487f8ff23e87f6c33fb28d53781 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 17 Jan 2013 12:59:23 +0100 Subject: [PATCH] vdpram: Export device node details to userspace This will allow udevd(8) or similar program to automatically create correct device nodes for us. Change-Id: I9815b5ff9ba3842515ac7020254265188ab90feb --- drivers/char/vdpram.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/char/vdpram.c b/drivers/char/vdpram.c index c5b9470af81d..7b078b56f31e 100755 --- a/drivers/char/vdpram.c +++ b/drivers/char/vdpram.c @@ -28,6 +28,7 @@ #include #include +#include #include /* printk(), min() */ #include /* kmalloc() */ #include /* everything... */ @@ -37,6 +38,7 @@ #include #include #include +#include #include #include @@ -104,6 +106,7 @@ module_param(vdpram_buffer, int, 0); static struct vdpram_dev *vdpram_devices; static struct buffer_t *buffer; static struct queue_t *queue; +static struct class *vdpram_class; static int vdpram_fasync(int fd, struct file *filp, int mode); static int spacefree(struct vdpram_dev *dev); @@ -595,7 +598,10 @@ static void vdpram_setup_cdev(struct vdpram_dev *dev, int index) printk(KERN_NOTICE "Error %d adding device%d\n", err, index); } - +static char *vdpram_devnode(struct device *dev, umode_t *mode) +{ + return kasprintf(GFP_KERNEL, "%s", dev_name(dev)); +} /* Initialize the devs; return how many we did */ int vdpram_init(void) @@ -621,6 +627,13 @@ int vdpram_init(void) goto err_alloc; } + vdpram_class = class_create(THIS_MODULE, "vdpram"); + if (IS_ERR(vdpram_class)) { + result = PTR_ERR(vdpram_class); + goto err_alloc; + } + vdpram_class->devnode = vdpram_devnode; + memset(vdpram_devices, 0, vdpram_nr_devs * sizeof(struct vdpram_dev)); for (i = 0; i < vdpram_nr_devs; i++) { if (i% 2 ==1) { @@ -650,7 +663,11 @@ int vdpram_init(void) //printk("%s buffer[%x].begin =%x\n", __FUNCTION__, i, buffer[i].begin ); //printk("%s buffer[%x].buffersize =%x\n", __FUNCTION__, i, buffer[i].buffersize ); //printk("%s buffer[%x].end =%x\n", __FUNCTION__, i, buffer[i].end ); - } + } + + for (i = 0; i < vdpram_nr_devs; i++) + device_create(vdpram_class, NULL, MKDEV(vdpram_major, i), NULL, + kasprintf(GFP_KERNEL, "vdpram%d", i)); return 0; @@ -679,8 +696,10 @@ void vdpram_cleanup(void) return; /* nothing else to release */ for (i = 0; i < vdpram_nr_devs; i++) { + device_destroy(vdpram_class, MKDEV(vdpram_major, i)); cdev_del(&vdpram_devices[i].cdev); } + class_destroy(vdpram_class); kfree(vdpram_devices); for (i= 0;i < vdpram_nr_devs ; i++) { -- 2.34.1