uio: Support 2^MINOR_BITS minors
register_chrdev limits uio devices to 256 minor numbers which causes problems on one system I have with 384+ uio devices. So instead set UIO_MAX_DEVICES to the maximum number of minors and use alloc_chrdev_region to reserve the uio minors. The final result is that the code works the same but the uio driver now supports any minor the idr allocator comes up with. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Hans J. Koch <hjk@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
6427a7655a
commit
91960a46c6
@ -23,9 +23,10 @@
|
|||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/kobject.h>
|
#include <linux/kobject.h>
|
||||||
|
#include <linux/cdev.h>
|
||||||
#include <linux/uio_driver.h>
|
#include <linux/uio_driver.h>
|
||||||
|
|
||||||
#define UIO_MAX_DEVICES 255
|
#define UIO_MAX_DEVICES (1U << MINORBITS)
|
||||||
|
|
||||||
struct uio_device {
|
struct uio_device {
|
||||||
struct module *owner;
|
struct module *owner;
|
||||||
@ -41,6 +42,7 @@ struct uio_device {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int uio_major;
|
static int uio_major;
|
||||||
|
static struct cdev *uio_cdev;
|
||||||
static DEFINE_IDR(uio_idr);
|
static DEFINE_IDR(uio_idr);
|
||||||
static const struct file_operations uio_fops;
|
static const struct file_operations uio_fops;
|
||||||
|
|
||||||
@ -731,15 +733,44 @@ static const struct file_operations uio_fops = {
|
|||||||
|
|
||||||
static int uio_major_init(void)
|
static int uio_major_init(void)
|
||||||
{
|
{
|
||||||
uio_major = register_chrdev(0, "uio", &uio_fops);
|
static const char name[] = "uio";
|
||||||
if (uio_major < 0)
|
struct cdev *cdev = NULL;
|
||||||
return uio_major;
|
dev_t uio_dev = 0;
|
||||||
return 0;
|
int result;
|
||||||
|
|
||||||
|
result = alloc_chrdev_region(&uio_dev, 0, UIO_MAX_DEVICES, name);
|
||||||
|
if (result)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
result = -ENOMEM;
|
||||||
|
cdev = cdev_alloc();
|
||||||
|
if (!cdev)
|
||||||
|
goto out_unregister;
|
||||||
|
|
||||||
|
cdev->owner = THIS_MODULE;
|
||||||
|
cdev->ops = &uio_fops;
|
||||||
|
kobject_set_name(&cdev->kobj, "%s", name);
|
||||||
|
|
||||||
|
result = cdev_add(cdev, uio_dev, UIO_MAX_DEVICES);
|
||||||
|
if (result)
|
||||||
|
goto out_put;
|
||||||
|
|
||||||
|
uio_major = MAJOR(uio_dev);
|
||||||
|
uio_cdev = cdev;
|
||||||
|
result = 0;
|
||||||
|
out:
|
||||||
|
return result;
|
||||||
|
out_put:
|
||||||
|
kobject_put(&cdev->kobj);
|
||||||
|
out_unregister:
|
||||||
|
unregister_chrdev_region(uio_dev, UIO_MAX_DEVICES);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uio_major_cleanup(void)
|
static void uio_major_cleanup(void)
|
||||||
{
|
{
|
||||||
unregister_chrdev(uio_major, "uio");
|
unregister_chrdev_region(MKDEV(uio_major, 0), UIO_MAX_DEVICES);
|
||||||
|
cdev_del(uio_cdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_uio_class(void)
|
static int init_uio_class(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user