greybus: vibrator-gb: proper allocate minor numbers
Change the driver to allocate minors in a proper manner, using the idr
interface.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
diff --git a/drivers/staging/greybus/vibrator-gb.c b/drivers/staging/greybus/vibrator-gb.c
index 22356af..e423751 100644
--- a/drivers/staging/greybus/vibrator-gb.c
+++ b/drivers/staging/greybus/vibrator-gb.c
@@ -11,11 +11,13 @@
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
+#include <linux/idr.h>
#include "greybus.h"
struct gb_vibrator_device {
struct gb_connection *connection;
struct device *dev;
+ int minor; /* vibrator minor number */
u8 version_major;
u8 version_minor;
};
@@ -202,7 +204,7 @@
#endif
};
-static int minor;
+static DEFINE_IDR(minors);
static int gb_vibrator_connection_init(struct gb_connection *connection)
{
@@ -221,17 +223,21 @@
goto error;
/*
- * FIXME: for now we create a device in sysfs for the vibrator, but odds
- * are there is a "real" device somewhere in the kernel for this, but I
+ * For now we create a device in sysfs for the vibrator, but odds are
+ * there is a "real" device somewhere in the kernel for this, but I
* can't find it at the moment...
*/
+ vib->minor = idr_alloc(&minors, vib, 0, 0, GFP_KERNEL);
+ if (vib->minor < 0) {
+ retval = vib->minor;
+ goto error;
+ }
dev = device_create(&vibrator_class, &connection->dev, MKDEV(0, 0), vib,
- "vibrator%d", minor);
+ "vibrator%d", vib->minor);
if (IS_ERR(dev)) {
retval = -EINVAL;
goto error;
}
- minor++;
vib->dev = dev;
#if LINUX_VERSION_CODE <= KERNEL_VERSION(3,11,0)
@@ -261,6 +267,7 @@
#if LINUX_VERSION_CODE <= KERNEL_VERSION(3,11,0)
sysfs_remove_group(&vib->dev->kobj, vibrator_groups[0]);
#endif
+ idr_remove(&minors, vib->minor);
device_unregister(vib->dev);
kfree(vib);
}