vdpram: Export device node details to userspace
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 17 Jan 2013 11:59:23 +0000 (12:59 +0100)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 23 Jan 2013 09:42:17 +0000 (18:42 +0900)
This will allow udevd(8) or similar program to automatically
create correct device nodes for us.

Change-Id: I9815b5ff9ba3842515ac7020254265188ab90feb

drivers/char/vdpram.c

index c5b9470af81d313728c4eb4bc8f20476d1436ea2..7b078b56f31e6cfb9e6c6dba98eca4e5b0d1be06 100755 (executable)
@@ -28,6 +28,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 
+#include <linux/types.h>
 #include <linux/kernel.h>      /* printk(), min() */
 #include <linux/slab.h>                /* kmalloc() */
 #include <linux/fs.h>          /* everything... */
@@ -37,6 +38,7 @@
 #include <linux/fcntl.h>
 #include <linux/poll.h>
 #include <linux/cdev.h>
+#include <linux/device.h>
 #include <linux/sched.h>
 #include <asm/uaccess.h>
 
@@ -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++) {