1 From: Jan Kara <jack@suse.cz>
2 Subject: Allow setting of number of raw devices as a module parameter
3 References: FATE 302178
6 Allow setting of maximal number of raw devices as a module parameter. This requires
7 changing of static array into a vmalloced one (the array is going to be too large
10 Signed-off-by: Jan Kara <jack@suse.cz>
13 drivers/char/Kconfig | 2 +-
14 drivers/char/raw.c | 33 +++++++++++++++++++++++++++------
15 2 files changed, 28 insertions(+), 7 deletions(-)
17 --- a/drivers/char/Kconfig
18 +++ b/drivers/char/Kconfig
19 @@ -1026,7 +1026,7 @@ config RAW_DRIVER
20 with the O_DIRECT flag.
23 - int "Maximum number of RAW devices to support (1-8192)"
24 + int "Maximum number of RAW devices to support (1-65536)"
28 --- a/drivers/char/raw.c
29 +++ b/drivers/char/raw.c
31 #include <linux/device.h>
32 #include <linux/mutex.h>
33 #include <linux/smp_lock.h>
34 +#include <linux/vmalloc.h>
36 #include <asm/uaccess.h>
38 @@ -29,10 +30,15 @@ struct raw_device_data {
41 static struct class *raw_class;
42 -static struct raw_device_data raw_devices[MAX_RAW_MINORS];
43 +static struct raw_device_data *raw_devices;
44 static DEFINE_MUTEX(raw_mutex);
45 static const struct file_operations raw_ctl_fops; /* forward declaration */
47 +static int max_raw_minors = MAX_RAW_MINORS;
49 +module_param(max_raw_minors, int, 0);
50 +MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)");
53 * Open/close code for raw IO.
55 @@ -158,7 +164,7 @@ static int raw_ctl_ioctl(struct inode *i
59 - if (rq.raw_minor <= 0 || rq.raw_minor >= MAX_RAW_MINORS) {
60 + if (rq.raw_minor <= 0 || rq.raw_minor >= max_raw_minors) {
64 @@ -266,12 +272,26 @@ static int __init raw_init(void)
65 dev_t dev = MKDEV(RAW_MAJOR, 0);
68 - ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw");
69 + if (max_raw_minors < 1 || max_raw_minors > 65536) {
70 + printk(KERN_WARNING "raw: invalid max_raw_minors (must be"
71 + " between 1 and 65536), using %d\n", MAX_RAW_MINORS);
72 + max_raw_minors = MAX_RAW_MINORS;
75 + raw_devices = vmalloc(sizeof(struct raw_device_data) * max_raw_minors);
77 + printk(KERN_ERR "Not enough memory for raw device structures\n");
81 + memset(raw_devices, 0, sizeof(struct raw_device_data) * max_raw_minors);
83 + ret = register_chrdev_region(dev, max_raw_minors, "raw");
87 cdev_init(&raw_cdev, &raw_fops);
88 - ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS);
89 + ret = cdev_add(&raw_cdev, dev, max_raw_minors);
91 kobject_put(&raw_cdev.kobj);
93 @@ -290,8 +310,9 @@ static int __init raw_init(void)
97 - unregister_chrdev_region(dev, MAX_RAW_MINORS);
98 + unregister_chrdev_region(dev, max_raw_minors);
100 + vfree(raw_devices);
104 @@ -300,7 +321,7 @@ static void __exit raw_exit(void)
105 device_destroy(raw_class, MKDEV(RAW_MAJOR, 0));
106 class_destroy(raw_class);
108 - unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS);
109 + unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), max_raw_minors);
112 module_init(raw_init);